Thread: no errors but still errors

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    57

    no errors but still errors

    ok this code compiles fine but when i run this window I get an error from windows Im not sure why
    using msvc++ 6.0 + windows xp

    Code:
    ///////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////
    //////////////////
    //
    //
    // Title: DrawingStuff
    // Author: Brad Hoffer
    // Notes: Good luck to myself!
    //
    //
    //////////////////
    ///////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////
    
    
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    #include <stdlib.h>
    
    
    int GameInit();
    	int GameLoop();
    	int GameShutdown();
    	
    	HWND g_hWndMain;
    
    
    
    
    
    
    long CALLBACK WndProc( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam )
    
    {
    	PAINTSTRUCT PaintStruct;
    	
    	HDC hDC;
    	
    	
    	
    	switch (uMessage)
    	{
    		case WM_CREATE:
    			{
    				return 0;
    			}
    
    		case WM_PAINT:
    			{
    
    				hDC = BeginPaint(hWnd, &PaintStruct);
    				
    				EndPaint (hWnd, &PaintStruct);
    
    				return 0;
    			}
    
    		case WM_DESTROY:
    			{
    				PostQuitMessage(0);
    				
    				return 0;
    			}
    
    		default:
    			{
    				return DefWindowProc(hWnd, uMessage, wParam, lParam);
    			}
    	}
    }
    
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pstrCmdLine, int iCmdShow)
    
    	{
    		HWND hWnd;
    		MSG msg;
    		WNDCLASSEX wc;
    		
    		
    
    		static char strAppName[] = "Brads first win app";
    
    		
    		
    		
    		
    		wc.cbSize = sizeof(WNDCLASSEX);
    		wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    		wc.cbClsExtra = 0;
    		wc.cbWndExtra = 0;
    		wc.lpfnWndProc = WndProc;
    		wc.hInstance = hInstance;
    		wc.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
    		wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    		wc.hIconSm = LoadIcon(NULL, IDI_HAND);
    		wc.hCursor = LoadCursor(NULL, IDC_CROSS);
    		wc.lpszMenuName = NULL;
    		wc.lpszClassName = strAppName;
    
    		RegisterClassEx(&wc);
    
    		hWnd = CreateWindowEx( NULL,
    								strAppName,
    								strAppName,
    								WS_OVERLAPPEDWINDOW,
    								CW_USEDEFAULT,
    								CW_USEDEFAULT,
    								512,512,
    								NULL,
    								NULL,
    								hInstance,
    								NULL);
    		g_hWndMain = hWnd;
    
    		GameInit();
    
    		ShowWindow(hWnd, iCmdShow);
    
    		UpdateWindow(hWnd);
    
    
    		while(TRUE)
    		{
    			
    			if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    				{
    					if (msg.message == WM_QUIT)
    						break;
    
    					TranslateMessage(&msg);
    
    					DispatchMessage(&msg);
    				}
    
    			else
    				{
    
    				GameLoop();
    				
    				}
    		}
    		
    		GameShutdown();
    		return msg.wParam;
    }
    
    
    int GameInit()
    {
    	return 0;
    }
    
    
    int GameLoop()
    {
    	HDC hDC;
    
    	hDC = GetDC(g_hWndMain);
    	
    	RECT ClientRect;
    	
    	GetClientRect(g_hWndMain,&ClientRect);
    
    	if (ClientRect.bottom == 0 || ClientRect.right == 0)
    		{
    			ReleaseDC(g_hWndMain,hDC);
    			return 0;
    		}
    
    	HPEN hPen = CreatePen(PS_SOLID,rand()%5,RGB(rand()%255,rand()%255,rand()%255,));
    
    	LOGBRUSH logBrush;
    
    	logBrush.lbColor = RGB(rand()%255,rand()%255,rand()%255);
    	logBrush.lbHatch = 0;
    	logBrush.lbStyle = BS_SOLID;
    
    	HBRUSH hBrush = CreateBrushIndirect(&logBrush);
    
    	SelectObject(hDC,hBrush);
    
    	SelectObject(hDC,hPen);
    
    	Rectangle(hDC,rand()%ClientRect.right,rand()%ClientRect.bottom,rand()%ClientRect.left,rand()%ClientRect.top);
    
    	DeleteObject(SelectObject(hDC,GetStockObject(BLACK_BRUSH)));
    	DeleteObject(SelectObject(hDC,GetStockObject(BLACK_PEN)));
    
    	ReleaseDC(g_hWndMain,hDC);
    
    	return 0;
    }
    
    int GameShutdown()
    {
    	return 0;
    }
    =@-OmegatronO-@=

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You cannot use LoadIcon() for the small icon. You have to use LoadImage() instead. LoadIcon() is now deprecated and maybe you should prefer LoadImage() for the larger icon too.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    57
    ok... tried that but its crying about my paramaters whats the prototype for LoadImage() i mean what are the parameters for it
    =@-OmegatronO-@=

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    heres how i did it in my object wrapper around the api.
    Code:
    void WinLib::WinClass::SetResIcons( int ResID )
    {
    	_class.hIcon = reinterpret_cast<HICON>
    		( ::LoadImage( _class.hInstance, MAKEINTRESOURCE( ResID ),
    		IMAGE_ICON,
    		::GetSystemMetrics( SM_CXICON ),
    		::GetSystemMetrics( SM_CYICON ),
    		LR_DEFAULTCOLOR ));
    	_class.hIconSm = reinterpret_cast<HICON>
    		( ::LoadImage( _class.hInstance, MAKEINTRESOURCE( ResID ),
    		IMAGE_ICON,
    		::GetSystemMetrics( SM_CXSMICON ),
    		::GetSystemMetrics( SM_CYSMICON ),
    		LR_DEFAULTCOLOR ));
    }
    for more details about how to use LoadImage or any other api function you can consult the docs at MSDN
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    57
    ok here is the problem Im learning from a book which so far has been verry good, entertaining, and... reasuring(i think thats how u spell that..) and ive tried the LoadImage() deal and i cant get it to work no matter what i put in there for parameters...
    now i have a cd that came with the book, which by the way is called The Zen of Direct3D Game Programming written by Peter Walsh and his source is on the cd
    The code appears indentical to what i have written and he used the LoadIcon() function and no problem compiling and running it so whats the deal?? so they both compile fine but only one runs
    Can anyone help me with this issue I apprecieate it here is his code:

    Code:
    #define WIN32_LEAN_AND_MEAN
    
    // The main windows include file
    #include <windows.h>
    #include <stdlib.h>
    
    int GameInit();
    int GameLoop();
    int GameShutdown();
    
    HWND g_hWndMain;
    
    // The window procedure to handle events
    long CALLBACK WndProc( HWND hWnd, UINT uMessage, 
                                    WPARAM wParam, LPARAM lParam )
    {
    	PAINTSTRUCT PaintStruct;	// Structure used during windows painting
    	HDC hDC;			// Handle to device context for painting
    
    	// Switch the windows message to figure out what it is
    	switch( uMessage )
    	{
    		case WM_CREATE:	// The CreateWindow() function was just called
    		{
    			// One Time Initialization
    			return 0;
    		}
    
    		case WM_PAINT:	// The window needs to be redrawn
    		{
    			// Tell windows we want to start updating the window
    			hDC = BeginPaint( hWnd, &PaintStruct );
    
    			// Tell windows we have finished updating the window
    			EndPaint( hWnd, &PaintStruct );
    			return 0;
    		}
    		
    		case WM_DESTROY:	// The window is about to be closed
    		{
    			// Our main window is closing.  This means we want our app to exit.
    			// Tell windows to put a WM_QUIT message in our message queue
    			PostQuitMessage( 0 );
    			return 0;
    		}
    
    		default:			// Some other message
    		{
    			// Let windows handle this message
    			return DefWindowProc( hWnd, uMessage, wParam, lParam );
    		}
    	}
    }
    
    // The windows entry point. The application will start executing here
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                                         PSTR pstrCmdLine, int iCmdShow )
    {
    	HWND hWnd;		// The handle to our main window
    	MSG msg;		// The message windows is sending us
    	WNDCLASSEX wc;	// The window class used to create our window
    
    	// The name of our class and also the title to our window
    	static char strAppName[] = "Multiple Rectangles";
    
    	// Fill in the window class with the attributes for our main window
    
    	// The size of this struture in bytes
    	wc.cbSize			= sizeof( WNDCLASSEX );
    	
    	//  The style of the window.
    	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    	// Useless information.  Just set to zero.
    	wc.cbClsExtra		= 0;
    	// Useless information.  Just set to zero.
    	wc.cbWndExtra		= 0;
    	// The name of our event handler
    	wc.lpfnWndProc		= WndProc;
    	// A handle to the applications instance
    	wc.hInstance		= hInstance;
    	// The handle to the brush to use for the window background
    	wc.hbrBackground	= (HBRUSH)GetStockObject( DKGRAY_BRUSH );
    	// A handle to the icon to use for the window
    	wc.hIcon			= LoadIcon( NULL, IDI_APPLICATION );
    	// A handle to a smaller version of the apps icon
    	wc.hIconSm			= LoadIcon( NULL, IDI_APPLICATION );
    	// A handle to the cursor to use while the mouse is over our window
    	wc.hCursor			= LoadCursor( NULL, IDC_CROSS );
    	// A handle to the resource to use as our menu
    	wc.lpszMenuName		= NULL;
    	// The human readable name for this class
    	wc.lpszClassName	= strAppName;
    
    	// Register the class with windows
    	RegisterClassEx( &wc );
    
    	// Create the window based on the previous class
    	hWnd = CreateWindowEx( NULL,	// Advanced style settings
    	            strAppName,			// The name of the class
    				strAppName,			// The window caption
    				WS_OVERLAPPEDWINDOW,// The window style
    			   	CW_USEDEFAULT,		// The initial x position 
                    CW_USEDEFAULT,		// The initial y position
    			   	512, 512,			// The intiial width / height
    				NULL,				// Handle to parent window						
    				NULL,				// Handle to the menu
    				hInstance,			// Handle to the apps instance
    				NULL );				// Advanced context
    
    	g_hWndMain = hWnd;
    
    	GameInit();
    
    	// Display the window we just created
    	ShowWindow( hWnd, iCmdShow );
    	// Draw the window contents for the first time
    	UpdateWindow( hWnd );
    
    	
    	// Start the message loop
    	while( TRUE )
    	{
    		// Check if a message is waiting for processing
    		if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
    		{
    			// Check if the message is to quit the application
    			if( msg.message == WM_QUIT )
    				// Exit the message loop
    				break;
    			
    			// Change the format of certain messages
    			TranslateMessage( &msg );
    			// Pass the message to WndProc() for processing
    			DispatchMessage( &msg );
    		}
    		else
    		{
    			GameLoop();
    		}
    	}
    
    
    	GameShutdown();
    
    	// Return control to windows with the exit code
    	return msg.wParam;
    }
    
    
    int GameInit()
    {
    	// Game Initialization
    
    	return 0;
    }
    
    int GameLoop()
    {
    	// Create a handle to the DC
    	HDC hDC;
    
    	// Get a DC for this window
    	hDC = GetDC( g_hWndMain );
    
    	// RECT structure to hold the dimensions of the client area
    	RECT ClientRect;
    
    	// Get the client area size
    	GetClientRect( g_hWndMain, &ClientRect );
    
    	// Make sure the window is not minimized
    	if( ClientRect.bottom == 0 || ClientRect.right == 0 )
    	{
    		// Return if the window is minimized
    		ReleaseDC( g_hWndMain, hDC );
    		return 0;
    	}
    
    	// Create a solid pen for the rectangle border
    	// with a random width and random color
    	HPEN hPen = CreatePen( PS_SOLID, rand()%5, 
    						RGB( 	rand()%255, 
    					        	rand()%255, 
    								rand()%255 ) );
    
    	// Brush structure to describe the brush
    	LOGBRUSH logBrush;
    
    	// The color will be random
    	logBrush.lbColor = RGB( rand()%255, 
    				rand()%255, 
    				rand()%255 );
    	// We are not using a hatch
    	logBrush.lbHatch = 0;
    	// The fill should be solid
    	logBrush.lbStyle = BS_SOLID;
    
    	// Create the brush
    	HBRUSH hBrush = CreateBrushIndirect( &logBrush );
    
    	// Select the brush into the device context
    	SelectObject( hDC, hBrush );
    	// Select the pen into device context
    	SelectObject( hDC, hPen );
    
    	// Draw the rectangle using random dimensions
    	Rectangle( hDC, rand()%ClientRect.right, 
    					rand()%ClientRect.bottom, 
    					rand()%ClientRect.right, 
    					rand()%ClientRect.bottom );
    	
    	// Get rid of the brush
    	DeleteObject( SelectObject( hDC, GetStockObject( BLACK_BRUSH ) ) );
    	// Get rid of the pen
    	DeleteObject( SelectObject( hDC, GetStockObject( BLACK_PEN ) ) );
    
    	// Release the DC back to Windows
    	ReleaseDC( g_hWndMain, hDC );
    
    	return 0;
    
    }
    
    int GameShutdown()
    {
    	// Shutdown Code
    
    	return 0;
    }
    =@-OmegatronO-@=

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    check out your rectangle params to his. Yours are wrong. His are right. Thats why you get the error. As for LoadIcon() the SDK docs say that it is only suitable for icons of SM_CXICON,SM_CYICON size. The same docs recommend using LoadImage() instead.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    7
    <pre>The same docs recommend using LoadImage() instead.</pre>

    Those idiots, they make perfectly good functions obsolete for no reason. Oh well, LoadIcon still works, so I'll stick with simplicity. I also see no reason why you need an extended window class here, you're not using extended styles. Just do WNDCLASS, omit the sizeof thingy, and omit the small icon; you're set. Besides, why not make your own icon, you can do 16 by 16 and 32 by 32 icons in the same file, so why not?

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    57
    ya it was the rect params
    im just gonna stik wit the LoadIcon() function
    he said i wouldnt need the extended stuff but it would maby come in handy some day if i ever give up game programming and become a grumpy old windows programmer.....uhh thats a joke eh!

    thanks alot people
    =@-OmegatronO-@=

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM