📄 gadgets.c
字号:
/*-----------------------------------------
GADGETS.C -- Gadgets for a frame window.
(c) Paul Yao, 1996
-----------------------------------------*/
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include "comcthlp.h"
#include "gadgets.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
LRESULT CALLBACK ClientWndProc (HWND, UINT, WPARAM, LPARAM) ;
char szAppName[] = "Gadgets" ;
BOOL bIgnoreSize = FALSE ;
HINSTANCE hInst ;
HWND hwndClient = NULL ;
HWND hwndToolBar = NULL ;
HWND hwndStatusBar = NULL ;
HWND hwndNotify = NULL ;
extern DWORD dwToolBarStyles ;
extern BOOL bStrings ;
extern BOOL bLargeIcons ;
extern BOOL bComboBox ;
extern DWORD dwStatusBarStyles ;
extern int cyToolBar ;
//-------------------------------------------------------------------
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR lpszCmdLine, int cmdShow)
{
HWND hwnd ;
MSG msg ;
WNDCLASSEX wc ;
hInst = hInstance ;
wc.cbSize = sizeof (wc) ;
wc.lpszClassName = szAppName ;
wc.hInstance = hInstance ;
wc.lpfnWndProc = WndProc ;
wc.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wc.hIcon = LoadIcon (hInst, MAKEINTRESOURCE (IDI_APP)) ;
wc.lpszMenuName = "MAIN" ;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.style = 0 ;
wc.cbClsExtra = 0 ;
wc.cbWndExtra = 0 ;
wc.hIconSm = LoadIcon (hInst, MAKEINTRESOURCE (IDI_APP)) ;
RegisterClassEx (&wc) ;
wc.lpszClassName = "ClientWndProc" ;
wc.hInstance = hInstance ;
wc.lpfnWndProc = ClientWndProc ;
wc.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wc.lpszMenuName = NULL ;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1) ;
wc.style = 0 ;
wc.cbClsExtra = 0 ;
wc.cbWndExtra = 0 ;
wc.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ;
RegisterClassEx (&wc) ;
hwnd = CreateWindowEx(0L,
szAppName, szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, cmdShow) ;
UpdateWindow (hwnd) ;
InitCommonControls () ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
//-------------------------------------------------------------------
void MenuCheckMark (HMENU hmenu, int id, BOOL bCheck)
{
int iState ;
iState = (bCheck) ? MF_CHECKED : MF_UNCHECKED ;
CheckMenuItem (hmenu, id, iState) ;
}
//-------------------------------------------------------------------
LRESULT CALLBACK
WndProc (HWND hwnd, UINT mMsg, WPARAM wParam, LPARAM lParam)
{
switch (mMsg)
{
case WM_CREATE :
{
// Create toolbar (source resides in toolbar.c).
hwndToolBar = InitToolBar (hwnd) ;
// Create status bar (source resides in statbar.c).
hwndStatusBar = InitStatusBar (hwnd) ;
// Create client window (contains notify list).
hwndClient = CreateWindowEx (WS_EX_CLIENTEDGE,
"ClientWndProc", NULL,
WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
hwnd, (HMENU) 4, hInst, NULL) ;
return 0 ;
}
case WM_COMMAND :
{
// Toolbar button commands.
if (LOWORD (wParam) < 300)
{
char ach[80] ;
wsprintf (ach, "Got Command (%d)", wParam) ;
MessageBox (hwnd, ach, szAppName, MB_OK) ;
break ;
}
// Menu item commands
switch (LOWORD (wParam))
{
// Toolbar settings
case IDM_STRINGS :
case IDM_LARGEICONS :
case IDM_SMALLICONS :
case IDM_NODIVIDER :
case IDM_WRAPABLE :
case IDM_TOP :
case IDM_BOTTOM :
case IDM_NOMOVEY :
case IDM_NOPARENTALIGN :
case IDM_NORESIZE :
case IDM_ADJUSTABLE :
case IDM_ALTDRAG :
case IDM_TOOLTIPS :
case IDM_COMBOBOX :
DestroyWindow (hwndToolBar) ;
hwndToolBar = RebuildToolBar (hwnd,
LOWORD (wParam)) ;
break ;
// Toolbar messages
case IDM_TB_CHECK :
case IDM_TB_ENABLE :
case IDM_TB_HIDE :
case IDM_TB_INDETERMINATE :
case IDM_TB_PRESS :
case IDM_TB_BUTTONCOUNT :
case IDM_TB_GETROWS :
case IDM_TB_CUSTOMIZE :
ToolBarMessage (hwndToolBar, LOWORD (wParam)) ;
break ;
// Status bar settings
case IDM_STAT_SIZEGRIP :
case IDM_STAT_TOP :
case IDM_STAT_BOTTOM :
case IDM_STAT_NOMOVEY :
case IDM_STAT_NOPARENTALIGN :
case IDM_STAT_NORESIZE :
DestroyWindow (hwndStatusBar) ;
hwndStatusBar = RebuildStatusBar (hwnd,
LOWORD (wParam)) ;
break ;
// Status bar messages
case IDM_ST_GETBORDERS :
case IDM_ST_GETPARTS :
case IDM_ST_SETTEXT :
case IDM_ST_SIMPLE :
StatusBarMessage (hwndStatusBar, LOWORD (wParam)) ;
break ;
// Toggle display of toolbar
case IDM_VIEW_TOOLBAR :
{
RECT r ;
if (hwndToolBar && IsWindowVisible (hwndToolBar))
{
ShowWindow (hwndToolBar, SW_HIDE) ;
}
else
{
ShowWindow (hwndToolBar, SW_SHOW) ;
}
// Resize other windows.
GetClientRect (hwnd, &r) ;
PostMessage (hwnd, WM_SIZE, 0,
MAKELPARAM (r.right, r.bottom)) ;
break;
}
// Toggle display of status bar
case IDM_VIEW_STATUS :
{
RECT r;
if (hwndStatusBar && IsWindowVisible (hwndStatusBar))
{
ShowWindow (hwndStatusBar, SW_HIDE) ;
}
else
{
ShowWindow (hwndStatusBar, SW_SHOW) ;
}
// Resize other windows.
GetClientRect (hwnd, &r) ;
PostMessage (hwnd, WM_SIZE, 0,
MAKELPARAM (r.right, r.bottom)) ;
break;
}
// Toggle display of notifications window.
case IDM_VIEW_NOTIFICATIONS :
hwndNotify = ViewNotificationsToggle (hwndClient) ;
break ;
// Toggle ignore WM_SIZE to show auto-size/auto-move
case IDM_IGNORESIZE :
case IDM_STAT_IGNORESIZE :
{
RECT r ;
bIgnoreSize = !bIgnoreSize ;
if (bIgnoreSize)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -