CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  基础类

窗体问题:如何使某个窗体永远在最上层

楼主jxgzay(jxgzay)2005-07-04 10:55:20 在 VB / 基础类 提问

form1为全屏最大华窗体,FORM2为播放AVI的演示窗体,FORM1下一个COMMAND1,  
   
  Private   Sub   Command1_Click()  
  Form2.Show  
  End   Sub  
  现在当FORM1获得焦点时,FORM2就被覆盖了,如何让form2在最上层?我用:当FORM2失去焦点时或FORM1获得焦点时,Form2.ZOrder   无效。  
   
  就是想实现一边操作mis(输入资料、切换其他窗体等),一边看VCD的效果。  
  问题点数:20、回复次数:9Top

1 楼w3k(网络3K)回复于 2005-07-04 11:02:53 得分 1

Private   Sub   Command1_Click()  
  Form2.Show   1  
  End   Sub  
  FORM2的为可用,但关闭form2时,FORM1获得焦点Top

2 楼LBwu(大鸟)回复于 2005-07-04 11:03:47 得分 2

BOOL   SetWindowPos(  
      HWND   hWnd,                           //   handle   to   window  
      HWND   hWndInsertAfter,     //   placement-order   handle  
      int   X,                                   //   horizontal   position  
      int   Y,                                   //   vertical   position  
      int   cx,                                 //   width  
      int   cy,                                 //   height  
      UINT   uFlags                         //   window-positioning   flags  
  );  
     
  Parameters  
  hWnd    
  Handle   to   the   window.    
  hWndInsertAfter    
  Handle   to   the   window   to   precede   the   positioned   window   in   the   Z   order.   This   parameter   must   be   a   window   handle   or   one   of   the   following   values:   Value   Meaning    
  HWND_BOTTOM   Places   the   window   at   the   bottom   of   the   Z   order.   If   the   hWnd   parameter   identifies   a   topmost   window,   the   window   loses   its   topmost   status   and   is   placed   at   the   bottom   of   all   other   windows.    
  HWND_NOTOPMOST   Places   the   window   above   all   non-topmost   windows   (that   is,   behind   all   topmost   windows).   This   flag   has   no   effect   if   the   window   is   already   a   non-topmost   window.    
  HWND_TOP   Places   the   window   at   the   top   of   the   Z   order.    
  HWND_TOPMOST   Places   the   window   above   all   non-topmost   windows.   The   window   maintains   its   topmost   position   even   when   it   is   deactivated.    
   
   
  For   more   information   about   how   this   parameter   is   used,   see   the   following   Remarks   section.    
   
  X    
  Specifies   the   new   position   of   the   left   side   of   the   window,   in   client   coordinates.    
  Y    
  Specifies   the   new   position   of   the   top   of   the   window,   in   client   coordinates.    
  cx    
  Specifies   the   new   width   of   the   window,   in   pixels.    
  cy    
  Specifies   the   new   height   of   the   window,   in   pixels.    
  uFlags    
  Specifies   the   window   sizing   and   positioning   flags.   This   parameter   can   be   a   combination   of   the   following   values:   Value   Meaning    
  SWP_ASYNCWINDOWPOS   If   the   calling   thread   does   not   own   the   window,   the   system   posts   the   request   to   the   thread   that   owns   the   window.   This   prevents   the   calling   thread   from   blocking   its   execution   while   other   threads   process   the   request.      
  SWP_DEFERERASE   Prevents   generation   of   the   WM_SYNCPAINT   message.      
  SWP_DRAWFRAME   Draws   a   frame   (defined   in   the   window's   class   description)   around   the   window.    
  SWP_FRAMECHANGED   Sends   a   WM_NCCALCSIZE   message   to   the   window,   even   if   the   window's   size   is   not   being   changed.   If   this   flag   is   not   specified,   WM_NCCALCSIZE   is   sent   only   when   the   window's   size   is   being   changed.    
  SWP_HIDEWINDOW   Hides   the   window.    
  SWP_NOACTIVATE   Does   not   activate   the   window.   If   this   flag   is   not   set,   the   window   is   activated   and   moved   to   the   top   of   either   the   topmost   or   non-topmost   group   (depending   on   the   setting   of   the   hWndInsertAfter   parameter).    
  SWP_NOCOPYBITS   Discards   the   entire   contents   of   the   client   area.   If   this   flag   is   not   specified,   the   valid   contents   of   the   client   area   are   saved   and   copied   back   into   the   client   area   after   the   window   is   sized   or   repositioned.    
  SWP_NOMOVE   Retains   the   current   position   (ignores   the   X   and   Y   parameters).    
  SWP_NOOWNERZORDER   Does   not   change   the   owner   window's   position   in   the   Z   order.    
  SWP_NOREDRAW   Does   not   redraw   changes.   If   this   flag   is   set,   no   repainting   of   any   kind   occurs.   This   applies   to   the   client   area,   the   nonclient   area   (including   the   title   bar   and   scroll   bars),   and   any   part   of   the   parent   window   uncovered   as   a   result   of   the   window   being   moved.   When   this   flag   is   set,   the   application   must   explicitly   invalidate   or   redraw   any   parts   of   the   window   and   parent   window   that   need   redrawing.    
  SWP_NOREPOSITION   Same   as   the   SWP_NOOWNERZORDER   flag.    
  SWP_NOSENDCHANGING   Prevents   the   window   from   receiving   the   WM_WINDOWPOSCHANGING   message.    
  SWP_NOSIZE   Retains   the   current   size   (ignores   the   cx   and   cy   parameters).    
  SWP_NOZORDER   Retains   the   current   Z   order   (ignores   the   hWndInsertAfter   parameter).    
  SWP_SHOWWINDOW   Displays   the   window.    
   
   
  Return   Values  
  If   the   function   succeeds,   the   return   value   is   nonzero.  
   
  If   the   function   fails,   the   return   value   is   zero.   To   get   extended   error   information,   callGetLastError.    
   
  调用这个api就可以了~~~  
  Top

3 楼jxgzay(jxgzay)回复于 2005-07-04 11:09:07 得分 0

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  
  Const   HWND_TOPMOST   =   -1  
  Const   SWP_SHOWWINDOW   =   &H40  
  Private   Sub   Form_load()  
  Dim   retValue   As   Long  
  '将窗体设置为处于所有窗口的顶层,注意在   VB   中运行时,可能不行,但编译成EXE后就可以了  
  retValue   =   SetWindowPos(Me.hwnd,   HWND_TOPMOST,   Me.CurrentX,   Me.CurrentY,   300,   300,   SWP_SHOWWINDOW)  
  End   Sub  
   
   
   
   
   
  Top

4 楼wangtopcool(逆水行舟,不进则退)回复于 2005-07-04 11:16:14 得分 5

用api函数  
  Public   Declare   Function   SetParent   Lib   "user32"   (ByVal   hWndChild   As   Long,   ByVal   hWndNewParent   As   Long)   As   Long  
  Public   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  
  Public   Const   HWND_TOPMOST   =   -1  
   
  在form1上放两个按钮  
  Private   Sub   Command1_Click()  
  SetParent   Form2.hWnd,   Form1.hWnd  
  Form2.Visible   =   True  
  End   Sub  
   
  Private   Sub   Command2_Click()  
  Unload   Form2  
  End   Sub  
   
  Private   Sub   Form_Load()  
          SetWindowPos   Me.hWnd,   HWND_TOPMOST,   0,   0,   0,   0,   0  
  End   SubTop

5 楼bee6803(欢笑人生)回复于 2005-07-04 11:16:31 得分 5

Public   Declare   Function   SetWindowPos   Lib   "user32"   (ByVal   hWnd   As   Long,   ByVal   hWndInsertAfter   As   Long,   ByVal   x   As   Long,   y,   ByVal   cx   As   Long,   ByVal   cy   As   Long,   ByVal   wFlags   As   Long)   As   Long  
  '   Various   constants   used   by   the   above   functions  
  Public   Const   HWND_TOPMOST   =   -1  
  Public   Const   HWND_NOTOPMOST   =   -2  
  Public   Const   TOPMOST_FLAGS   =   SWP_NOMOVE   Or   SWP_NOSIZE  
   
  Public   Sub   AlwaysOnTop(TheForm   As   Form,   Toggle   As   Boolean)  
  '   TheForm:     窗体是否置顶  
  '   Toggle:       Boolean   (True/False)   -   True   永远置顶   ,   False   正常  
           
          If   Toggle   =   True   Then  
                  SetWindowPos   TheForm.hWnd,   HWND_TOPMOST,   0,   0,   0,   0,   TOPMOST_FLAGS  
          Else  
                  SetWindowPos   TheForm.hWnd,   HWND_NOTOPMOST,   0,   0,   0,   0,   TOPMOST_FLAGS  
          End   If  
  End   Sub  
  '窗体调用  
   
  Private   Sub   Form_Load()  
                  AlwaysOnTop   Me,   True  
  End   SubTop

6 楼bee6803(欢笑人生)回复于 2005-07-04 11:18:44 得分 5

'模块中定义API  
  Public   Declare   Function   SetWindowPos   Lib   "user32"   (ByVal   hWnd   As   Long,   ByVal   hWndInsertAfter   As   Long,   ByVal   x   As   Long,   y,   ByVal   cx   As   Long,   ByVal   cy   As   Long,   ByVal   wFlags   As   Long)   As   Long  
  '   Various   constants   used   by   the   above   functions  
  Public   Const   HWND_TOPMOST   =   -1  
  Public   Const   HWND_NOTOPMOST   =   -2  
  Public   Const   TOPMOST_FLAGS   =   SWP_NOMOVE   Or   SWP_NOSIZE  
  ''模块中定义  
  Public   Sub   AlwaysOnTop(TheForm   As   Form,   Toggle   As   Boolean)  
  '   TheForm:     窗体名称  
  '   Toggle:       Boolean   (True/False)   -   True   永远置顶   ,   False   正常  
           
          If   Toggle   =   True   Then  
                  SetWindowPos   TheForm.hWnd,   HWND_TOPMOST,   0,   0,   0,   0,   TOPMOST_FLAGS  
          Else  
                  SetWindowPos   TheForm.hWnd,   HWND_NOTOPMOST,   0,   0,   0,   0,   TOPMOST_FLAGS  
          End   If  
  End   Sub  
  '窗体调用  
   
  Private   Sub   Form_Load()  
                  AlwaysOnTop   Me,   True  
  End   Sub  
  Top

7 楼wosirius(神经第六)回复于 2005-07-04 13:16:00 得分 0

mTop

8 楼penguinMII(企鹅)回复于 2005-07-04 14:25:12 得分 1

用AIP函数就可以了。  
  楼上都说完了。。。。Top

9 楼fujlt(菜鸟)回复于 2005-07-04 15:32:56 得分 1

同上   SetWindowPosTop

相关问题

  • 如何让窗体总在最上层
  • 如何让窗体居于最上层??
  • 怎么使有子窗体的窗体永远在上面?急
  • 如何让窗体永远在其他窗体的前面??
  • 如何将A窗体永远在B窗体的上面?
  • MDI主窗体里的某个子窗体被选中,主窗体如何截获这个事件
  • 怎样在主窗体中使它的某个子窗体获得焦点?
  • MDI窗体中,如何判断某个具体的子窗体是否打开?
  • 如何在A窗体中处理子窗体某个控件的消息/事件?
  • 如何判断MDI窗体的某个子窗体是否被create?

关键词

  • 窗体
  • topmost
  • hwnd
  • places
  • positioned
  • bottom
  • handle
  • form
  • 获得
  • 焦点时

得分解答快速导航

  • 帖主:jxgzay
  • w3k
  • LBwu
  • wangtopcool
  • bee6803
  • bee6803
  • penguinMII
  • fujlt

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo