十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
在调用安装窗口时就指定为隐藏啊,如Shell "安装程序文件名",vbHide '隐藏运行 如果是针对已运行的程序,可以用API来隐藏窗体比如我有一个“计算器”的程序在运行,点下面这个按钮就可以将它隐藏了Option Explicit
新晃网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站开发等网站项目制作,到程序开发,运营维护。创新互联成立与2013年到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联。
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_HIDE = 0 Private Sub Command1_Click()
Dim 窗口句柄 As Long
窗口句柄 = FindWindow(vbNullString, "计算器")
ShowWindow 窗口句柄, SW_HIDE
End Sub
1、没有事件是直接由最小化、还原触发的,它们都会触发SizeChanged事件。所以你可以写主窗体的SizeChanged事件来控制副窗体显隐,顺便改变副窗体的相对位置;
2、在SizeChanged事件中,通过判断窗体的WindowState属性来确定用户是最小化还是还原了;(FormWindowState.Minimized和FormWindowState.Normal枚举)
3、调用副窗体的BringToFront方法可以把副窗体带到最前面来
添加一个窗体:
窗体代码:
Option
Explicit
Private
Sub
Form_Load()
'设置窗体过程
SetWindowHook
Me.hWnd
End
Sub
Private
Sub
Form_Unload(Cancel
As
Integer)
'取消窗体过程。
DelWindowHook
End
Sub
添加一个模块,模块代码:
Option
Explicit
Private
Declare
Function
ShowWindow
Lib
"user32"
_
(ByVal
hWnd
As
Long,
ByVal
nCmdShow
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
Private
Declare
Function
CallWindowProc
Lib
"user32"
_
Alias
"CallWindowProcA"
_
(ByVal
lpPrevWndFunc
As
Long,
ByVal
hWnd
As
Long,
ByVal
Msg
As
Long,
_
ByVal
wParam
As
Long,
ByVal
lParam
As
Long)
As
Long
Private
Declare
Function
RegisterHotKey
Lib
"user32"
_
(ByVal
hWnd
As
Long,
ByVal
id
As
Long,
_
ByVal
fsModifiers
As
Long,
ByVal
vk
As
Long)
As
Long
Private
Declare
Function
UnregisterHotKey
Lib
"user32"
_
(ByVal
hWnd
As
Long,
ByVal
id
As
Long)
As
Long
Private
Declare
Function
GetWindowText
Lib
"user32"
Alias
"GetWindowTextA"
_
(ByVal
hWnd
As
Long,
ByVal
lpString
As
String,
ByVal
cch
As
Long)
As
Long
Private
Declare
Function
GetClassName
Lib
"user32"
Alias
"GetClassNameA"
_
(ByVal
hWnd
As
Long,
ByVal
lpClassName
As
String,
ByVal
nMaxCount
As
Long)
As
Long
Private
Declare
Function
GetForegroundWindow
Lib
"user32"
()
As
Long
Private
Const
GWL_WNDPROC
=
(-4)
Private
Const
WM_HOTKEY
=
H312
Private
Const
VK_F7
=
H76
Dim
hPrevWndProc
As
Long
'原先的窗口过程。
Dim
hPrevHandle
As
Long
'原先的窗口句柄。
Dim
hHotKey
As
Long
'热键句柄。
Dim
hH
As
Long
'隐藏的窗口句柄。
Private
Function
GetClassNameStr(ByVal
hWnd
As
Long)
As
String
'获取窗体的类名。
Dim
TempStr
As
String,
Rc
As
Long
Const
NAME_MAX_LEN
=
256
TempStr
=
Space(NAME_MAX_LEN)
Rc
=
GetClassName(hWnd,
TempStr,
NAME_MAX_LEN)
GetClassNameStr
=
StrConv(LeftB$(StrConv(TempStr,
_
vbFromUnicode),
Rc),
vbUnicode)
End
Function
Private
Function
GetWindowTextStr(ByVal
hWnd
As
Long)
As
String
'获取窗体标题。
Dim
TempStr
As
String,
Rc
As
Long
Const
NAME_MAX_LEN
=
256
TempStr
=
Space(NAME_MAX_LEN)
Rc
=
GetWindowText(hWnd,
TempStr,
NAME_MAX_LEN)
GetWindowTextStr
=
StrConv(LeftB$(StrConv(TempStr,
_
vbFromUnicode),
Rc),
vbUnicode)
End
Function
Private
Function
WindowProc(ByVal
hWnd
As
Long,
_
ByVal
uMsg
As
Long,
ByVal
wParam
As
Long,
_
ByVal
lParam
As
Long)
As
Long
'新的窗口过程。
Dim
hNowWindow
As
Long
If
uMsg
=
WM_HOTKEY
And
wParam
=
101
Then
'如果按下了指定热键。
hNowWindow
=
GetForegroundWindow()
If
GetClassNameStr(hNowWindow)
=
"Notepad"
_
And
GetWindowTextStr(hNowWindow)
=
_
"无标题
-
记事本"
And
hH
=
Then
'如果当前的活动窗口是无标题记事本。
'隐藏窗体。
hH
=
hNowWindow
ShowWindow
hH,
ElseIf
hH
Then
'显示窗体
ShowWindow
hH,
5
hH
=
End
If
End
If
'调用原有的窗体过程。
WindowProc
=
CallWindowProc(hPrevWndProc,
_
hWnd,
uMsg,
wParam,
lParam)
End
Function
Public
Sub
SetWindowHook(ByVal
hWnd
As
Long)
'设置新的窗口过程。
hPrevHandle
=
hWnd
hPrevWndProc
=
SetWindowLong
_
(hPrevHandle,
GWL_WNDPROC,
AddressOf
WindowProc)
'设置热键(F7)。
hHotKey
=
RegisterHotKey(hPrevHandle,
101,
0,
VK_F7)
End
Sub
Public
Sub
DelWindowHook()
'恢复原有的窗口过程。
SetWindowLong
hPrevHandle,
GWL_WNDPROC,
hPrevWndProc
'取消热键
UnregisterHotKey
hPrevHandle,
hHotKey
End
Sub
'刚才我用自己的程序将QQ窗口隐藏了,句柄在,还能够重显.方法如下:
'第一步,获取操作窗口的句柄,(非问不述)
'调用api函数
setwindowpos
隐藏目标窗口.
Public
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
SetWindowPos
lngWindow,
-1,
0,
0,
0,
0,
H80
'隐藏,注意-1表示顶层,但隐藏了,所以怎么设都没关系.
SetWindowPos
lngWindow,
-1,
0,
0,
0,
0,
H40
'就可以显示了.
'注这只是隐藏指定窗口,而不能达到隐藏进程的目的.
你说的是不是调用另外一个窗口。。。
假设你有两个窗体
一个叫做form1
一个叫做form2
在form1中添加一个按钮,当点击按钮的时候将调用form2的窗口并隐藏form1窗口。。
这时你可以双击按钮给他添加如下代码:
form2.show();
//显示form2这个窗体
form1.hide();
//隐藏form1这个窗体
这样就可以了...这是在VB中调用窗口,如果是在C#里面比较麻烦,要先实例化才可以...
Form2
form2=new
Form2();
//先实例化Form2窗体
form2.show();
//调用他的窗体
this.hide();
//this是当前的意思,就是说隐藏当前窗体Form1
首先要添加两个窗体,假设第一个窗体名为Form1,第二个窗体名为Form2。在Form1窗体中添加个按钮Command1。按钮单击事件的代码为:
Private Sub Command1_Click()
Form2.Show '用show方法加载并且显示名为Form2的窗体
End Sub
show 方法后面省略了两个参数即Form2.Show 0或Form2.Show 1此参数可缺省。可自行运行验证