• home
  • forum
  • my
  • kt
  • download
  • A Simple Basic Window

    Author: 2009-03-17 08:26:31 From:

    This is very basic tutorial for making win32 based applications in C or C++ language, in this tutorial we will create a basic window. Learn how basic window works.

    Your First Basic Window Application

    /*  Environment Dev C++  */
    /*  Author Yodrive.com  */
     
    #include <windows.h>
     
    HWND hwnd;
    HINSTANCE hInstance;
     
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
     
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
    			LPSTR lpCmdLine, int nCmdShow )
    {
     
    // Declare a Class, u can set Icon Cursor and Background Color in Class
      MSG  msg ;    
      WNDCLASS wc = {0};
      wc.lpszClassName = TEXT( "Static Control" );
      wc.hInstance     = hInstance ;
      wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
      wc.lpfnWndProc   = WndProc ;
      wc.hCursor       = LoadCursor(0,IDC_ARROW);
      wc.hIcon          = LoadIcon (NULL, IDI_APPLICATION);
      wc.hCursor = LoadCursor (NULL, IDC_ARROW);
     
    // Register Above Declared Class
      RegisterClass(&wc);
     
    // Create Window and Store its Handle HWND in Variable hwnd
     hwnd = CreateWindow( wc.lpszClassName, TEXT("Win32 Basic Window "),
                    WS_OVERLAPPEDWINDOW,
                    100, 100, 330, 270, 0, 0, hInstance, 0);  
     
    // Show and update window, it require handle of ur Created window which is stored in hwnd  
     ShowWindow(hwnd, nCmdShow);
     UpdateWindow(hwnd);
     
    // Loop for getting message send by user to Window eg, Mouse and Keyboard inputs
     
      while( GetMessage(&msg, NULL, 0, 0))
      {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
      return (int) msg.wParam;
    }
     
    // Perform Action on Messages , Sent By  Above While Loop
    LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
    {
     
      switch(msg)
       {
        case WM_DESTROY:
           {
            PostQuitMessage(0);
            return 0;
           }
       }
     
     return DefWindowProc(hwnd, msg, wParam, lParam);
    }

    Every Basic Window Have 5 Basic Steps.
    We will follow these steps to Create a Basic Window

    1. WinMain Function ( Entry Point of GUI Program )

    2. Defining a Window Class and Registering.

    3. Createwindow Function for making a window

    4. While loop for Get message Translate Message and Dispatch Message

    5. WindowProcedure for Performing a action according to dispatched Messages By 4th step

    Read our Other Tutorials in Win32 API Category for Learn more about Pure win32 Api Programming

    discuss this topic to forum

    relation tutorial

    No information

    Category

      Database Related (0)
      Development (5)
      File Manipulation (3)
      Games and Entertainment (10)
      Graphics (14)
      Introduction to C and Cpp (23)
      Miscellaneous (9)
      Networking (5)
      Programming in C and Cpp (10)
      Security (3)

    New

    Hot