WM_SYSCOMMAND

从窗口系统菜单上发送该消息,实现窗口的最大化,最小化,移动,还原,移动等操作
假设在CWnd派生类中
如,关闭窗口SC_CLOSE
SendMessage(WM_SYSCOMMAND, SC_CLOSE, NULL);
最小化窗口SC_MINIMIZE
SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, NULL);
窗口移动状态SC_MOVE

 


SendMessage(WM_SYSCOMMAND, SC_MOVE, NULL);

改变窗口状态还有其他的方法
如,更改窗口布局
WINDOWPLACEMENT lwndpl;
WINDOWPLACEMENT * lpwndpl;
lpwndpl=&lwndpl;
GetWindowPlacement(lpwndpl);
lpwndpl->showCmd=SW_SHOW;


SetWindowPlacement(lpwndpl);

客户区移动
在OnLButtonDown中添加如下代码:
PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y)); 

 

FromHandle(pMsg->hwnd)->SendMessage(WM_SYSCOMMAND,SC_MOVE+1,0);

 

 

WM_SYSCOMMAND 消息使用技巧

void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)

{

    TRACE("        nID = %x", nID);

    if ( nID == SC_RESTORE && ::IsZoomed(m_hWnd) )    // 最大化时屏蔽"还原"

        return;

    if ( nID == 0x0f032 || nID == SC_MAXIMIZE)        // 屏蔽双击标题栏

    {

        RECT rtScreen ={0};

        if ( !SystemParametersInfo(SPI_GETWORKAREA, 0, &rtScreen, 0)    )

            return;

        else

            SetWindowPos(NULL, rtScreen.left, rtScreen.top,

            rtScreen.right, rtScreen.bottom, 0);

        return;

    }

    if ( nID == 0x0f012 || nID == SC_MOVE)    // 屏蔽拖动标题栏  CFileException

        return;

    if ( nID == 0x0f032 )    // 屏蔽双击标题栏

        return;

    if ( nID == 0x0f006 || nID == 0x0f001 & nID == 0x0f003 & nID == 0x0f008)    // 屏蔽改变大小

        return;

    if ( nID == ID_SYSTEM_MENU_DEFINE)        // 系统关于菜单

        PostMessage(WM_COMMAND, ID_APP_ABOUT, 0);

    CFrameWnd::OnSysCommand(nID, lParam);

 

你可能感兴趣的:(command,null,System,menu)