VB弹出前台窗口问题

来源:百度知道 编辑:UC知道 时间:2024/09/26 02:18:54
我写了个VB程序,运行后就把主界面隐藏了,而达到某个条件用form1.show显示主窗体后却不是前台的激活窗口,只是在任务栏里闪,我网上搜了下,尝试过用setforegroundwindow,setactivewindow等都不能使它弹到前台,怎么能够实现?尽量详细点,最好自己先测试下

绝对成功..

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds 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
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1

Private Sub Command1_Click()
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, &H2 Or &H1
AppActivate Me.Caption
SetWindowPos Me.hwnd, -2, 0, 0, 0, 0, &H2 Or &H1
End Sub

哪有这么麻烦!

me.hide
form1.show

就好了

不过也有可能你把form1最小化了,此时就要恢复窗口到最大化,恢复原值还未测试过