在調(diào)用安裝窗口時(shí)就指定為隱藏啊,如Shell "安裝程序文件名",vbHide '隱藏運(yùn)行 如果是針對已運(yùn)行的程序,可以用API來隱藏窗體比如我有一個(gè)“計(jì)算器”的程序在運(yùn)行,點(diǎn)下面這個(gè)按鈕就可以將它隱藏了Option Explicit
新晃網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站開發(fā)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)成立與2013年到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。
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, "計(jì)算器")
ShowWindow 窗口句柄, SW_HIDE
End Sub
1、沒有事件是直接由最小化、還原觸發(fā)的,它們都會觸發(fā)SizeChanged事件。所以你可以寫主窗體的SizeChanged事件來控制副窗體顯隱,順便改變副窗體的相對位置;
2、在SizeChanged事件中,通過判斷窗體的WindowState屬性來確定用戶是最小化還是還原了;(FormWindowState.Minimized和FormWindowState.Normal枚舉)
3、調(diào)用副窗體的BringToFront方法可以把副窗體帶到最前面來
添加一個(gè)窗體:
窗體代碼:
Option
Explicit
Private
Sub
Form_Load()
'設(shè)置窗體過程
SetWindowHook
Me.hWnd
End
Sub
Private
Sub
Form_Unload(Cancel
As
Integer)
'取消窗體過程。
DelWindowHook
End
Sub
添加一個(gè)模塊,模塊代碼:
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
'獲取窗體標(biāo)題。
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)
=
_
"無標(biāo)題
-
記事本"
And
hH
=
Then
'如果當(dāng)前的活動(dòng)窗口是無標(biāo)題記事本。
'隱藏窗體。
hH
=
hNowWindow
ShowWindow
hH,
ElseIf
hH
Then
'顯示窗體
ShowWindow
hH,
5
hH
=
End
If
End
If
'調(diào)用原有的窗體過程。
WindowProc
=
CallWindowProc(hPrevWndProc,
_
hWnd,
uMsg,
wParam,
lParam)
End
Function
Public
Sub
SetWindowHook(ByVal
hWnd
As
Long)
'設(shè)置新的窗口過程。
hPrevHandle
=
hWnd
hPrevWndProc
=
SetWindowLong
_
(hPrevHandle,
GWL_WNDPROC,
AddressOf
WindowProc)
'設(shè)置熱鍵(F7)。
hHotKey
=
RegisterHotKey(hPrevHandle,
101,
0,
VK_F7)
End
Sub
Public
Sub
DelWindowHook()
'恢復(fù)原有的窗口過程。
SetWindowLong
hPrevHandle,
GWL_WNDPROC,
hPrevWndProc
'取消熱鍵
UnregisterHotKey
hPrevHandle,
hHotKey
End
Sub
'剛才我用自己的程序?qū)Q窗口隱藏了,句柄在,還能夠重顯.方法如下:
'第一步,獲取操作窗口的句柄,(非問不述)
'調(diào)用api函數(shù)
setwindowpos
隱藏目標(biāo)窗口.
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表示頂層,但隱藏了,所以怎么設(shè)都沒關(guān)系.
SetWindowPos
lngWindow,
-1,
0,
0,
0,
0,
H40
'就可以顯示了.
'注這只是隱藏指定窗口,而不能達(dá)到隱藏進(jìn)程的目的.
你說的是不是調(diào)用另外一個(gè)窗口。。。
假設(shè)你有兩個(gè)窗體
一個(gè)叫做form1
一個(gè)叫做form2
在form1中添加一個(gè)按鈕,當(dāng)點(diǎn)擊按鈕的時(shí)候?qū)⒄{(diào)用form2的窗口并隱藏form1窗口。。
這時(shí)你可以雙擊按鈕給他添加如下代碼:
form2.show();
//顯示form2這個(gè)窗體
form1.hide();
//隱藏form1這個(gè)窗體
這樣就可以了...這是在VB中調(diào)用窗口,如果是在C#里面比較麻煩,要先實(shí)例化才可以...
Form2
form2=new
Form2();
//先實(shí)例化Form2窗體
form2.show();
//調(diào)用他的窗體
this.hide();
//this是當(dāng)前的意思,就是說隱藏當(dāng)前窗體Form1
首先要添加兩個(gè)窗體,假設(shè)第一個(gè)窗體名為Form1,第二個(gè)窗體名為Form2。在Form1窗體中添加個(gè)按鈕Command1。按鈕單擊事件的代碼為:
Private Sub Command1_Click()
Form2.Show '用show方法加載并且顯示名為Form2的窗體
End Sub
show 方法后面省略了兩個(gè)參數(shù)即Form2.Show 0或Form2.Show 1此參數(shù)可缺省??勺孕羞\(yùn)行驗(yàn)證