What is my window?

This is a discussion on What is my window? within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to make a template of a window using functions, making it more efficient. I still have these two ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    What is my window?

    I'm trying to make a template of a window using functions, making it more efficient. I still have these two errors in which I cannot figure out what is wrong.
    Code:
    #include "window.h"
    
    RECT windowRect = {100, 100, 400, 400};
    LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
    void MakeWindow(HINSTANCE hInstance, char * className, char * title, int iCmdShow);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
    	MakeWindow(hInstance,"Windows Class","Title",iCmdShow);
    }
    
    void MakeWindow(HINSTANCE hInstance, char * className, char * title, int iCmdShow)
    {
    	HWND hWnd;
    	MSG msg;
    	WNDCLASSEX wndClass;
    
    	wndClass.cbSize = sizeof(wndClass);
    	wndClass.style = CS_HREDRAW | CS_VREDRAW;
    	wndClass.lpfnWndProc = WndProc;
    	wndClass.cbClsExtra = 0;
    	wndClass.cbWndExtra = 0;
    	wndClass.hInstance = hInstance;
    	wndClass.hIcon = LoadIcon (NULL, IDI_WINLOGO);
    	wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
    	wndClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
    	wndClass.lpszMenuName = NULL;
    	wndClass.lpszClassName = className;
    
    	RegisterClassEx (&wndClass);
    	hWnd = CreateWindow(title,wndClass,WS_OVERLAPPEDWINDOW,windowRect.left,windowRect.top,windowRect.right,windowRect.bottom,NULL,NULL,hInstance,NULL);
    	ShowWindow(hWnd,iCmdShow);
    	UpdateWindow(hWnd);
    	while(GetMessage(&msg,NULL,0,0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	UnregisterClassEx(wndClass,hInstance);
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch(iMsg)
    	{
    	case WM_CLOSE:
    	case WM_QUIT:
    	case WM_DESTROY:
    		{
    			PostQuitMessage(0);
    			break;
    		}
    	}
    	return DefWindowProc(hWnd, iMsg, wParam, lParam);
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    First of all you should include the correct header file. The proper way of doing this is:
    Code:
    #include <windows.h>
    Next you should post the actual errors you are getting so that we can help you.

  3. #3
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    ok well right of the bat I can tell you that you are mixing up your datatypes and functions which is no doubt causing you problems:

    Code:
    WNDCLASSEX wndClass;
    
    // . . . 
    
    RegisterClassEx (&wndClass);
    
    // . . . .
    
    hWnd = CreateWindow(// . . .should be CreatWindowEx
    
    // . . .
    UnregisterClassEx //doesn't exist, should be UnregisterClass

    Maybe that will help you.

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    Errors:

    The "window.h" is where you would include everything because this is supposed to be a template.

    The errors I get are:
    1. win_main.cpp(31): error C2664: 'CreateWindowExA' : cannot convert parameter 3 from 'WNDCLASSEX' to 'LPCSTR'
    2. win_main.cpp(39): error C3861: 'UnregisterClassEx': identifier not found, even with argument-dependent lookup

    For other information the contents of 'window.h' are:
    Code:
    #include <windows.h>
    #include <iostream>

  5. #5
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Look at the post above. Either stick with WNDCLASS, RegisterClass and CreateWindow or do WNDCLASSEX, RegisterClassEx and CreateWindowEX.

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    Thank You

    Yeah that worked. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21