Results 1 to 4 of 4

Thread: C/C++ - Simple Win32 App

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2003
    Posts
    34

    C/C++ - Simple Win32 App

    This is just a simple setup for a simple win32 app. I didnt really do much explaining but i did include some comments on whats going on at a particular place. I will hopefully get a simple opengl tutorial up soon, building off this framework. If want a more in-depth explaination on how all this code works do a search on google.com.

    Code:
    #define WIN32_LEAN_AND_MEAN  //cut down on windows
    
    #include <windows.h>  //our windows library
    
    
    //================================================================================
    //event handler
    //the event handler processes messages from windows
    //ex.  Key Press,MouseMove, Close, ETC ...
    //================================================================================
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam, LPARAM lParam)
    {
    
    switch(message)
    {
    case WM_CLOSE:
    PostQuitMessage(0); //send message to close program
    return 0;
    break;
    
    }
    
    return DefWindowProc(hwnd,message,wParam,lParam);
    }
    
    //================================================================================
    //program entry point
    //This is where the program actually starts
    //We need to setup up a windows class then register it
    //after you register it you can create your window
    //================================================================================
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
    {
    WNDCLASSEX winClass;  //windows class
    HWND hwnd; //windows handle
    MSG msg;  //message
    bool done;  //status of app
    
    //window class structure
    winClass.cbSize = sizeof(WNDCLASSEX);
    winClass.style = CS_HREDRAW | CS_VREDRAW;
    winClass.lpfnWndProc = WndProc;
    winClass.cbClsExtra = 0;
    winClass.cbWndExtra = 0;
    winClass.hInstance = hInstance;
    winClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    winClass.hCursor = LoadCursor(NULL,IDC_ARROW);
    winClass.hbrBackground = NULL;
    winClass.lpszMenuName = NULL;
    winClass.lpszClassName = "MyClass";
    winClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
    
    //register our windows class
    if (!RegisterClassEx(&winClass))
         return 0;
    
    //once class is registered create window
    hwnd = CreateWindowEx(NULL,       //extended style
    		      "MyClass",  //class name
    		      "Win32 App",//app name
    		      WS_OVERLAPPEDWINDOW |   WS_VISIBLE|  //style
    		      WS_SYSMENU | WS_CLIPCHILDREN | 
    		      WS_CLIPSIBLINGS,
    		      100,100, //x y coordinates
    		      400,400,  //height and width
    		      NULL,    //handle to parent
    		      NULL,    //handle to menu
    		      hInstance,  //app instance
    		      NULL);    //no extra params
    
    //check to see if hwnd failed or not
    if (!hwnd)
    return 0;
    
    ShowWindow(hwnd,SW_SHOW);  //show window
    UpdateWindow(hwnd);  //update the window
    
    done = false;  //start of loop
    //================================================================================
    //Message Loop
    //This loop is specially setup for something like Directx/Opengl Render functions but it can but used for a normal app too
    //================================================================================
    
    
    
    
    while (!done)
    {
    PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE);
    
    if (msg.message == WM_QUIT)
    {
    done = true;
    }
    else
    {
    //do what you want
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }
    return msg.wParam;
    }
    Last edited by BeholderOf; Sep 18th, 2003 at 09:08 AM.

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