Sign in to follow this  
R1cochet

Help with win32 code

Recommended Posts

R1cochet    236
I have started working on learning the directx11 using the new directx 11 [url="http://www.amazon.com/Beginning-DirectX-11-Game-Programming/dp/1435458958/ref=sr_1_1?s=books&ie=UTF8&qid=1306741141&sr=1-1"]book[/url] 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
R1cochet    236
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
jyk    2094
Small tip: these sorts of errors can generally be resolved quickly by using the debugger.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this