please dont rip this site Prev Next

WinMain info  Overview  Group

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,

// pointer to command line

    int nCmdShow 

// show state of window



Identifies the current instance of the application.
Identifies the previous instance of the application. For a Win32-based application, this parameter is always NULL. If you need to detect whether another instance already exists, create a uniquely named mutex using the CreateMutex function. CreateMutex will succeed even if the mutex already exists, but the GetLastError function will return ERROR_ALREADY_EXISTS. This indicates that another instance of your application exists, because it created the mutex first.
Points to a null-terminated string specifying the command line for the application, excluding the program name. To retrieve the entire command line, use the GetCommandLine function.
Specifies how the window is to be shown. This parameter can be one of the following values:




Hides the window and activates another window.


Minimizes the specified window and activates the top-level window in the systemís list.


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).


Activates a window and displays it in its current size and position.


Activates a window and displays it as a maximized window.


Activates a window and displays it as an icon.


Displays a window as an icon. The active window remains active.


Displays a window in its current state. The active window remains active.


Displays a window in its most recent size and position. The active window remains active.


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).

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.


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.

See Also

CreateMutex, DispatchMessage, GetCommandLine, GetMessage, PostQuitMessage, TranslateMessage

file: /Techref/os/win/api/win32/func/src/f91_17.htm, 7KB, , updated: 2000/4/7 12:19, local time: 2022/5/26 13:57,

 ©2022 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF=""> WinMain</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2022 contributors:
o List host: MIT, Site host, Top posters @20220526
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!