vb.net隐藏其他窗口,vb隐藏所有控件

VB如何实现:隐藏外部程序窗口

添加一个窗体:

成都创新互联专注于企业全网整合营销推广、网站重做改版、通城网站定制设计、自适应品牌网站建设、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

VB显示新窗口和隐藏窗口代码

你说的是不是调用另外一个窗口。。。

假设你有两个窗体

一个叫做form1

一个叫做form2

在form1中添加一个按钮,当点击按钮的时候将调用form2的窗口并隐藏form1窗口。。

这时你可以双击按钮给他添加如下代码:

form2.show();

//显示form2这个窗体

form1.hide();

//隐藏form1这个窗体

这样就可以了...这是在VB中调用窗口,如果是在C#里面比较麻烦,要先实例化才可以...

Form2

form2=new

Form2();

//先实例化Form2窗体

form2.show();

//调用他的窗体

this.hide();

//this是当前的意思,就是说隐藏当前窗体Form1

VB.NET两个窗体怎么同步显示或隐藏?

1、没有事件是直接由最小化、还原触发的,它们都会触发SizeChanged事件。所以你可以写主窗体的SizeChanged事件来控制副窗体显隐,顺便改变副窗体的相对位置;

2、在SizeChanged事件中,通过判断窗体的WindowState属性来确定用户是最小化还是还原了;(FormWindowState.Minimized和FormWindowState.Normal枚举)

3、调用副窗体的BringToFront方法可以把副窗体带到最前面来

VB.NET按下一个按钮如何弹出第三个窗口,隐藏第一个和第二个

首先要添加两个窗体,假设第一个窗体名为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://scyanting.com/article/hshooo.html