开发者

Blocking action of CDialog's maximize/minimize button

I am using mfc CDialog. I need to show the close and minimize/maximize butto开发者_运维问答n, but they should not close or maximize the dialog. I have overriden OnClose method and kept the dialog open even if close button is clicked. But I am unable to block maximize and minimize of the dialog as there doesn't seem to be a OnMaximize method. Is there an alternative way?


You need to handle the WM_SYSCOMMAND message, watching for wParam == SC_MAXIMIZE.

If you catch the SC_MINIMIZE, you can do what you want and not pass it on to Windows.

msdn

Found this snippet here.

const int WM_SYSCOMMAND= 0x0112;
const int SC_MAXIMIZE= 0xF030;
protected override void WndProc(ref Message m)
{
    if(m.Msg==WM_SYSCOMMAND)
    {
        if((int)m.WParam==SC_MAXIMIZE)
        {
            MessageBox.Show("Maximized!!");
            return; // swallow the message
        }
    }
    base.WndProc (ref m);
}


You can not show at all the minimise/maximise icons i your dialog. You can do that by going to Dialog properties (right vlick on your Dialog Contorol --> Properties), Select Styles pain and unselect 'Minimise Box', 'Maximise Box'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜