Home > Back-end >  WinMain parameters for help
WinMain parameters for help

Time:02-06

Just learn WinMain, hInstance namely "handle to the current instance" exactly is what mean

CodePudding user response:

Namely pointer to the current instance

CodePudding user response:

For example, if you perform the same program twice, both hInstance value is different, used to distinguish between the two,
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 the current instance
HINSTANCE hPrevInstance,//handle to the previous instance
LPSTR lpCmdLine,//a pointer to the command line
Int nCmdShow//show the state of the window
);

The Parameters
HInstance
Handle to the current instance of the application. The
HPrevInstance
Handle to the previous instance of the application. For a Win32 - -based application, this parameter is always NULL.
If you need to detect been another instance already exists, create a uniquely named mutex using theCreateMutex function. The CreateMutex will succeed even If the mutex already exists, but theGetLastError function will return ERROR_ALREADY_EXISTS. This are that another instance of your application exists, because it created the mutex first.

LpCmdLine
Pointer to a null - terminated string specifying the command line for the application, excluding the program name. To retrieve the - the command line, use theGetCommandLine function.
NCmdShow
Specifies how the window is to be to. This parameter can be one of the following values: Value a fancy
SW_HIDE Hides the window and activates 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, the system restores it to its the 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 active window remains active.
SW_SHOWNA Displays a window in its current state. The active window remains active.
SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, the system restores it to its the original size and position (same as SW_RESTORE).


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

Few
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 always return a Unicode strings is that lpCmdLine USES the LPSTR data type, not the LPTSTR data type. The GetCommandLine function can be 2 access Unicode strings in the command line, because it USES the LPTSTR data type.

Windows CE: Windows CE does not support the following values for the nCmdShow parameter:

SW_MINIMIZE

SW_RESTORE

SW_SHOWMAXIMIZED

SW_SHOWMINIMIZED

SW_SHOWMINNOACTIVE

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: the Requires version 1.0 or later.
Header: Declared in winbase. H.
The Import Library: the User - defined.

See Also
Windows, the Overview Window Functions provides, CreateMutex DispatchMessage, GetCommandLine, GetMessage, PostQuitMessage, TranslateMessage


  • Related