Handmade Hero»Forums»Code
Steve Martin
3 posts
Episode 2, Can't resize/drag window
I've started following the series and on episode 2 at 50:20, my window is not resizable or dragable and is already white. There are also no WM_CLOSE messages when you click the close button.

From what I can tell I've written it out exactly the same(it's not the downloaded source)and checked it over and over and am completely baffled as to why it wouldn't work the same.

I'm using Windows 7 64
Emacs 23.4.1
Visual Studio 2015(14.0)

Just so you can see it and in case I'm blind, here is my code:

ps. I'm a complete beginner :)



#include <windows.h>

LRESULT CALLBACK
MainWindowCallback(HWND Window,
UINT Message,
WPARAM WParam,
LPARAM LParam)

{
LRESULT Result = 0;

switch(Message)
{
case WM_SIZE:
{
OutputDebugStringA("WM_SIZE\n");
} break;

case WM_DESTROY:
{
OutputDebugStringA("WM_DESTROY\n");
} break;

case WM_CLOSE:
{
OutputDebugStringA("WM_CLOSE\n");
} break;

case WM_ACTIVATEAPP:
{
OutputDebugStringA("WM_ACTIVATEAPP\n");
} break;

default:
{
//OutputDebugStringA("default\n");
Result = DefWindowProc(Window, Message, WParam, LParam);
} break;
}

return(Result);
}


int CALLBACK
WinMain(HINSTANCE Instance,
HINSTANCE PrevInstance,
LPSTR CommadLine,
int ShowCode)
{
WNDCLASS WindowClass = {};

WindowClass.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
WindowClass.lpfnWndProc = MainWindowCallback;
//WindowClass.cbClsExtra;
//WindowClass.cbWndExtra;
WindowClass.hInstance = Instance;
//WindowClass.hIcon;
//WindowClass.hCursor;
//WindowClass.hbrBackground;
//WindowClass.lpszMenuName;
WindowClass.lpszClassName = "HandmadeHeroWindowClass";

if(RegisterClass(&WindowClass))
{
HWND WindowHandle =
CreateWindowEx(
0,
WindowClass.lpszClassName,
"Handmade Hero",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
Instance,
0);
if(WindowHandle)
{

for(;;)
{
MSG Message;
BOOL MessageResult = GetMessage(&Message, 0, 0, 0);
if(MessageResult > 0)
{
TranslateMessage(&Message);
}
else
{
break;
}
}
}
else
{

}
}
else
{
}

return(0);
}
3 posts
Episode 2, Can't resize/drag window
The WM_SIZE, WM_CLOSE messages need to be dispatched to the window procedure.
To do this call DispatchMessageA(&Message) after/before TranslateMessage(&Message).
Steve Martin
3 posts
Episode 2, Can't resize/drag window
But this code is exactly the same as Casey's and his worked while mine did not. Did the language change since the video was uploaded or something?
3 posts
Episode 2, Can't resize/drag window
https://youtu.be/4ROiWonnWGk?t=49m30s

look real close at 49:30.
Steve Martin
3 posts
Episode 2, Can't resize/drag window
Ha! :woohoo:

Thanks for that, I must have looked over that a dozen times and missed it every time.

Out of interest, do you know why I would still get the WM_ACTIVATEAPP message without having the DispatchMessage line?
3 posts
Episode 2, Can't resize/drag window
WM_ACTIVATEAPP goes directly to the WindowProc function and not into the message queue for dispatch.