Results 1 to 7 of 7

Thread: please look at this simple code!

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    please look at this simple code!

    Ok I quit programming for one month and now i started again so here i wrote my empty window program:

    Code:
    #include <windows.h>
    LRESULT CALLBACK WndProc(HWND hwnd, UINT imsg, WPARAM wparam, LPARAM lparam)
    {
    	switch(imsg)
    	{
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    	}
    		return DefWindowProc(hwnd, imsg, wparam, lparam);
    }
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    	WNDCLASSEX wc;
        MSG msg;
    	HWND winhwnd;
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc = WndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hInstance;
    	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = "mycalss";
    	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    
    	if(!RegisterClassEx(&wc))
    	{
    		MessageBox(NULL, "Error in Class Registeration", "Error", MB_OK);
    		return 0;
    	}
    	winhwnd = CreateWindow("myclass", "the title", WS_OVERLAPPEDWINDOW,
    		0,0,34,34,NULL,NULL,hInstance,NULL);
    	if(winhwnd == NULL)
    	{
    		MessageBox(NULL, "Error Creating Hwnd", "Error", MB_OK);
    		return 0;
    	}
    	ShowWindow(winhwnd, nShowCmd);
    	while(GetMessage(&msg, NULL, 0,0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return msg.wParam;
    }
    Can you please get the error in there because when i run the program, it give me the messagebox saying "Error Creating Hwnd".
    Thanks!
    Baaaaaaaaah

  2. #2
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Talking Found it!

    Here:
    Code:
    wc.lpszClassName = "mycalss";
    That is what the classname is, and here:

    Code:
    winhwnd = CreateWindow("myclass", "the title", WS_OVERLAPPEDWINDOW,
    		0,0,34,34,NULL,NULL,hInstance,NULL);
    the classnames are different. i changed them, and it worked
    Amon Ra
    The Power of Learning.

  3. #3
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Thumbs up

    just make them the same
    Amon Ra
    The Power of Learning.

  4. #4

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    I did not get that!

    I did not get that. How come the class name "myclass" was different in the class and hwnd. I used the same name!
    And here is a kind of new version of that. It gives the same error!

    Code:
    #include <windows.h>
    LRESULT CALLBACK WndProc(HWND hwnd, UINT imsg, WPARAM wparam, LPARAM lparam)
    {
    	switch(imsg)
    	{
    	case WM_CLOSE:
    		DestroyWindow(hwnd);
    		break;
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		break;
    	default:
    		return DefWindowProc(hwnd, imsg, wparam, lparam);
    	}
    	return 0;
    	}
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    	WNDCLASSEX wc;
        MSG msg;
    	HWND winhwnd;
    
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = 0;
    	wc.lpfnWndProc = WndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hInstance;
    	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = "mycalss";
    	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    
    	if(!RegisterClassEx(&wc))
    	{
    		MessageBox(NULL, "Error in Class Registeration", "Error", MB_OK);
    		return 0;
    	}
    	winhwnd = CreateWindowEx(
    		WS_EX_CLIENTEDGE, 
    		"myclass", 
    		"the title", 
    		WS_OVERLAPPEDWINDOW,
    		0,
    		0,
    		340,
    		304,
    		NULL,
    		NULL,
    		hInstance,
    		NULL);
    	if(winhwnd == NULL)
    	{
    		MessageBox(NULL, "Error in hwnd Registeration", "Error", MB_OK);
    		return 0;
    	}
    	ShowWindow(winhwnd, nShowCmd);
    	UpdateWindow(winhwnd);
    	while(GetMessage(&msg, NULL, 0,0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return msg.wParam;
    }
    Please tell me the exact error!
    Baaaaaaaaah

  5. #5
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    no...

    One of them is "mycalss" and the other is "myclass". Spelling mistake
    Amon Ra
    The Power of Learning.

  6. #6

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    sorry!

    Oh yes i got that the class names were like that

    mycalss
    myclass


    May I was sleeping at that time!

    THanks a lot buddy
    Baaaaaaaaah

  7. #7
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Talking

    No prob... C++ is so much fun, but sometimes, small stuff like that can....(you know what i mean) LOL
    PS: Did you take a look at my "windows" thread thanks
    Amon Ra
    The Power of Learning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width