Thread: What is wrong with this code?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    What is wrong with this code?

    I get no errors when I run this code, but my error message pops up. I tried taking the error message out, and no window popped up and nothing happened. What is wrong!

    main.cpp
    Code:
    #include <windows.h>
    #include "resource.h"
    
    LRESULT CALLBACK WinProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
    HWND MakeWindow(HINSTANCE hInstance);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR iCmdLine, int iShow)
    {
    	HWND hWnd;
    	hWnd = MakeWindow(hInstance);
    	if(!hWnd)
    	{
    		MessageBox(hWnd,"Failed to Create Window!","Fatal Error!",MB_ICONERROR);
    		UnregisterClass("Boodle",hInstance);
    		return NULL;
    	}
    	MSG iMsg;
    	while(1)
    	{
    		if(PeekMessage(&iMsg,NULL,0,0,PM_REMOVE))
    		{
    			TranslateMessage(&iMsg);
    			DispatchMessage(&iMsg);
    		}
    	}
    	UnregisterClass("Boodle",hInstance);
    	return iMsg.wParam;
    }
    
    LRESULT CALLBACK WinProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch(iMsg)
    	{
    		case WM_DESTROY:
    		{
    			PostQuitMessage(0);
    			break;
    		}
    	}
    	return DefWindowProc (hWnd, iMsg, wParam, lParam);
    }
    
    HWND MakeWindow(HINSTANCE hInstance)
    {
    	WNDCLASSEX wndClassEx;
    	wndClassEx.cbSize = sizeof(wndClassEx);
    	wndClassEx.style = CS_HREDRAW | CS_VREDRAW;
    	wndClassEx.cbClsExtra = 0;
    	wndClassEx.cbWndExtra = 0;
    	wndClassEx.hIconSm = (HICON)LoadImage(hInstance,MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,0,0,LR_DEFAULTSIZE);
    	wndClassEx.lpszMenuName = NULL;
    	wndClassEx.lpfnWndProc = WinProc;
    	wndClassEx.hInstance = hInstance;
    	wndClassEx.hIcon = (HICON)LoadImage(hInstance,MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,0,0,LR_DEFAULTSIZE);
    	wndClassEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	wndClassEx.lpszClassName = "Boodle";
    
    	RegisterClassEx(&wndClassEx);
    
    	HWND hWnd;
    
    	hWnd = CreateWindow("Boodle","Might of the Boodle!",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,650,600,NULL,NULL,hInstance,NULL);
    
    	if(!hWnd)
    		return NULL;
    
    	return hWnd;
    }
    resource.h
    Code:
    //{{NO_DEPENDENCIES}}
    // Microsoft Visual C++ generated include file.
    // Used by resource.rc
    //
    #define IDI_ICON1                       101
    
    // Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE        102
    #define _APS_NEXT_COMMAND_VALUE         40001
    #define _APS_NEXT_CONTROL_VALUE         1001
    #define _APS_NEXT_SYMED_VALUE           101
    #endif
    #endif
    The resource file just has my icon. I'm using MSVS .NET so I cannot give you the source for resource.rc because it won't show you.
    Last edited by ElWhapo; 01-22-2005 at 09:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM