为什么关闭子窗体时,整个系统失去焦点

oceanmap 2002-08-21 09:17:45
我的系统中使用了一个mdi窗体,几个普通窗体,将普通窗体的mdichild设置为false,程序中调用这些窗体时再使用API函数SetParent将这些窗体设置位mdi窗体的子窗体,但是当关闭这些窗体时整个系统失去焦点,直接被其他系统覆盖了,究竟什么原因,如何解决,望高手帮忙!
...全文
67 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hfycl 2002-08-22
  • 打赏
  • 举报
回复
mark
Gulang68 2002-08-22
  • 打赏
  • 举报
回复
Option Explicit

'新建两个窗体、一个按钮、一个图片框。
'// Window attribute functions
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long


'// Z-order and placement APIs
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

'// Focus and activation functions
Private Declare Function winSetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Private Declare Function winGetFocus Lib "user32" Alias "GetFocus" () As Long

Private Const GWL_STYLE = (-16)
Private Const WS_CHILD = &H40000000

' SetWindowPos Flags
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOREDRAW = &H8
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_NOCOPYBITS = &H100
Private Const SWP_NOOWNERZORDER = &H200

Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER

' SetWindowPos() hwndInsertAfter values
Private Const HWND_TOP = 0
Private Const HWND_BOTTOM = 1
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Private Sub Command1_Click()
Dim hWndPage As Long
Dim hForm As VB.Form
Dim hWndBin As Long
Dim dwStyle As Long
Set hForm = New Form2
Load hForm
hWndPage = hForm.hwnd
hWndBin = Picture1.hwnd
dwStyle = GetWindowLong(hWndPage, GWL_STYLE)
dwStyle = dwStyle Or WS_CHILD
Call SetWindowLong(hWndPage, GWL_STYLE, dwStyle)
Call SetParent(hWndPage, hWndBin)
Call SetWindowPos(hWndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE)
hForm.Visible = True
End Sub

================================================================
我是一个兵,来自老百姓。
renjunjun 2002-08-22
  • 打赏
  • 举报
回复
你试试在关闭其它窗体的时候加上一句:
MainForm.SetFocus
visualcpu 2002-08-22
  • 打赏
  • 举报
回复
当然会这样了!
建议不要用MDI窗体,麻烦S了
petkoala 2002-08-22
  • 打赏
  • 举报
回复
你的问题和我的有点类似吧!!

我的问题是“关于“叉”的问题!!(还有个尾巴~) ”

你能帮我解决么~~~~~~
heimayi 2002-08-22
  • 打赏
  • 举报
回复
egge@163.com
我可以帮你看看!!1
petkoala 2002-08-22
  • 打赏
  • 举报
回复
你的问题和我的有点类似吧!!

我的问题是“关于“叉”的问题!!(还有个尾巴~) ”

你能帮我解决么~~~~~~

7,765

社区成员

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

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