📄 initialization.c
字号:
//
// COMMENTS:
//
int exitInstance (MSG* pmsg)
{
return pmsg->wParam ;
}
//
// BOOL registerWindowClasses (HINSTANCE hinst, UINT resPoolID)
//
// hinst Application module (instance) handle
// resPoolID Resource identifier
//
// PURPOSE: Register all application-specific window classes
//
// COMMENTS:
//
// The specified resPoolID parameter is the UINT resource identifier
// used to locate the application's main frame window class name,
// the menu used on the main frame window, the large and small icons
// for the main frame window.
static BOOL
registerWindowClasses (HINSTANCE hinst, UINT resPoolID)
{
TCHAR ClassName [MAX_RESOURCESTRING + 1] ;
WNDCLASSEX wcex ;
VERIFY (LoadString (hinst, resPoolID, ClassName, DIM(ClassName))) ;
/********************************************************************/
/* Register one class for the main application window and a second */
/* for the disk windows. */
/********************************************************************/
wcex.cbSize = sizeof (WNDCLASSEX) ;
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ;
wcex.lpfnWndProc = mainFrameWndProc ;
wcex.cbClsExtra = 0 ;
wcex.cbWndExtra = 0 ;
wcex.hInstance = hinst ;
wcex.hIcon = LoadIcon (hinst, MAKEINTRESOURCE (resPoolID)) ;
wcex.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wcex.hbrBackground = (HBRUSH) (COLOR_WINDOW+1) ;
wcex.lpszMenuName = MAKEINTRESOURCE (resPoolID) ;
wcex.lpszClassName = ClassName ;
wcex.hIconSm = LoadImage (hinst,
MAKEINTRESOURCE (resPoolID),
IMAGE_ICON,
GetSystemMetrics (SM_CXSMICON),
GetSystemMetrics (SM_CYSMICON),
LR_SHARED) ;
// Register the window class and abort the initialization upon failure.
if (!internalRegisterClass (&wcex))
return FALSE ;
/******************************/
/* Now define the disk class. */
/******************************/
/********************************************/
/* Fetch the name of the disk window class. */
/********************************************/
wcex.cbSize = sizeof (WNDCLASSEX) ;
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_SAVEBITS ;
wcex.lpfnWndProc = diskWndProc ;
wcex.cbClsExtra = 0 ;
wcex.cbWndExtra = UGW_DWMAXUSED ;
wcex.hInstance = hinst ;
wcex.hIcon = LoadIcon (hinst, MAKEINTRESOURCE (resPoolID)) ;
wcex.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wcex.hbrBackground = GetStockObject (NULL_BRUSH) ;
wcex.lpszMenuName = NULL ;
wcex.lpszClassName = DiskClass ;
wcex.hIconSm = NULL ;
// Register the window class and return success/failure status
return internalRegisterClass (&wcex) ;
}
//
// HWND createMainFrameWindow (HINSTANCE hinst, int nCmdShow)
//
// hinst Application module (instance) handle
// nCmdShow Initial show window state
//
// PURPOSE: Create the application's main frame window
// and show the window as requested
//
// COMMENTS:
//
static HWND
createMainFrameWindow (HINSTANCE hinst, int nCmdShow)
{
HWND hwnd ;
TCHAR ClassName [MAX_RESOURCESTRING + 1] ;
TCHAR Title [MAX_RESOURCESTRING + 1] ;
// Create the main frame window
VERIFY (LoadString (hinst, IDR_MAINFRAME, ClassName, DIM (ClassName))) ;
VERIFY (LoadString (hinst, IDS_APP_TITLE, Title, DIM (Title))) ;
hwnd =
CreateWindowEx (0, // Extended window styles
ClassName, // Address of registered class name
Title, // Address of window name
WS_OVERLAPPEDWINDOW|// Window style
WS_CLIPCHILDREN,
CW_USEDEFAULT, // Horizontal position of window
0, // Vertical position of window
CW_USEDEFAULT, // Window width
0, // Window height
NULL, // Handle of parent or owner window
NULL, // Handle of menu
hinst, // Handle of application instance
NULL) ; // Address of window-creation data
ASSERT (NULL != hwnd) ;
if (!hwnd)
return NULL ;
ShowWindow (hwnd, nCmdShow) ;
UpdateWindow (hwnd) ;
return hwnd ;
}
//
// BOOL internalRegisterClass (const LPWNDCLASSEX lpwcex)
//
// lpwcex Pointer to WNDCLASSEX structure
//
// PURPOSE: Registers the window class using RegisterClassEx
// if it is available. If not, registers the class
// using RegisterClass.
//
// COMMENTS: RegisterClassEx was introduced in Windows 95 and
// Windows NT 3.51. An application must register its
// window classes using RegisterClassEx in order to
// specify the small icons which should be used for
// the application.
//
ATOM
internalRegisterClass (const LPWNDCLASSEX lpwcex)
{
WNDCLASS wc ;
// Get the module handle of the 32-bit USER DLL
HANDLE hModule = GetModuleHandle (TEXT("USER32")) ;
if (NULL != hModule) {
// If we're running on a Win32 version supporting RegisterClassEx
// get the address of the function so we can call it
#if defined (UNICODE)
REGISTERCLASSEXPROC proc =
(REGISTERCLASSEXPROC) GetProcAddress (hModule, "RegisterClassExW") ;
#else
REGISTERCLASSEXPROC proc =
(REGISTERCLASSEXPROC) GetProcAddress (hModule, "RegisterClassExA") ;
#endif
if (NULL != proc)
// RegisterClassEx exists...
// return RegisterClassEx (&wcex) ;
return (*proc) (lpwcex) ;
}
// Convert the WNDCLASSEX structure to a WNDCLASS structure
wc.style = lpwcex->style ;
wc.lpfnWndProc = lpwcex->lpfnWndProc ;
wc.cbClsExtra = lpwcex->cbClsExtra ;
wc.cbWndExtra = lpwcex->cbWndExtra ;
wc.hInstance = lpwcex->hInstance ;
wc.hIcon = lpwcex->hIcon ;
wc.hCursor = lpwcex->hCursor ;
wc.hbrBackground = lpwcex->hbrBackground ;
wc.lpszMenuName = lpwcex->lpszMenuName ;
wc.lpszClassName = lpwcex->lpszClassName ;
return RegisterClass (&wc) ;
}
/********************************************************/
/* Create all the child windows representing the disks. */
/********************************************************/
BOOL
mainFrame_CreateDiskWindows (HWND hwndParent)
{
HINSTANCE hInstance ;
HWND hwndChild ;
int i ;
hInstance = GetWindowInstance (hwndParent) ;
/****************************/
/* Create the disk windows. */
/****************************/
for (i = NUMDISKS; i > 0; i--) {
hwndChild = CreateWindow (
DiskClass, // Class of the window to create
NULL, // Window caption text
WS_CHILD | WS_VISIBLE,// Window styles
0, 0, 0, 0, // No initial size
hwndParent, // Parent window handle
(HMENU) i, // Child window ID
hInstance, // Instance of module owning window
NULL) ; // Ptr to user-defined parameters
/****************************************************/
/* Insure that the window was successfully created. */
/****************************************************/
if (!hwndChild)
return FALSE ;
}
return TRUE ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -