📄 freclien.cpp
字号:
Modifies: ...
Returns: LRESULT
Standard Windows WindowProc return value.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
LRESULT CMainWindow::WindowProc(
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
LRESULT lResult = FALSE;
switch (uMsg)
{
case WM_CREATE:
break;
case WM_MEASUREITEM:
// Get setup for painting text in this window.
{
LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam;
lpmis->itemHeight = m_tm.tmHeight + m_tm.tmExternalLeading;
lpmis->itemWidth = m_wWidth;
lResult = TRUE;
}
case WM_SIZE:
// Handle a resize of this window.
m_wWidth = LOWORD(lParam);
m_wHeight = HIWORD(lParam);
// Handle a resize of this window.
// Restart the ball from upper left, clear window.
m_pGuiBall->Restart();
break;
case WM_TIMER:
// This is our timed attempt to continuously paint the moving ball.
// It doesn't move it. Other non-GUI threads move the virtual ball.
m_pGuiBall->PaintBall();
break;
case WM_COMMAND:
// Dispatch and handle any Menu command messages received.
lResult = DoMenu(wParam, lParam);
break;
case WM_CHAR:
if (wParam == 0x1b)
{
// Exit this app if user hits ESC key.
PostMessage(m_hWnd,WM_CLOSE,0,0);
break;
}
case WM_LBUTTONUP:
case WM_PAINT:
// If something major happened or user clicks or hits key then
// repaint the whole window.
m_pGuiBall->PaintWin();
break;
case WM_CLOSE:
// The user selected Close on the main window's System menu
// or Exit on the File menu.
case WM_QUIT:
// If the app is being quit then close any associated help windows.
// ::WinHelp(m_hWnd, m_szHelpFile, HELP_QUIT, 0);
default:
// Defer all messages NOT handled here to the Default Window Proc.
lResult = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
break;
}
return(lResult);
}
/*F+F++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: UnicodeOk
Summary: Checks if the platform will handle unicode versions of
Win32 string API calls.
Args: void
Returns: BOOL
TRUE if unicode support; FALSE if not.
------------------------------------------------------------------------F-F*/
BOOL UnicodeOk(void)
{
BOOL bOk = TRUE;
TCHAR szUserName[MAX_STRING_LENGTH];
DWORD dwSize = MAX_STRING_LENGTH;
if (!GetUserName(szUserName, &dwSize))
bOk = ERROR_CALL_NOT_IMPLEMENTED == GetLastError() ? FALSE : TRUE;
return bOk;
}
/*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
Function: InitApplication
Summary: Initializes the application and registers its main window
class. InitApplication is called only once (in WinMain).
Args: HINSTANCE hInstance)
Handle to the first instance of the application.
Returns: BOOL.
TRUE if success.
FALSE if fail.
F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/
BOOL InitApplication(
HINSTANCE hInstance)
{
BOOL bOK;
// The window class for all instances of the main frame window.
WNDCLASSEX wcf;
// Assign the appropriate values for this main frame window class.
wcf.cbSize = sizeof(WNDCLASSEX);
wcf.style = CS_HREDRAW | CS_VREDRAW; // Class style(s).
wcf.lpfnWndProc = &WindowProc; // Global Window Procedure for
// all windows of this class.
wcf.cbClsExtra = 0; // No per-class extra data.
wcf.cbWndExtra = 0; // No per-window extra data.
wcf.hInstance = hInstance; // Owner of this class.
wcf.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // Default color.
wcf.lpszMenuName = TEXT(MAIN_WINDOW_CLASS_MENU_STR); // Menu name from .RC.
wcf.lpszClassName = TEXT(MAIN_WINDOW_CLASS_NAME_STR); // Class name from .RC.
wcf.hCursor = LoadCursor(NULL, IDC_ARROW); // Cursor.
wcf.hIcon = LoadIcon( // Icon name from .RC.
hInstance,
TEXT("AppIcon"));
wcf.hIconSm = (HICON)LoadImage( // Load small icon.
hInstance,
TEXT("AppIcon"),
IMAGE_ICON,
16, 16,
0);
// Register the window class and return FALSE if unsuccesful.
bOK = RegisterClassEx(&wcf);
if (!bOK)
{
// If RegisterClassEx() didn't work then try RegisterClass().
bOK = RegisterClass((LPWNDCLASS)&wcf.style);
}
return (bOK);
}
/*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
Function: WinMain
Summary: The Windows main entry point function for this application.
Initializes the application, the OLE Libraries, and starts
the main application message loop.
Args: HINSTANCE hInstance,
Instance handle; a new one for each invocation of this app.
HINSTANCE hPrevInstance,
Instance handle of the previous instance. NULL in Win32.
LPSTR lpCmdLine,
Windows passes a pointer to the application's
invocation command line.
int nCmdShow)
Bits telling the show state of the application.
Returns: int
msg.wParam (upon exit of message loop).
FALSE if this instance couldn't initialize and run.
F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/
extern "C" int PASCAL WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CMainWindow* pWin = NULL;
MSG msg;
HACCEL hAccel;
int iRun = FALSE;
// If we were compiled for UNICODE and the platform seems OK with this
// then proceed. Else we error and exit the app.
if (UnicodeOk())
{
// Call to initialize the OLE COM Library. Use the OLE SUCCEEDED macro
// to detect success. If fail then exit app with error message.
// Tell COM that this client process and all subordinate threads
// will live in a multi-threaded world. This means that all subsequent
// COM objects created and functioned by this client must be coded
// to be thread-safe. This is where we tell COM that we are using
// the "Free-threading" model (rather than the default Apartment Model).
if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
{
// If we succeeded in initializing the COM Library we proceed to
// initialize the application. If we can't init the application
// then we signal shut down with an error message exit.
iRun = InitApplication(hInstance);
if (iRun)
{
// Assume we'll set iRun to TRUE when initialization is done.
iRun = FALSE;
// We are still go for running so we try to create a nifty new
// CMainWindow object for this app instance.
pWin = new CMainWindow;
if (NULL != pWin)
{
// Now we initialize an instance of the new CMainWindow.
// This includes creating the main window. Note: if
// InitInstance fails then it would have already deleted
// pWin so we wouldn't need to delete it here.
if (pWin->InitInstance(hInstance, nCmdShow))
{
// Load the keyboard accelerators from the resources.
hAccel = LoadAccelerators(hInstance, TEXT("AppAccel"));
if (NULL != hAccel)
{
// Signal App Initialization is successfully done.
iRun = TRUE;
}
}
}
}
if (iRun)
{
// If we initialized the app instance properly then we are still
// go for running. We then start up the main message pump for
// the application.
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(pWin->GetHwnd(), hAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// We also ask COM to unload any unused COM Servers, including our
// friend, FRESERVE.
CoFreeUnusedLibraries();
// We'll pass to Windows the reason why we exited the message loop.
iRun = msg.wParam;
}
else
{
// We failed to initialize the application--issue an error
// messagebox.
TCHAR szMsg[MAX_STRING_LENGTH];
// Load the error message string from the resources.
if (LoadString(
hInstance,
IDS_APPINITFAILED,
szMsg,
MAX_STRING_LENGTH))
{
// Put up error message box saying that application couldn't be
// initialized. Parent window is desktop (ie, NULL).
MessageBox(
NULL,
szMsg,
TEXT(ERROR_TITLE_STR),
MB_OK | MB_ICONEXCLAMATION);
}
delete pWin;
}
// We're exiting this app (either normally or by init failure) so
// shut down the OLE COM Library.
CoUninitialize();
}
else
{
// We failed to Initialize the OLE COM Library.
TCHAR szMsg[MAX_STRING_LENGTH];
// Load the error message string from the resources.
if (LoadString(
hInstance,
IDS_OLEINITFAILED,
szMsg,
MAX_STRING_LENGTH))
{
// Put up error message box saying that OLE COM Library
// couldn't be initialized. Parent window is desktop (ie, NULL).
// And exit the failed application.
MessageBox(
NULL,
szMsg,
TEXT(ERROR_TITLE_STR),
MB_OK | MB_ICONEXCLAMATION);
}
}
}
else
{
// If we were compiled for UNICODE but the platform has problems with
// this then indicate an error and exit the app immediately.
CHAR szMsg[MAX_STRING_LENGTH];
if (LoadStringA(
hInstance,
IDS_NOUNICODE,
szMsg,
MAX_STRING_LENGTH))
{
MessageBoxA(
NULL,
szMsg,
ERROR_TITLE_STR,
MB_OK | MB_ICONEXCLAMATION);
}
}
return iRun;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -