Jump to content
  • Advertisement
Sign in to follow this  
R1cochet

Help with win32 code

This topic is 2611 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have started working on learning the directx11 using the new directx 11 book and i am having problems with creating the blank window, when i compile the code the window shows up but it's not responding. I cant figure out whats wrong with the code, the source code from the book compiles correctly though showing the blank window. Here is what i have written. Can anyone tell what I'm doing wrong here.

# include <Windows.h>

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT paintstruct;
HDC hDC;
switch(message)
{
case WM_PAINT:
hDC = BeginPaint(hwnd,&paintstruct);
EndPaint(hwnd,&paintstruct);
break;

case WM_DESTROY:
PostQuitMessage(0);
break;

default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}

int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow)
{
UNREFERENCED_PARAMETER(prevInstance);
UNREFERENCED_PARAMETER(cmdShow);
WNDCLASSEX wndClass = {0};
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = WndProc;
wndClass.hInstance = hInstance;
wndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = "M";

if(!RegisterClassEx(&wndClass))
{
return -1;
}
RECT rc = {0,0,640,480};
AdjustWindowRect (&rc,WS_OVERLAPPEDWINDOW,FALSE);

HWND hwnd = CreateWindow("M","Blank Win 32 Window",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,rc.right - rc.left,rc.bottom - rc.top ,NULL,NULL,hInstance,NULL);
if(!hwnd)
{
return -1;
}

ShowWindow(hwnd,cmdShow);

// Demo Initialize
MSG msg = {0};

while(msg.message != WM_QUIT);
{
if (PeekMessage (&msg,0,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// Update
// Draw
}
}
// Demo Shutdown

return static_cast<int>(msg.wParam);
}

Share this post


Link to post
Share on other sites
Advertisement
Your problem is caused by the semi-colon at the end of this line (it is causing an infinite loop)

while(msg.message != WM_QUIT);

If you remove the semi-colon, all is ok ;)

Share this post


Link to post
Share on other sites
After even going through the code many times i couldn't figure out what was going wrong. looking at the source given and comparing it with what i had written, not realizing i made the simplest of mistakes. I guess i just really needed a break :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!