📄 mainwnd.c
字号:
if (TreeView_HitTest(Info->hTreeView, &HitTest))
(void)TreeView_SelectItem(Info->hTreeView, HitTest.hItem);
}
}
break;
case TTN_GETDISPINFO:
{
LPTOOLTIPTEXT lpttt;
UINT idButton;
lpttt = (LPTOOLTIPTEXT)lParam;
idButton = (UINT)lpttt->hdr.idFrom;
switch (idButton)
{
case IDC_PROP:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_PROP);
break;
case IDC_REFRESH:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_REFRESH);
break;
case IDC_PROGHELP:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_HELP);
break;
case IDC_EXIT:
lpttt->lpszText = MAKEINTRESOURCE(IDS_TOOLTIP_EXIT);
break;
}
}
break;
}
}
static VOID
MainWndCommand(PMAIN_WND_INFO Info,
WORD CmdId,
HWND hControl)
{
UNREFERENCED_PARAMETER(hControl);
switch (CmdId)
{
case IDC_PROP:
{
HTREEITEM hSelected = TreeView_GetSelection(Info->hTreeView);
OpenPropSheet(Info->hTreeView,
hSelected);
}
break;
case IDC_REFRESH:
{
HANDLE DevEnumThread;
SendMessage(Info->hTool,
TB_SETSTATE,
IDC_PROP,
(LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
EnableMenuItem(GetMenu(Info->hMainWnd), IDC_PROP, MF_GRAYED);
EnableMenuItem(Info->hShortcutMenu, IDC_PROP, MF_GRAYED);
/* create seperate thread to emum devices */
DevEnumThread = CreateThread(NULL,
0,
DeviceEnumThread,
&Info->hTreeView,
0,
NULL);
if (!DevEnumThread)
{
DisplayString(_T("Failed to enumerate devices"));
break;
}
CloseHandle(DevEnumThread);
}
break;
case IDC_PROGHELP:
{
DisplayString(_T("Help is not yet implemented\n"));
SetFocus(Info->hTreeView);
}
break;
case IDC_EXIT:
{
PostMessage(Info->hMainWnd,
WM_CLOSE,
0,
0);
}
break;
case IDC_ABOUT:
{
DialogBox(hInstance,
MAKEINTRESOURCE(IDD_ABOUTBOX),
Info->hMainWnd,
(DLGPROC)AboutDialogProc);
SetFocus(Info->hTreeView);
}
break;
}
}
static VOID CALLBACK
MainWndResize(PMAIN_WND_INFO Info,
WORD cx,
WORD cy)
{
RECT rcClient, rcTool, rcStatus;
int lvHeight, iToolHeight, iStatusHeight;
/* Size toolbar and get height */
SendMessage(Info->hTool, TB_AUTOSIZE, 0, 0);
GetWindowRect(Info->hTool, &rcTool);
iToolHeight = rcTool.bottom - rcTool.top;
/* Size status bar and get height */
SendMessage(Info->hStatus, WM_SIZE, 0, 0);
GetWindowRect(Info->hStatus, &rcStatus);
iStatusHeight = rcStatus.bottom - rcStatus.top;
/* Calculate remaining height and size list view */
GetClientRect(Info->hMainWnd, &rcClient);
lvHeight = rcClient.bottom - iToolHeight - iStatusHeight;
SetWindowPos(Info->hTreeView,
NULL,
0,
iToolHeight,
rcClient.right,
lvHeight,
SWP_NOZORDER);
}
static LRESULT CALLBACK
MainWndProc(HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
PMAIN_WND_INFO Info;
LRESULT Ret = 0;
/* Get the window context */
Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwnd,
GWLP_USERDATA);
if (Info == NULL && msg != WM_CREATE)
{
goto HandleDefaultMessage;
}
switch(msg)
{
case WM_CREATE:
{
Info = (PMAIN_WND_INFO)(((LPCREATESTRUCT)lParam)->lpCreateParams);
/* Initialize the main window context */
Info->hMainWnd = hwnd;
SetWindowLongPtr(hwnd,
GWLP_USERDATA,
(LONG_PTR)Info);
if (!InitMainWnd(Info))
SendMessage(hwnd, WM_CLOSE, 0, 0);
/* Show the window */
ShowWindow(hwnd,
Info->nCmdShow);
}
break;
case WM_SIZE:
{
MainWndResize(Info,
LOWORD(lParam),
HIWORD(lParam));
}
break;
case WM_NOTIFY:
{
OnNotify(Info, lParam);
}
break;
case WM_CONTEXTMENU:
{
OnContext(Info, lParam);
}
break;
case WM_COMMAND:
{
MainWndCommand(Info,
LOWORD(wParam),
(HWND)lParam);
goto HandleDefaultMessage;
}
case WM_MENUSELECT:
{
if (Info->hStatus != NULL)
{
if (!MainWndMenuHint(Info,
LOWORD(wParam),
MainMenuHintTable,
sizeof(MainMenuHintTable) / sizeof(MainMenuHintTable[0]),
IDS_HINT_BLANK))
{
MainWndMenuHint(Info,
LOWORD(wParam),
SystemMenuHintTable,
sizeof(SystemMenuHintTable) / sizeof(SystemMenuHintTable[0]),
IDS_HINT_BLANK);
}
}
}
break;
case WM_ENTERMENULOOP:
{
Info->InMenuLoop = TRUE;
UpdateMainStatusBar(Info);
break;
}
case WM_EXITMENULOOP:
{
Info->InMenuLoop = FALSE;
UpdateMainStatusBar(Info);
break;
}
case WM_CLOSE:
{
FreeDeviceStrings(Info->hTreeView);
DestroyMenu(Info->hShortcutMenu);
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
{
HeapFree(ProcessHeap,
0,
Info);
SetWindowLongPtr(hwnd,
GWLP_USERDATA,
0);
/* Break the message queue loop */
PostQuitMessage(0);
}
break;
default:
{
HandleDefaultMessage:
Ret = DefWindowProc(hwnd,
msg,
wParam,
lParam);
}
break;
}
return Ret;
}
HWND
CreateMainWindow(LPCTSTR lpCaption,
int nCmdShow)
{
PMAIN_WND_INFO Info;
HWND hMainWnd = NULL;
Info = (PMAIN_WND_INFO)HeapAlloc(ProcessHeap,
HEAP_ZERO_MEMORY,
sizeof(MAIN_WND_INFO));
if (Info != NULL)
{
Info->nCmdShow = nCmdShow;
hMainWnd = CreateWindowEx(WS_EX_WINDOWEDGE,
szMainWndClass,
lpCaption,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
CW_USEDEFAULT,
CW_USEDEFAULT,
600,
450,
NULL,
NULL,
hInstance,
Info);
if (hMainWnd == NULL)
{
GetError();
HeapFree(ProcessHeap,
0,
Info);
}
}
return hMainWnd;
}
BOOL
InitMainWindowImpl(VOID)
{
WNDCLASSEX wc = {0};
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = MainWndProc;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance,
MAKEINTRESOURCE(IDI_MAIN_ICON));
wc.hCursor = LoadCursor(NULL,
IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
wc.lpszClassName = szMainWndClass;
wc.hIconSm = (HICON)LoadImage(hInstance,
MAKEINTRESOURCE(IDI_MAIN_ICON),
IMAGE_ICON,
16,
16,
LR_SHARED);
return RegisterClassEx(&wc) != (ATOM)0;
}
VOID
UninitMainWindowImpl(VOID)
{
UnregisterClass(szMainWndClass,
hInstance);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -