arg

This is a discussion on arg within the Windows Programming forums, part of the Platform Specific Boards category; I hate how tempremental this **** can be... I just wrote this, I thoght it would work no problem... but ...

  1. #1
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    Angry arg

    I hate how tempremental this **** can be... I just wrote this, I thoght it would work no problem... but for some dumbass reason it says "FAILED TO CREATE WINDOW", in otherwords hwnd == NULL.

    Code:
    #include <windows.h>
    
    bool jah = true;
    
    HWND hwnd;
    
    LRESULT CALLBACK wndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    
    	switch(Message)
    	{
    	case WM_CLOSE: DestroyWindow(hwnd); jah = false; return 0;
    	default:return 0;
    	}
    	return DefWindowProc(hwnd, Message, wParam, lParam);
    }
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
    {
    	MSG * msg = new MSG;
    	WNDCLASSEX wnd;
    	ZeroMemory((void*)&wnd,sizeof(WNDCLASSEX));
    	wnd.cbSize = sizeof(WNDCLASSEX);
    	wnd.hbrBackground = (HBRUSH)(COLOR_WINDOW);
    	wnd.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    	wnd.hCursor       = LoadCursor(NULL, IDC_ARROW);
    	wnd.hIconSm		  = wnd.hIcon;
    	wnd.hInstance	  = hInstance;
    	wnd.lpfnWndProc   = wndProc;
    	wnd.lpszClassName = "listcontroltest";
    	if(!RegisterClassEx(&wnd))
    	{
    		MessageBox(NULL,"FAILED TO REGISTER CLASS","ERROR",MB_ICONERROR);
    		return 0;
    	}
    
    	hwnd = CreateWindowEx(WS_SYSMENU,"listcontroltest","Hello",WS_SYSMENU,0,0,100,100,NULL,(HMENU)NULL,hInstance,NULL);
    	if(!hwnd)
    	{
    		MessageBox(NULL,"FAILED TO CREATE WINDOW","ERROR",MB_ICONERROR);
    		return 0;
    	}
    
    	ShowWindow(hwnd,nCmdShow);
    	UpdateWindow(hwnd);
    
    	while(jah)
    	{
    		PeekMessage(msg,NULL,0,0,PM_REMOVE);
    		TranslateMessage(msg);
    		DispatchMessage(msg);
    	}
    	return 1;
    }
    SPH

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    5
    hi,
    I think that the problem is in the below function's first parameter.
    It should not be WS_SYSMENU ( I can be wrong!!) please refer MSDN for the function defination. Put 0 or NULL on the First Param.

    CreateWindowEx(WS_SYSMENU,"listcontroltest","Hello " ,WS_SYSMENU,0,0,100,100,NULL,(HMENU)NULL,hInstance
    ,NULL);


    jatan

  3. #3
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    Your wndproc is preventing your window from being created. You'll have to remove the default case. Also unless you change the style in the CreateWindowEx() call you probably wont get what you expect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer to struct
    By Paul Johnston in forum C Programming
    Replies: 4
    Last Post: 06-11-2009, 03:01 AM
  2. Replies: 10
    Last Post: 06-08-2009, 02:42 PM
  3. Replies: 5
    Last Post: 08-12-2007, 05:26 PM
  4. Ranged numbers
    By Desolation in forum Game Programming
    Replies: 8
    Last Post: 07-25-2006, 10:02 PM
  5. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM

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