用代码设置窗体FormStyle为TopMost

来源:互联网 发布:自由走廊 知乎 编辑:程序博客网 时间:2024/06/04 19:30

函数原型:
BOOL SetWindowPos(

    HWND hWnd, // handle of 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
   );

TOPMOST:
SetWindowPos(Form2->Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
//SWP_NOMOVE|SWP_NOSIZE表示不重设大小和位置,也就是忽略X,Y,cx,cy四个参数

取消TOPMOST:
SetWindowPos(Form2->Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);