| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5612 人关注过本帖
标题:怎么让窗口在最前端显示
只看楼主 加入收藏
luguojun
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2005-9-7
收藏
 问题点数:0 回复次数:4 
怎么让窗口在最前端显示
在程序里面,通过鼠标动作,调出来的窗口在最前端显示,始终让他获得焦点
搜索更多相关主题的帖子: 窗口 
2008-08-31 13:09
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:0 
若你的程序中有十个窗体,想让其中的一个窗体显示在最前端:
窗体名称.Show 1

若是象QQ面板那样显示在最前,则要用到API函数"SetWindowPos"
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

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2008-08-31 14:02
dao1975
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-9-1
收藏
得分:0 
窗口上放一个时控器,Timer1.Interval值设为 1
编写以下代码,就可以让你的窗口一直在最上层了

Option Explicit
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Declare Function ClipCursorBynum& Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim mouse As RECT
Dim pid As Long
Dim hProcess As Long '存放进程句柄


Private Sub Timer2_Timer()
Dim hwnd As Long
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, &O1 + &O2
hwnd = FindWindow(vbNullString, "你的窗口名")
GetWindowThreadProcessId hwnd, pid   '获取进程标识符
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid)
SetForegroundWindow hwnd '使指定窗口为当前活动窗口
mouse.Left = Me.Left / Screen.TwipsPerPixelX
mouse.Top = Me.Top / Screen.TwipsPerPixelY
mouse.Right = (Me.Left + Me.Width) / Screen.TwipsPerPixelX
mouse.Bottom = (Me.Top + Me.Height) / Screen.TwipsPerPixelY
ClipCursor mouse
End Sub
2008-09-01 07:28
jrs123
Rank: 2
等 级:论坛游民
威 望:1
帖 子:627
专家分:14
注 册:2006-9-5
收藏
得分:0 
你想要的是悬浮窗体吗?鼠标靠近就弹出,窗体始终在最前.
下面是一个下拉式悬浮窗的代码:(悬浮窗隐藏在屏幕上方:)
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal ptx As Long, ByVal pty As Long) As Long
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 Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal X As Long, _
    ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Const HWND_TOPMOST = -1
Private Type POINTAPI
        X As Long
        Y As Long
End Type
Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
     End Type
Private Is_Move_B As Boolean
Private Is_Movestar_B As Boolean
Private MyRect As RECT
Private MyPoint As POINTAPI
Private Movex As Long, Movey As Long
Private max As Long
Private Sub Form_Load()
        Timer1.Interval = 50: Timer2.Interval = 1000
        Form1.BackColor = vbBlue
        Get_Windows_Rect
        Picture1.Width = 10700
        Form1.Width = 10770
     End Sub
Sub Get_Windows_Rect()
        Dim dl&
        max = 2200: Form1.Height = max '窗体高度调整
        Form1.Top = 0
        dl& = GetWindowRect(Form1.hwnd, MyRect)
        End Sub
Private Sub Form_Paint()
        If PtInRect(MyRect, MyPoint.X, MyPoint.Y) = 0 Then
             SetWindowPos Me.hwnd, HWND_TOPMOST, Me.Left / Screen.TwipsPerPixelX, _
                  Me.Top \ Screen.TwipsPerPixelY, Me.Width \ Screen.TwipsPerPixelX, _
                  Form1.Height \ Screen.TwipsPerPixelY, 0
        End If
End Sub
Private Sub Timer1_Timer()
       Dim dl&
       dl& = GetCursorPos(MyPoint)
           If (PtInRect(MyRect, MyPoint.X, MyPoint.Y) And _
                     Form1.Height = max) Or MyPoint.Y <= 30 Then
                         Form1.BackColor = vbBlue
                Form1.Height = max
                         If MyPoint.X - MyRect.Left <= 10 Or Is_Movestar_B Then
                   Screen.MousePointer = 15
                   Is_Move_B = True
                Else
                   Screen.MousePointer = 0
                   Is_Move_B = False
          End If
                Else
               If Not Is_Movestar_B Then
                  Form1.Height = 30
               End If
            End If
End Sub

[[it] 本帖最后由 jrs123 于 2008-9-1 21:39 编辑 [/it]]
2008-09-01 21:34
twsgl
Rank: 1
等 级:新手上路
帖 子:136
专家分:5
注 册:2007-6-15
收藏
得分:0 
如果你这位老兄还上学的话就去看看课本
2008-09-03 22:56
快速回复:怎么让窗口在最前端显示
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017017 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved