Thread: Just starting Windows Programming, School me!

  1. #16
    Absent Minded Programmer
    Join Date
    May 2005
    Okay, so here is my first attempt at a main window.

    BOOL CreateMainWindow(char* title, int width, int height)
    	DWORD    dwExStyle;
    	DWORD    dwStyle;
    	RECT     WindowRect;
    	WindowRect.left =(long)0;
    	hInstance = GetModuleHandle(NULL);
    	dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
    	dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style
    	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);		// Adjust Window To True Requested Size
    	if (!(hWnd=CreateWindowEx(	dwExStyle,							// Extended Style For The Window
    								WC_DIALOG,					// Class Name
    								title,								// Window Title
    								dwStyle |							// Defined Window Style
    								WS_CLIPSIBLINGS |					// Required Window Style
    								WS_CLIPCHILDREN,					// Required Window Style
    								0, 0,								// Window Position
    								WindowRect.right-WindowRect.left,	// Calculate Window Width
  ,	// Calculate Window Height
    								NULL,								// No Parent Window
    								NULL,								// No Menu
    								hInstance,							// Instance
    								NULL)))								// Dont Pass Anything To WM_CREATE
    		MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
    		return FALSE;								// Return FALSE
    	ShowWindow(hWnd,SW_SHOW);						// Show The Window
    	SetForegroundWindow(hWnd);						// Slightly Higher Priority
    	SetFocus(hWnd);									// Sets Keyboard Focus To The Window
    	return TRUE;
    The only issue with this, is that the X button at the top right doesn't work! Why?

    Also, Can someone explain more to me about the device context? Do I need one for this main window? Or do I only need a device context when I'm drawing things, like in our OpenGL frame I want to create.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #17
    train spotter
    Join Date
    Aug 2001
    near a computer
    WM_CLOSE should call DestroyWindow() [WM_DESTROY] which will clean up and call PostQuitMessage().

    As you have no processing in these handlers I would pass them on to the DefWindowProc(). ie remove the WM_CLOSE and I think it will work.

    As you have not followed correct switch/case/break syntax there are probably other errors (where DefWindowProc() is/ is not called after the message is/is not processed).

    DCs and OpenGL......

    Seen these?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #18
    Absent Minded Programmer
    Join Date
    May 2005
    Definately, I used those to get a milkshape model loader and such running. They don't really explain the win32 part too much, but I'll look again at it.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 01-01-2007, 07:36 AM
  2. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  3. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  4. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM