### 高分请问:怎样判断某窗体是MDI、MDIChild窗体?(内详) ####

LoveDana 2001-11-13 09:51:14
现在需要判断某窗体是为MDI、MDIChild还是普通窗体。请问,怎样判断?
...全文
209 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
LoveDana 2001-11-18
  • 打赏
  • 举报
回复
呵呵,不是的,我发现这几天我都不能结帖子,每次输入密码后按回车,等上老半天,最后总是550/500错误
xfflean 2001-11-18
  • 打赏
  • 举报
回复
Hehe,
老兄,
结不了就算咯
我不是为了分数来这
只想多交几个朋友~
LoveDana 2001-11-18
  • 打赏
  • 举报
回复
天阿,怎么结不了帖子?我晚上再来看看,是否能够结
LoveDana 2001-11-18
  • 打赏
  • 举报
回复
非常感谢,马上结帖子。
xfflean 2001-11-18
  • 打赏
  • 举报
回复
Sure.
const ws_cgild=(-12)
OK?
xfflean 2001-11-17
  • 打赏
  • 举报
回复
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long


Function Ismdiform(hwnd As Long) As Boolean
Dim mdihwnd As Long
mdihwnd = GetWindowLong(hwnd, -12)
If mdihwnd = 0 Then
Ismdiform = False
Exit Function
Else
Ismdiform = True
Exit Function
End If
End Function
LoveDana 2001-11-17
  • 打赏
  • 举报
回复
请问,-12是否为WS_CGILD?如果不是,其常数是什么?
LoveDana 2001-11-16
  • 打赏
  • 举报
回复
可能我没有说清楚:我现在只想区分MDIForm和普通Form,其中MDIForm是指可以拥有Child的窗体,并不是MDIChild窗体。
LoveDana 2001-11-16
  • 打赏
  • 举报
回复
to:xfflean(雄) 
可是,如果是MDIForm呢?MDIChildForm有parent,可是,MDIForm和普通的Form都没有Parent,怎样区别?
xfflean 2001-11-16
  • 打赏
  • 举报
回复
普通窗体没有parent,那getparent返回0
涵数返回false.
mdi窗体有parent,那涵数返回true
LoveDana 2001-11-16
  • 打赏
  • 举报
回复
楼上,你只判断了是否为MDI窗体。而且,普通窗体也没有Parent吖。现在的关键是:区分MDI和普通窗体。
xfflean 2001-11-14
  • 打赏
  • 举报
回复
Declare Function GetParent Lib "user32" Alias "GetParent" (ByVal hwnd As Long) As Long
Function isMdiForm(hwnd as long) as Boolean
dim mdiformhwnd as long
mdiformhwnd=GetParent(hwnd)
if mdiformhwnd=0 then
IsMdiform=False 'No MDI
Exit Function
else
isMdiForm=True
exit function
end if
end function
Wesely 2001-11-13
  • 打赏
  • 举报
回复
看看这个Form有没有Parent。
Ganzl 2001-11-13
  • 打赏
  • 举报
回复
那样的话只有使用api了
:-)
LoveDana 2001-11-13
  • 打赏
  • 举报
回复
楼上,如果我只有窗体的.hwnd,怎么办?
Ganzl 2001-11-13
  • 打赏
  • 举报
回复
一样,不过声明的时候不是form型而是object或variant了
LoveDana 2001-11-13
  • 打赏
  • 举报
回复
楼上,如果我是在dll里面判断引用的窗体呢?你的方法就不可以通过了。
Ganzl 2001-11-13
  • 打赏
  • 举报
回复
使用窗体的mdichild属性,对于mdiform来说,没有mdichild属性,可以捕获这一错误:
Dim x As Form

On Error Resume Next
For Each x In Forms
MsgBox x.MDIChild
If Err.Number <> 0 Then
MsgBox "false"
Err.Clear
End If
Next

以上程序调试通过

LoveDana 2001-11-13
  • 打赏
  • 举报
回复
请问楼上,到底是哪个API?
ColderRain 2001-11-13
  • 打赏
  • 举报
回复
use api
TMenuItem显示在右侧 不使用MDI制作子窗体 不使用标题栏移动窗体 不使用标题栏移动窗口 两行hint 从XML文件动态创建菜单 从另外MDI子窗口读数据 使控件具有阴影效果 使每个MDIChild填充整个主窗口区域 使用Enter键替代Tab键 使用动画效果关闭窗口 使用动画方式打开窗体 使用帮助文件 使用状态栏显示hint 使用系统图标 使窗体不能移动 关闭一个MDI窗体 创建一个能改变大小的无边界窗体 创建半透明窗体 创建圆角窗体 创建透明窗体 判断窗体是modal 制作动画应用程序图标 制作可移动不能改变大小的窗体 制作永远最小化窗口 制作透明窗口 取和设置鼠标位置 取鼠标指针下面的活动TWinControl 启动时隐藏主窗口 在 window xp 使用阴影效果 在TCombobox内显示多行文本 在TScrollBox上显示窗体 在你的程序中使用 Win XP 可视风格 在窗体上制造多边形洞 在窗体上挖洞 在窗体周围画彩色轮廓 定位messagebox 实现窗口的最小化动画效果 将InputQuery定位在窗体居中位置 怪异窗体 手动改变窗体比例 抓屏 拖拽时显示窗口内容 捕获主窗体WM_MOVE消息 改变Hint字体 改变Hint的显示时间 改变MessageDlg的按钮标题 最小化控件 最小化第二个窗口到任务栏 查找窗体注册类 格式化MessageDlg 检查PopUp菜单是否打开 检查控件是否被其它窗口遮掩 添加菜单项到系统菜单 渐变色填充窗体 特效窗口 移动指针到当前具有焦点的控件 移除系统菜单项 自动关闭TCommonDialog 运行时改变MainForm 运行时移动控件 运行时移动窗口控件 选中或取消其它窗口的复选框 通过在标题栏上右击缩小窗口 防止 Windows 最小化窗体 防止控件重画 防止窗体改变大小和移动 隐藏标题栏 隐藏窗体的最大化和最小化按钮
VB窗体控件大小随窗体大小变化自動調整 有时窗体变化后,如改变分辨率后控件大小却不能随之改变。手工代码调整实在麻烦,下面的模块实现自动查找窗体上控件并使其改变大小以适应窗体变化。 在Form的Resize事件中调用函数Resize_All就能实现控件自动调整大小,如: Private Sub Form_Resize() Dim H, i As Integer On Error Resume Next Resize_ALL Me 'Me是窗体名,Form1,Form2等等都可以 End Sub 在模块中添加以下代码: Public Type ctrObj Name As String Index As Long Parrent As String Top As Long Left As Long Height As Long Width As Long ScaleHeight As Long ScaleWidth As Long End Type Private FormRecord() As ctrObj Private ControlRecord() As ctrObj Private bRunning As Boolean Private MaxForm As Long Private MaxControl As Long Private Const WM_NCLBUTTONDOWN = &HA1 Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function ReleaseCapture Lib "USER32" () As Long Function ActualPos(plLeft As Long) As Long If plLeft < 0 Then ActualPos = plLeft + 75000 Else ActualPos = plLeft End If End Function Function FindForm(pfrmIn As Form) As Long Dim i As Long FindForm = -1 If MaxForm > 0 Then For i = 0 To (MaxForm - 1) If FormRecord(i).Name = pfrmIn.Name Then FindForm = i Exit Function End If Next i End If End Function Function AddForm(pfrmIn As Form) As Long Dim FormControl As Control Dim i As Long ReDim Preserve FormRecord(MaxForm + 1) FormRecord(MaxForm).Name = pfrmIn.Name FormRecord(MaxForm).Top = pfrmIn.Top FormRecord(MaxForm).Left = pfrmIn.Left FormRecord(MaxForm).Height = pfrmIn.Height FormRecord(MaxForm).Width = pfrmIn.Width FormRecord(MaxForm).ScaleHeight = pfrmIn.ScaleHeight FormRecord(MaxForm).ScaleWidth = pfrmIn.ScaleWidth AddForm = MaxForm MaxForm = MaxForm + 1 For Each FormControl In pfrmIn i = FindControl(FormControl, pfrmIn.Name) If i < 0 Then i = AddControl(FormControl, pfrmIn.Name) End If Next FormControl End Function Function FindControl(inControl As Control, inName As String) As Long Dim i As Long FindControl = -1 For i = 0 To (MaxControl - 1) If ControlRecord(i).Parrent = inName Then If ControlRecord(i).Name = inControl.Name Then On Error Resume Next If ControlRecord(i).Index = inControl.Index Then FindControl = i Exit Function End If On Error GoTo 0 End If End If Next i End Function Function AddControl(inControl As Control, inName As String) As Long ReDim Preserve ControlRecord(MaxControl + 1) On Error Resume Next ControlRecord(MaxControl).Name = inControl.Name ControlRecord(MaxControl).Index = inControl.Index ControlRecord(MaxControl).Parrent = inName If TypeOf inControl Is Line Then ControlRecord(MaxControl).Top = inControl.Y1 ControlRecord(MaxControl).Left = ActualPos(inControl.X1) ControlRecord(MaxControl).Height = inControl.Y2 ControlRecord(MaxControl).Width = ActualPos(inControl.X2) Else ControlRecord(MaxControl).Top = inControl.Top ControlRecord(MaxControl).Left = ActualPos(inControl.Left) ControlRecord(MaxControl).Height = inControl.Height ControlRecord(MaxControl).Width = inControl.Width End If inControl.IntegralHeight = False On Error GoTo 0 AddControl = MaxControl MaxControl = MaxControl + 1 End Function Function PerWidth(pfrmIn As Form) As Long Dim i As Long i = FindForm(pfrmIn) If i < 0 Then i = AddForm(pfrmIn) End If PerWidth = (pfrmIn.ScaleWidth * 100) \ FormRecord(i).ScaleWidth End Function Function PerHeight(pfrmIn As Form) As Double Dim i As Long i = FindForm(pfrmIn) If i < 0 Then i = AddForm(pfrmIn) End If PerHeight = (pfrmIn.ScaleHeight * 100) \ FormRecord(i).ScaleHeight End Function Public Sub ResizeControl(inControl As Control, pfrmIn As Form) On Error Resume Next Dim i As Long Dim widthfactor As Single, heightfactor As Single Dim minFactor As Single Dim yRatio, xRatio, lTop, lLeft, lWidth, lHeight As Long yRatio = PerHeight(pfrmIn) xRatio = PerWidth(pfrmIn) i = FindControl(inControl, pfrmIn.Name) If inControl.Left < 0 Then lLeft = CLng(((ControlRecord(i).Left * xRatio) \ 100) - 75000) Else lLeft = CLng((ControlRecord(i).Left * xRatio) \ 100) End If lTop = CLng((ControlRecord(i).Top * yRatio) \ 100) lWidth = CLng((ControlRecord(i).Width * xRatio) \ 100) lHeight = CLng((ControlRecord(i).Height * yRatio) \ 100) If TypeOf inControl Is Line Then If inControl.X1 < 0 Then inControl.X1 = CLng(((ControlRecord(i).Left * xRatio) \ 100) - 75000) Else inControl.X1 = CLng((ControlRecord(i).Left * xRatio) \ 100) End If inControl.Y1 = CLng((ControlRecord(i).Top * yRatio) \ 100) If inControl.X2 < 0 Then inControl.X2 = CLng(((ControlRecord(i).Width * xRatio) \ 100) - 75000) Else inControl.X2 = CLng((ControlRecord(i).Width * xRatio) \ 100) End If inControl.Y2 = CLng((ControlRecord(i).Height * yRatio) \ 100) Else inControl.Move lLeft, lTop, lWidth, lHeight inControl.Move lLeft, lTop, lWidth inControl.Move lLeft, lTop End If End Sub Public Sub ResizeForm(pfrmIn As Form) Dim FormControl As Control Dim isVisible As Boolean Dim StartX, StartY, MaxX, MaxY As Long Dim bNew As Boolean If Not bRunning Then bRunning = True If FindForm(pfrmIn) < 0 Then bNew = True Else bNew = False End If If pfrmIn.Top < 30000 Then isVisible = pfrmIn.Visible On Error Resume Next If Not pfrmIn.MDIChild Then On Error GoTo 0 ' ' pfrmIn.Visible = False Else If bNew Then StartY = pfrmIn.Height StartX = pfrmIn.Width On Error Resume Next For Each FormControl In pfrmIn If FormControl.Left + FormControl.Width + 200 > MaxX Then MaxX = FormControl.Left + FormControl.Width + 200 End If If FormControl.Top + FormControl.Height + 500 > MaxY Then MaxY = FormControl.Top + FormControl.Height + 500 End If If FormControl.X1 + 200 > MaxX Then MaxX = FormControl.X1 + 200 End If If FormControl.Y1 + 500 > MaxY Then MaxY = FormControl.Y1 + 500 End If If FormControl.X2 + 200 > MaxX Then MaxX = FormControl.X2 + 200 End If If FormControl.Y2 + 500 > MaxY Then MaxY = FormControl.Y2 + 500 End If Next FormControl On Error GoTo 0 pfrmIn.Height = MaxY pfrmIn.Width = MaxX End If On Error GoTo 0 End If For Each FormControl In pfrmIn ResizeControl FormControl, pfrmIn Next FormControl On Error Resume Next If Not pfrmIn.MDIChild Then On Error GoTo 0 pfrmIn.Visible = isVisible Else If bNew Then pfrmIn.Height = StartY pfrmIn.Width = StartX For Each FormControl In pfrmIn ResizeControl FormControl, pfrmIn Next FormControl End If End If On Error GoTo 0 End If bRunning = False End If End Sub Public Sub SaveFormPosition(pfrmIn As Form) Dim i As Long If MaxForm > 0 Then For i = 0 To (MaxForm - 1) If FormRecord(i).Name = pfrmIn.Name Then FormRecord(i).Top = pfrmIn.Top FormRecord(i).Left = pfrmIn.Left FormRecord(i).Height = pfrmIn.Height FormRecord(i).Width = pfrmIn.Width Exit Sub End If Next i AddForm (pfrmIn) End If End Sub Public Sub RestoreFormPosition(pfrmIn As Form) Dim i As Long If MaxForm > 0 Then For i = 0 To (MaxForm - 1) If FormRecord(i).Name = pfrmIn.Name Then If FormRecord(i).Top < 0 Then pfrmIn.WindowState = 2 ElseIf FormRecord(i).Top < 30000 Then pfrmIn.WindowState = 0 pfrmIn.Move FormRecord(i).Left, FormRecord(i).Top, FormRecord(i).Width, FormRecord(i).Height Else pfrmIn.WindowState = 1 End If Exit Sub End If Next i End If End Sub Public Sub Resize_ALL(Form_Name As Form) Dim OBJ As Object For Each OBJ In Form_Name ResizeControl OBJ, Form_Name Next OBJ End Sub Public Sub DragForm(frm As Form) On Local Error Resume Next Call ReleaseCapture Call SendMessage(frm.hwnd, WM_NCLBUTTONDOWN, 2, 0) End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧