📄 winmain.cpp
字号:
/**
* WinMain.cpp Copyright _ 2001 Li Zhaoming. All rights reserved.
* Calls initialization functions and processes the message loop
* PLATFORMS: Windows 95/98, Me, 2000
*/
#include "stdafx.h"
#include "resource.h"
// Global instance.
HINSTANCE g_hinstance;
// Toggle full screen mode on or off.
BOOL g_bFullScreen = false;
// String buffer.
char szAppName[20]; // The name of this application
char szTitle[50]; // The title bar text
char szOpenPath[MAX_PATH];
/**
* calls initialization function, processes message loop
*
* PARAMETERS:
* hInstance - The handle to the instance of this application that
* is currently being executed.
*
* hPrevInstance - This parameter is always NULL in Win32
* applications.
*
* lpCmdLine - A pointer to a null terminated string specifying the
* command line of the application.
*
* nCmdShow - Specifies how the main window is to be diplayed.
*
* RETURN VALUE:
* If the function terminates before entering the message loop,
* return FALSE.
* Otherwise, return the WPARAM value sent by the WM_QUIT message.
*
* COMMENTS:
* Windows recognizes this function by name as the initial entry point
* for the program. This function calls the initialization routine.
* It then executes a message retrieval and dispatch loop that is the
* top-level control structure for the remainder of 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 PostQuitMessage().
*
* If this function must abort before entering the message loop, it
* returns the conventional value NULL.
*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
// Initialize application by setting up the main window.
if (!initApplication(hInstance, nCmdShow))
{
return FALSE; // Exits if unable to initialize
}
hAccelTable = LoadAccelerators(hInstance, szAppName);
// Acquire and dispatch messages until a WM_QUIT message is received.
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator (msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg); // Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
}
return msg.wParam; // Returns the value from PostQuitMessage
}
/**
* Initializes window data and registers window class.
*
* PARAMETERS:
* hInstance - The handle to the instance of this application that
* is currently being executed.
* nCmdShow - Specifies how the main window is to be displayed.
*
* RETURN VALUE:
* TRUE - Success
* FALSE - Initialization failed
*
* COMMENTS:
* This function is called at application initialization time. It
* performs initialization tasks for the current application instance.
* Unlike Win16, in Win32, each instance of an application must register
* window classes.
*
* In this function, we initialize a window class by filling out a data
* structure of type WNDCLASS and calling the Windows RegisterClass()
* function. Then we create the main window and show it.
*/
BOOL initApplication(HINSTANCE hInstance, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd; // Main window handle.
// Load the application name and description strings.
LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
LoadString(hInstance, IDS_TITLE, szTitle, sizeof(szTitle));
// Save the instance handle in static variable, which will be used in
// many subsequence calls from this application to Windows.
g_hinstance = hInstance; // Store instance handle in our global variable
// Fill in window class structure with parameters that describe the
// main window.
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW; // Class style(s).
wc.lpfnWndProc = (WNDPROC)WndProc; // Window Procedure
wc.cbClsExtra = 0; // No per-class extra data.
wc.cbWndExtra = 0; // No per-window extra data.
wc.hInstance = hInstance; // Owner of this class
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON)); // Icon name from .RC
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Cursor
wc.hbrBackground= NULL; // No background Brush here, prevent blinking of toolbar.
wc.lpszMenuName = szAppName; // Menu name from .RC
wc.lpszClassName= szAppName; // Name to register as
wc.hIconSm = LoadIcon(wc.hInstance, (LPCTSTR) IDI_APPICON); // Load small icon image
// Register the window class and return FALSE if unsuccesful.
if (!RegisterClassEx(&wc))
{
// Assume we are running on NT where RegisterClassEx() is
// not implemented, so let's try calling RegisterClass().
if (!RegisterClass((LPWNDCLASS)&wc.style))
return FALSE;
}
// Create a main window for this application instance.
hwnd = CreateWindow(szAppName, // See RegisterClass() call
szTitle, // Text for window title bar
WS_OVERLAPPEDWINDOW,// Window style
CW_USEDEFAULT, 0, // Use default positioning
CW_USEDEFAULT, 0, // Use default size
NULL, // Overlapped has no parent
NULL, // Use the window class menu
hInstance, // This instance owns this window
NULL); // Don't need data in WM_CREATE
// If window could not be created, return "failure"
if (!hwnd) return FALSE;
// Make the window visible; update its client area; and return "success"
ShowWindow(hwnd, nCmdShow); // Show the window
UpdateWindow(hwnd); // Sends WM_PAINT message
return TRUE; // We succeeded...
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -