Win32 Skeleton

Code

    #include 
    
    
    LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
    char szWinName[] = "Windows skeleton";
    
    
    int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszArgs, int nWinMode)
    {
    	HWND hwnd;
    	MSG msg;
    	WNDCLASS wcl;
    
    	wcl.hInstance = hThisInst;
    	wcl.lpszClassName = szWinName;
    	wcl.lpfnWndProc = WindowFunc;
    	wcl.style = 0;
    	wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wcl.lpszMenuName = NULL;
    
    	wcl.cbClsExtra = 0;
    	wcl.cbWndExtra = 0;
    
    	wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    
    	if (!RegisterClass (&wcl)) return 0;
    
    	hwnd = CreateWindow(
    	  szWinName,
    	  szWinName,
    	  WS_OVERLAPPEDWINDOW,
    	  CW_USEDEFAULT,
    	  CW_USEDEFAULT,
    	  CW_USEDEFAULT,
    	  CW_USEDEFAULT,
    	  HWND_DESKTOP,
    	  NULL,
    	  hThisInst,
    	  NULL
    	);
    
    	ShowWindow(hwnd, nWinMode);
    	UpdateWindow(hwnd);
    
    	// Message loop
    	while(GetMessage(&msg, NULL, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return msg.wParam;
    }
    
    
    LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch(message)
    	{
    		case WM_DESTROY:
    		PostQuitMessage(0);
    		break;
    
    		default:
    		return DefWindowProc(hwnd, message, wParam, lParam);
    	}
    
    	return 0;
    
    }
    
    
    
      

Output

    A Window.
    

Timer method one - WM_TIMER message

Code

    /** Need timer # deal **
     ***********************/
    #define IDT_TIMER1          1
    
    
    /** Start the timer *****************************************************************
     *                                                                                  *
     * hWin = Window timer messages are sent to.                                        *
     * IDT_TIMER1 = The timer id number.                                                *
     * timevarible_ms = Number of milliseconds for timer to go off in.                  *
     * (TIMERPROC) 0 = Callback function.  If null WM_TIMER posted instead (like here). *
     ************************************************************************************/
    SetTimer(hWin, IDT_TIMER1, timevarible_ms, (TIMERPROC) 0);
    
    
    /** In the callback function for the window specified for timer events. **
     *************************************************************************/
    LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
      switch(message)
      {
       /** Handle message ********************************
        * If the callback function for the timer is null *
        * the WM_TIMER message is posted instead with    *
        * wParam containing the timer id number.         *
        **************************************************/
        case WM_TIMER:                
        switch(wParam)                 
        {                              
          case IDT_TIMER1:             
          // Timer code goes here.
          break;
        }
        break;
      }
    }
    
      

Output

Timer method two - Callback function

Code

    /** Need timer # deal **
     ***********************/
    #define IDT_TIMER1          1
    
    
    /** Start the timer *****************************************************************
     *                                                                                  *
     * hWin = Window timer messages are sent to.                                        *
     * IDT_TIMER1 = The timer id number.                                                *
     * timevarible_ms = Number of milliseconds for timer to go off in.                  *
     * (TIMERPROC) 0 = Callback function.  If null WM_TIMER posted instead (like here). *
     ************************************************************************************/
    SetTimer(hWin, IDT_TIMER1, timevarible_ms, (TIMERPROC) Timer1Func);
    
    
    /** In the callback function for timer events. **
     ************************************************/
    VOID CALLBACK Timer1Func(HWND hwnd, UINT message, UINT timerID, DWORD currentTime)
    {
     /** Handle message ********************************
      * If the callback function for the timer is null *
      * the WM_TIMER message is posted instead with    *
      * wParam containing the timer id number.         *
      **************************************************/
      switch(timerID)
      {                              
        case IDT_TIMER1:             
        // Timer code goes here.
        break;
      }
    }
    
    
      

Output