Board logo

标题: (VB)制作TopMost窗口 [打印本页]

作者: 毛主席    时间: 2007-10-8 10:34     标题: (VB)制作TopMost窗口

制作TopMost窗口
     制作TopMost窗口很简单,只需一个API函数就可以实现。
下面的例子就实现了这个功能。
>>步骤1----建立新工程,在窗体上放置一个CommandButton按钮。
>>步骤2----编写如下代码:

Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_TOPMOST = -1
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 Sub Command1_Click()
    SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE _
    Or SWP_NOSIZE
End Sub

>>步骤3----编译运行,点击Command1,看看是不是始终位于最上层。
要去掉TopMost属性,只要将参数HWND_TOPMOST换成HWND_NOTOPMOST,
当然,得说明常量:HWND_NOTOPMOST = -2




欢迎光临 ::电驴基地:: (https://www.cmule.com/) Powered by Discuz! 6.0.0