请问在vb怎样把窗体显示在最前方。我是想用户在播放powerpoint时在屏幕左上角显示一个统计信息窗体。

解决方案 »

  1.   

    建立一个"总在最前面总在最前面"(TopMos t)的窗口。具体的做法如下: 在VB程序中加入如下的声明: Declare Function SetWindowPos Lib"user"(Byval h%,Byval hb%,Byval x%,Byval y %,Byval cx%,Byval cy%,Byval f%)As Integer Global Const SWP_NOMOVE=2 Global Const SWP_NOSIZE=1 Global Const HWND_TOPMOST=-1 Global Const HWND _NOTOPMOST=-2 Global Const FLAGS=SWP _NOMOVE Or SWP_NOSIZE 假设要把窗体frmExample设置成总在最前面的窗口,只要在frmExample窗体的Form_Load过程里加入以下代码: Dim success% success=SetWindowPos(frmExam-ple.hWnd,HWND_TOPMOST,0,0,0,0,FLAGS) 如果要取消总在最前面的特性,则可以执行如下的代码: success=SetWindowPos(frmExa-mple.hWnd,HWND_NOTOPMOST,0,0,0,0,FLAGS) 
    success不等于0表示SetWindowPos执行成功
      

  2.   

    SetWindowPos API.
    SetWindowPos 窗体句柄, HWND_TOPMOST, left, top, width, height , SWP_SHOWWINDOW
      

  3.   

    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 Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1
    Private Const HWND_TOPMOST = -1
    Private Sub Form_Load()
        Me.Left = 0
        Me.Top = 0
        '把表單總是置于最上層
        Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE)
    End Sub