Need help with a simple Window

This is a discussion on Need help with a simple Window within the C++ Programming forums, part of the General Programming Boards category; Hello, it's me toonlover. May any one help me with this code, it's a simple window....here is the code: Code: ...

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Texas
    Posts
    103

    Need help with a simple Window

    Hello, it's me toonlover. May any one help me with this code, it's a simple window....here is the code:
    Code:
    // DEMO2_3.CPP - A complete windows program
    
    // INCLUDES ///////////////////////////////////////////////
    #define WIN32_LEAN_AND_MEAN  // just say no to MFC
    
    #include <windows.h>   // include all the windows headers
    #include <windowsx.h>  // include useful macros
    #include <stdio.h>     
    #include <math.h>
    
    // DEFINES ////////////////////////////////////////////////
    
    // defines for windows 
    #define WINDOW_CLASS_NAME "WINCLASS1"
    
    // GLOBALS ////////////////////////////////////////////////
    
    
    // FUNCTIONS //////////////////////////////////////////////
    LRESULT CALLBACK WindowProc(HWND hwnd, 
    						    UINT msg, 
                                WPARAM wparam, 
                                LPARAM lparam)
    {
    // this is the main message handler of the system
    PAINTSTRUCT		ps;		// used in WM_PAINT
    HDC				hdc;	// handle to a device context
    
    // what is the message 
    switch(msg)
    	{	
    	case WM_CREATE: 
            {
    		// do initialization stuff here
    
            // return success
    		return(0);
    		} break;
    
    	case WM_PAINT: 
    		{
    		// simply validate the window
    		hdc = BeginPaint(hwnd,&ps);	 
    		// you would do all your painting here
            EndPaint(hwnd,&ps);
    
            // return success
    		return(0);
       		} break;
    
    	case WM_DESTROY: 
    		{
    		// kill the application, this sends a WM_QUIT message 
    		PostQuitMessage(0);
    
            // return success
    		return(0);
    		} break;
    
    	default:break;
    
        } // end switch
    
    // process any messages that we didn't take care of 
    return (DefWindowProc(hwnd, msg, wparam, lparam));
    
    } // end WinProc
    
    // WINMAIN ////////////////////////////////////////////////
    int WINAPI WinMain(	HINSTANCE hinstance,
    					HINSTANCE hprevinstance,
    					LPSTR lpcmdline,
    					int ncmdshow)
    {
    
    WNDCLASSEX winclass; // this will hold the class we create
    HWND	   hwnd;	 // generic window handle
    MSG		   msg;		 // generic message
    
    // first fill in the window class stucture
    winclass.cbSize         = sizeof(WNDCLASSEX);
    winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                              CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc	= WindowProc;
    winclass.cbClsExtra		= 0;
    winclass.cbWndExtra		= 0;
    winclass.hInstance		= hinstance;
    winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
    winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
    winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
    winclass.lpszMenuName	= NULL;
    winclass.lpszClassName	= WINDOW_CLASS_NAME;
    winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
    
    // register the window class
    if (!RegisterClassEx(&winclass))
    	return(0);
    
    // create the window
    if (!(hwnd = CreateWindowEx(NULL, // extended style
                                WINDOW_CLASS_NAME,   // class
    						    "Your Basic Window", // title
    						    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    					 	    0,0,	    // initial x,y
    						    400,400,  // initial width, height
    						    NULL,	    // handle to parent 
    						    NULL,	    // handle to menu
    						    hinstance,// instance of this application
    						    NULL)))	// extra creation parms
    return(0);
    
    // enter main event loop
    while(GetMessage(&msg,NULL,0,0))
     	 { 
    	 // translate any accelerator keys
    	 TranslateMessage(&msg);
    
    	 // send the message to the window proc
    	 DispatchMessage(&msg);
    	 } // end while
    
    // return to Windows like this
    return(msg.wParam);
    
    } // end WinMain
    
    ///////////////////////////////////////////////////////////
    And my compiler is telling me this error, it's Visual C++ 6.0 with SP6:
    Code:
    --------------------Configuration: Code - Win32 Debug--------------------
    Linking...
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/Code.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    
    Code.exe - 2 error(s), 0 warning(s)
    May any one please be of any assistance...Please....Thankyou in advance.....

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    1) this should be in the 'Windows Programming' forum

    2) you should initialize and register your window before your winproc.. also your message loop also needs to be before your windows procedure.

    3) you'll need to compile your program as a 'windows' project.. (as opposed to a dos console project) how do do this will vary amoung compilers.. if using Borland, use the -W switch after the bcc32 command. If using dev-cpp or mvsc++ 6.0, be sure to open a win32 project.
    Last edited by The Brain; 07-03-2005 at 11:35 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    May 2005
    Location
    Texas
    Posts
    103
    What do you mean by a "windows" project...In my Visual C++, there is no "Windows' as a project, please help me..

  4. #4
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Lightbulb It's right herr.

    it's right here. yo.
    Attached Images Attached Images  
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  5. #5
    *this
    Join Date
    Mar 2005
    Posts
    498
    Wait...Where is it?

  6. #6
    Registered User
    Join Date
    May 2005
    Location
    Texas
    Posts
    103
    Thankyou the Brain...For helping me....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 07:14 AM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  3. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

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