Jump to content
  • Advertisement
Sign in to follow this  
alex9025

Guys what am i doing wrong? (C++)

This topic is 3991 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 wrote this code, according to a book i got, it compiles alright with no problem but when i double click it to run it loads up since i see it in the task manager's processes but the acctual window does not show up
#include <windows.h>
LRESULT CALLBACK WndProc (HWND hWindow, UINT iMessage,
                           WPARAM wParam, LPARAM lPARAM);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInst,
                       LPSTR lpCmdLine, int nShowCMD)
{
 WNDCLASS kWndClass;

kWndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
kWndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
kWndClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);

kWndClass.hInstance = hInstance;
kWndClass.lpfnWndProc = WndProc;
kWndClass.lpszClassName = "Hello World";

kWndClass.lpszMenuName = NULL;

kWndClass.cbClsExtra = NULL;
kWndClass.cbWndExtra = NULL;
kWndClass.style = NULL;

if (!RegisterClass (&kWndClass))
{
 return -1;
}

HWND hWindow;
hWindow = CreateWindow ("Hello World!", "A Test Window",
                         WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT,
                         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                         NULL, NULL, hInstance, NULL);
MSG kMessage;
while (GetMessage (&kMessage, hWindow, 0, 0))
{
 TranslateMessage (&kMessage);
 DispatchMessage (&kMessage);
}

return 0;
}
LRESULT CALLBACK WndProc (HWND hWindow, UINT iMessage,
                           WPARAM wParam, LPARAM lParam)
{
switch (iMessage)
{
 case WM_CLOSE:
      PostQuitMessage (0);
      break;

      default:
      return DefWindowProc (hWindow, iMessage, wParam, lParam);
      }
      return 0;
 }

[Edited by - alex9025 on August 12, 2007 4:02:12 PM]

Share this post


Link to post
Share on other sites
Advertisement
The name of your window class is "Hello World", but the parameter you pass to CreateWindow() is "Hello World!" (with a !). To avoid this kind of mistake, just pass kWndClass.lpszClassName.

Share this post


Link to post
Share on other sites
Try this:


hWindow = CreateWindow ( kWndClass.lpszClassName, "A Test Window",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL );

If you also needed to process the WM_PAINT message to properly display a window then you'll need to add a call to UpdateWindow( hWindow ); after ShowWindow.

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!