设置或取消窗口顶层属性

来源:互联网 发布:仿阿里云首页效果 编辑:程序博客网 时间:2024/05/02 02:46
设置窗口顶层:
//SetWindowLong(hWnd,GWL_EXSTYLE,GetWindowLong(hWnd,GWL_EXSTYLE) | WS_EX_TOPMOST);
SetWindowPos(hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
If you have changed certain window data usingSetWindowLong, you must callSetWindowPos to have the changes take effect.
取消窗口顶层:
SetWindowPos(hWnd,HWND_NOTOPMOST ,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);

The SetWindowPos function changes the size, position, and Z order of a child, pop-up, or top-level window. Child, pop-up, and top-level windows are ordered according to their appearance on the screen. The topmost window receives the highest rank and is the first window in the Z order.

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);
 
也就是改变SetWindowLong不起作用,必须用SetWindowPos
判断是否具有WS_EX_TOPMOST窗口属性
    if( GetWindowLong(this->Handle, GWL_EXSTYLE) & WS_EX_TOPMOST )            Caption= "WS_EX_TOPMOST";  
   else       
  Caption="no";