int PASCAL WinMain(hinstCurrent, hinstPrevious, lpszCmdLine, nCmdShow) | |||||
HINSTANCE hinstCurrent; | /* handle of current instance | */ | |||
HINSTANCE hinstPrevious; | /* handle of previous instance | */ | |||
LPSTR lpszCmdLine; | /* address of command line | */ | |||
int nCmdShow; | /* show-window type (open/icon) | */ |
The WinMain function is called by the system as the initial entry point for a Windows application.
hinstCurrent
Identifies the current instance of the application.
hinstPrevious
Identifies the previous instance of the application.
lpszCmdLine
Points to a null-terminated string specifying the command line for the application.
nCmdShow
Specifies how the window is to be shown. This parameter can be one of the following values:
Value | Meaning |
SW_HIDE | Hides the window and passes activation to another window. |
SW_MINIMIZE | Minimizes the specified window and activates the top-level window in the system's list. |
SW_RESTORE | Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position (same as SW_SHOWNORMAL). |
SW_SHOW | Activates a window and displays it in its current size and position. |
SW_SHOWMAXIMIZED | Activates a window and displays it as a maximized window. |
SW_SHOWMINIMIZED | Activates a window and displays it as an icon. |
SW_SHOWMINNOACTIVE | Displays a window as an icon. The window that is currently active remains active. |
SW_SHOWNA | Displays a window in its current state. The window that is currently active remains active. |
SW_SHOWNOACTIVATE | Displays a window in its most recent size and position. The window that is currently active remains active. |
SW_SHOWNORMAL | Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position (same as SW_RESTORE). |
The return value is the return value of the PostQuitMessage function if the function is successful. This function returns NULL if it terminates before entering the message loop.
The WinMain function calls the instance-initialization function and, if no other instance of the program is running, the application-initialization function. It then performs a message retrieval-and-dispatch loop that is the top-level control structure for the remainder of the application's execution. The loop is terminated when a WM_QUIT message is received, at which time this function exits the application instance by returning the value passed by the PostQuitMessage function.
The following example uses the WinMain function to initialize the application (if necessary), initialize the instance, and establish a message loop:
int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious,
LPSTR lpszCmdLine, int nCmdShow)
{
MSG msg;
if (hinstPrevious == NULL) /* other instances? */
if (!InitApplication(hinstCurrent)) /* shared items */
return FALSE; /* initialization failed */
/* Perform initializations for this instance. */
if (!InitInstance(hinstCurrent, nCmdShow))
return FALSE;
/* Get and dispatch messages until WM_QUIT message. */
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg); /* translates virtual key codes */
DispatchMessage(&msg); /* dispatches message to window */
}
return ((int) msg.wParam); /* return value of PostQuitMessage */
}
DispatchMessage, GetMessage, PostQuitMessage, TranslateMessage