添加一個窗體:
成都創新互聯專注于企業全網整合營銷推廣、網站重做改版、通城網站定制設計、自適應品牌網站建設、H5場景定制、商城系統網站開發、集團公司官網建設、外貿營銷網站建設、高端網站制作、響應式網頁設計等建站業務,價格優惠性價比高,為通城等各大城市提供網站開發制作服務。
窗體代碼:
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
你說的是不是調用另外一個窗口。。。
假設你有兩個窗體
一個叫做form1
一個叫做form2
在form1中添加一個按鈕,當點擊按鈕的時候將調用form2的窗口并隱藏form1窗口。。
這時你可以雙擊按鈕給他添加如下代碼:
form2.show();
//顯示form2這個窗體
form1.hide();
//隱藏form1這個窗體
這樣就可以了...這是在VB中調用窗口,如果是在C#里面比較麻煩,要先實例化才可以...
Form2
form2=new
Form2();
//先實例化Form2窗體
form2.show();
//調用他的窗體
this.hide();
//this是當前的意思,就是說隱藏當前窗體Form1
1、沒有事件是直接由最小化、還原觸發的,它們都會觸發SizeChanged事件。所以你可以寫主窗體的SizeChanged事件來控制副窗體顯隱,順便改變副窗體的相對位置;
2、在SizeChanged事件中,通過判斷窗體的WindowState屬性來確定用戶是最小化還是還原了;(FormWindowState.Minimized和FormWindowState.Normal枚舉)
3、調用副窗體的BringToFront方法可以把副窗體帶到最前面來
首先要添加兩個窗體,假設第一個窗體名為Form1,第二個窗體名為Form2。在Form1窗體中添加個按鈕Command1。按鈕單擊事件的代碼為:
Private Sub Command1_Click()
Form2.Show '用show方法加載并且顯示名為Form2的窗體
End Sub
show 方法后面省略了兩個參數即Form2.Show 0或Form2.Show 1此參數可缺省。可自行運行驗證
網頁名稱:vb.net隱藏其他窗口,vb隱藏所有控件
文章鏈接:http://vcdvsql.cn/article0/hshooo.html
成都網站建設公司_創新互聯,為您提供網站維護、網站建設、自適應網站、微信公眾號、網站內鏈、企業網站制作
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯