Thread: Basic windows programming

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    4

    Basic windows programming

    I'm doing a lesson from a book call "Tricks of the Window Game Programming Gurus", where it trys to teach you how to make the basic parts of a window.
    Sorry for cloggin the place up with comments but thats how I remember what the certain things do.
    However, when linking the file i get 2 errors:
    Code:
    Linking...
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/Demo.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.
    
    Demo.exe - 2 error(s), 0 warning(s)
    heres my code
    Code:
    //DEMO2_3.C - A complete windows program
    
    //INCLUDES/////////////////////////////////////////////////////
    #define WIN32_LEAN_AND_MEAN
    
    #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"
    
    //FUNCTIONS////////////////////////////////////////////////////
    
    //the event handler
    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;
    
    } //ends switch
    
    //process any messages that we didn't take car of
    return (DefWindowProc(hwnd, msg, wparam, lparam));
    
    } //ends WinProc
    
    //WINMAIN//////////////////////////////////////////////////////////
    int WINAPI WinMain(HINSTANCE hinstance,
    				   HINSTANCE hprevinstance,
    				   LPSTR lpcmdline,
    				   int ncmdshow)
    {
    
    WNDCLASSEX winclass; //this will hold the class we make
    HWND	hwnd;	//generic window handle
    MSG		msg;	//generic message
    
    
    // first fill in window class structure
    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 ="WINCLASS1";
    winclass.hIconSm    = LoadIcon(NULL, IDI_APPLICATION);
    
    
    //this registers our class with windows
    if(!RegisterClassEx(&winclass))
       return(0);
    
    //this creates the window, bails if there is a problem
    if(!(hwnd = CreateWindowEx(NULL,	//extended style
    		"WINCLASS1",          //this points to the class
    		"Your Basic Window",    //the title of the window
    		WS_OVERLAPPEDWINDOW | WS_VISIBLE,    //a few styles for the window
    		0,0,		//initial x,y coordinates
    		400,400,	//initial width and height 
    		NULL,		//makes the handle to the parent, NULL makes desktop the parent
    		NULL,		//handle to the menu
    		hinstance,         //instance of this application
    		NULL)))	         //extra creation parameters
    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
    Any suggestions? Oh yeah, I'm usin Visual C++.

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    175
    I think, while creating project, you have choosen 'Win32 Console application'. And that is the reason, it is showing up the error.

    Create Win32 Application..

    Hopefully that will sovle this problem

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    4
    aww man, you were right on the money.

    TY roaring tiger

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Also, GetMessage() returns one of THREE values: positive, zero, or negative (if an error occurs). So unless you want an infinite loop on error, change to:

    while(GetMessage() > 0)
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LoadFromFile() causes Windows 98 to freeze?
    By MidnightlyCoder in forum Windows Programming
    Replies: 8
    Last Post: 03-17-2006, 02:23 PM
  2. Program works on Windows XP and 2000, not on 98 or ME
    By MidnightlyCoder in forum C++ Programming
    Replies: 7
    Last Post: 03-10-2006, 03:36 PM
  3. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM