NO

Author Topic: MDI status bar wizard code incorrect  (Read 2322 times)

jmac

  • Guest
MDI status bar wizard code incorrect
« on: June 13, 2010, 05:52:10 AM »
If you create a sample MDI application using the MDI wizard the status bar does not get resized on changing the size of the main window. There is code in the WM_SIZE message but it appears that the initial setting of the global HWND for the status bar is incorrect. If you add a new line at the end of the handler for WM_CREATE like g_hWndStatusBar = GetDlgItem(hwnd, ID_STATUSBAR); it will work correctly. I am not sure why the initial setting of this hwnd in WM_CREATE is not working, any ideas?

JohnF

  • Guest
Re: MDI status bar wizard code incorrect
« Reply #1 on: June 13, 2010, 08:12:23 AM »
I've looked at it - it appears that if you use max speed compile it has a problem, if you select no speed optimization it works.

I will get back later.

EDIT:

I think there was a buffer overrun with ptArray

Code: [Select]
void SizeStatusPanels(HWND hWndParent, HWND hWndStatusbar, int nrOfParts)
{

int   ptArray[nrOfParts];

Change to

Code: [Select]
void SizeStatusPanels(HWND hWndParent, HWND hWndStatusbar, int nrOfParts)
{

int   ptArray[nrOfParts+1];

I have updated the wizard on my web site.

Thanks for the bug report.

John
« Last Edit: June 13, 2010, 09:53:27 AM by JohnF »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2097
Re: MDI status bar wizard code incorrect
« Reply #2 on: June 13, 2010, 02:28:36 PM »
Few ideas after testing that in Linux/Wine:

In HWND CreateToolBarWnd(HWND hWndParent, HINSTANCE hInst)
  WS_EX_CLIENTEDGE -> 0
  remove | WS_BORDER
Code: [Select]
// Create the toolbar.
hWndTB = CreateWindowEx(0,
   TOOLBARCLASSNAME,
(LPTSTR) NULL,
    WS_CHILD  | CCS_TOP | TBSTYLE_TOOLTIPS,
0, 0, 0, 0,
hWndParent,
(HMENU) ID_TOOLBAR,
hInst,
NULL);
Just another way to do that:
Code: [Select]
LRESULT FrameWndProc_OnSize(HWND hwnd, int flag, int x, int y)
{

// ReSize the various child windows
SendMessage(g_hWndStatusBar, WM_SIZE, flag, x);
SendMessage(g_hWndToolBar, WM_SIZE, flag, x);
SizeStatusPanels(hwnd, g_hWndStatusBar, numParts);

// Position the MDI client window between the tool and status bars
if (flag != SIZE_MINIMIZED)
{
RECT rcStat, rcClient;
GetClientRect(hwnd, &rcClient);
GetClientRect(g_hWndToolBar, &rcStat);
rcClient.top = rcStat.bottom + 3;
rcClient.bottom = rcClient.bottom - rcStat.bottom - 3;
GetClientRect(g_hWndStatusBar, &rcStat);
rcClient.bottom = rcClient.bottom - rcStat.bottom;
MoveWindow(g_hWndClient, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom, TRUE);
}
return 0;
}
« Last Edit: June 13, 2010, 02:32:23 PM by timovjl »
May the source be with you

JohnF

  • Guest
Re: MDI status bar wizard code incorrect
« Reply #3 on: June 13, 2010, 09:57:54 PM »
Thanks, I will make that change to the call to MoveWindow.

John