Reputation: 489
I have a window HWND assignWnd
that is a child window of the main window. This window doesn't seem to process the WM_CREATE message. For example, here is the WM_CREATE message within my window procedure.
case WM_CREATE:
{
hdc = GetDC(assignWnd);
GetTextMetrics(assignWnd,&tm);
cyChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC(assignWnd,hdc);
return 0;
}
The variable cyChar
is an int
and is declared within the window procedure. It is used later in the WM_PAINT message. Whenever I compile the program, I get a run-time error stating that cyChar
is being used before it initialized. If I place the above code within the WM_PAINT message however, the program works as expected.
The obvious problem is that I don't want these calls to be made every time the window is painted. I would like these commands (and others later on) to be processed during the WM_CREATE message.
Any explanation as to why the WM_CREATE message is not being processed in this child window be greatly appreciated.
Upvotes: 1
Views: 541
Reputation: 37122
Presumably cyChar
is local to the window procedure. It's not a question of WM_CREATE
not being processed, it's that the cyChar
you assign in WM_CREATE
is not the same cyChar
that you use in WM_PAINT
. You need to make your variable global or static so that it survives from one call to the window procedure to another.
Upvotes: 1