windows_programming_notes.nbk: Home | Index | Next Page: WM_ACTIVATE | Previous Page: Windows Styles


 WinMain

The WinMain function is called by the system as the initial entry point for a Win32-based application.

    int WINAPI WinMain(
      HINSTANCE hInstance,      // handle to current instance
      HINSTANCE hPrevInstance,  // handle to previous instance
      LPSTR lpCmdLine,          // command line
      int nCmdShow              // show state
    );

Parameters

Return Values

If the function succeeds, terminating when it receives a WM_QUIT message, it should return the exit value contained in that message's wParam parameter. If the function terminates before entering the message loop, it should return zero.

Remarks

Your WinMain should initialize the application, display its main window, and enter a message retrieval-and-dispatch loop that is the top-level control structure for the remainder of the application's execution. Terminate the message loop when it receives a WM_QUIT message. At that point, your WinMain should exit the application, returning the value passed in the WM_QUIT message's wParam parameter. If WM_QUIT was received as a result of calling PostQuitMessage, the value of wParam is the value of the PostQuitMessage function's nExitCode parameter. For more information, see Creating a Message Loop.

ANSI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. The reason that WinMain cannot return Unicode strings is that lpCmdLine uses the LPSTR data type, not the LPTSTR data type. The GetCommandLine function can be used to access Unicode strings in the command line, because it uses the LPTSTR data type.

Requirements


windows_programming_notes.nbk: Home | Index | Next Page: WM_ACTIVATE | Previous Page: Windows Styles


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time