MDI maximized child bug
-
Hi all, It is very common to create a mdi child in a initially maximized state in some cases. I set SW_MAXIMIZE style in the MDICREATESTRUCT structure then send a message to mdi client window. After that, I saw twin sizing boxes on the top-right corner of my frame window (a pair of [Min][Max][Close] tri-buttons). If I restore the child window, the child got one and there was still one remaining on the corner. I was using Win32 SDK, not MFC. The code I used to create the child is like this:
HWND child_createWnd(HWND hwndClient, int x, int y, int w, int h, TCHAR szCaption[], TCHAR szFilename[])
{
HWND hwndChild ;
MDICREATESTRUCT mdicreate ;if(!childClass) childClass = zw\_child\_registerClass(); mdicreate.szClass = szChildClass ; mdicreate.szTitle = szCaption ; mdicreate.hOwner = GetModuleHandle(0) ; mdicreate.x = CW\_USEDEFAULT ; mdicreate.y = CW\_USEDEFAULT ; mdicreate.cx = CW\_USEDEFAULT ; mdicreate.cy = CW\_USEDEFAULT ; mdicreate.style = WS\_VSCROLL | WS\_HSCROLL | WS\_MAXIMIZE; `//MAXIMIZE window style` mdicreate.lParam = (LPARAM)szFilename ; hwndChild = (HWND) SendMessage (hwndClient, WM\_MDICREATE, 0, (LPARAM) (LPMDICREATESTRUCT) &mdicreate) ; return hwndChild;
}
I followed Petzold's sample code (cha18, Programming Windows 5ed.)to do this. I wander if I missed something. So I tried it on the sample code directly and add the flag to the style, but still happened. Did anyone ever get this problem? I'm very thankful if anyone can help me.
-
Hi all, It is very common to create a mdi child in a initially maximized state in some cases. I set SW_MAXIMIZE style in the MDICREATESTRUCT structure then send a message to mdi client window. After that, I saw twin sizing boxes on the top-right corner of my frame window (a pair of [Min][Max][Close] tri-buttons). If I restore the child window, the child got one and there was still one remaining on the corner. I was using Win32 SDK, not MFC. The code I used to create the child is like this:
HWND child_createWnd(HWND hwndClient, int x, int y, int w, int h, TCHAR szCaption[], TCHAR szFilename[])
{
HWND hwndChild ;
MDICREATESTRUCT mdicreate ;if(!childClass) childClass = zw\_child\_registerClass(); mdicreate.szClass = szChildClass ; mdicreate.szTitle = szCaption ; mdicreate.hOwner = GetModuleHandle(0) ; mdicreate.x = CW\_USEDEFAULT ; mdicreate.y = CW\_USEDEFAULT ; mdicreate.cx = CW\_USEDEFAULT ; mdicreate.cy = CW\_USEDEFAULT ; mdicreate.style = WS\_VSCROLL | WS\_HSCROLL | WS\_MAXIMIZE; `//MAXIMIZE window style` mdicreate.lParam = (LPARAM)szFilename ; hwndChild = (HWND) SendMessage (hwndClient, WM\_MDICREATE, 0, (LPARAM) (LPMDICREATESTRUCT) &mdicreate) ; return hwndChild;
}
I followed Petzold's sample code (cha18, Programming Windows 5ed.)to do this. I wander if I missed something. So I tried it on the sample code directly and add the flag to the style, but still happened. Did anyone ever get this problem? I'm very thankful if anyone can help me.
I read "Daniel Bowen, Creating a new MDI child: maximization and focus issues" and got some idea. I should handle redraw and focus issues. Set the client window as MDIS_ALLCHILDSTYLES style and change the function to :
HWND child_createWnd(HWND hwndClient, int x, int y, int w, int h, TCHAR szCaption[], TCHAR szFilename[])
{
HWND hwndChild ;
MDICREATESTRUCT mdicreate ;
int fMax = 0;if(!childClass) childClass = zw\_child\_registerClass(); mdicreate.szClass = szChildClass ; mdicreate.szTitle = szCaption ; mdicreate.hOwner = GetModuleHandle(0) ; mdicreate.x = CW\_USEDEFAULT ; mdicreate.y = CW\_USEDEFAULT ; mdicreate.cx = CW\_USEDEFAULT ; mdicreate.cy = CW\_USEDEFAULT ; mdicreate.style = `WS_OVERLAPPEDWINDOW | WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_HSCROLL;` mdicreate.lParam = (LPARAM)szFilename ; `SendMessage(hwndClient, WM_SETREDRAW, FALSE, 0); /* Disable redraw */` hwndChild = (HWND) SendMessage (hwndClient, WM\_MDICREATE, 0, (LPARAM) (LPMDICREATESTRUCT) &mdicreate) ; `/* Should maximize? */ SendMessage(hwndClient, WM_MDIGETACTIVE, 0, &fMax); fMax? ShowWindow(hwndChild, SW_MAXIMIZE) : ShowWindow(hwndChild, SW_NORMAL); /* Handle focus here */ SetFocus(hwndChild); /* Enable and redraw */ SendMessage(hwndClient, WM_SETREDRAW, TRUE, 0); RedrawWindow(hwndClient, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);` return hwndChild;
Right now everything is correct except very slow. If you have better idea, please let me know, thanks.