Jump to content
  • Advertisement
Sign in to follow this  
zee_ola05

[DX] Win32 Help

This topic is 2657 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



#include <windows.h>


// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);

/*
hInstance - identifier of the "instance"/application
prevInstance - obsolete, not important
lpCmdLine - string pointer, like argv in C (getting cmdline parameters)
showCmd - not important in games
*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc; //fill up this struct and then Register

ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc; //WindowProc() is a function that handles messages (e.g. mouse and keyboard inputs)
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = "Window Class 1";

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL,
"Window Class 1 - CreateWindowEx",
"Window Name 1",
WS_OVERLAPPEDWINDOW,
300,
300,
500,
400,
NULL,
NULL,
hInstance,
NULL);

ShowWindow(hWnd, nCmdShow);

MSG msg;

while(true)
{
//Check if there is a message in the message queue. If none, continue with the game code, else process
while(PeekMessage(&msg, hWnd, 0,0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

if(msg.message == WM_QUIT)
break;

/*
Run Game Code Here
*/
}

return msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
//close application
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}

//Hnadle any statement the switch-case didn't
return DefWindowProc(hWnd, message, wParam, lParam);
}



I have this program written using MS Visual C++ 2010. When I debug it (F5), there is no error and it runs. BUT it does not show anything. I'm expecting a blank window. Can anyone help me identifying what is wrong with this code? Thanks!

I'm following a DirectX tutorial, BTW.

Share this post


Link to post
Share on other sites
Advertisement
You should check function return values for errors. Most Windows functions will indicate success or failure, and if they fail you can call GetLastError() to find out what the exact error is. In particular your CreateWindowEx() call is failing.

Share this post


Link to post
Share on other sites
Thank you. Can you tell me what in particular is wrong with CreateWindowEx()?

And if I use the GetLastError(), How will I display the error?

Share this post


Link to post
Share on other sites
Take a look at the CreateWindowEx() call. Which parameter is the window class parameter? Now compare that value to the name of the window class you registered.

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!