📄 wndproc.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//
// MODULE: wndproc.cpp
//
// PURPOSE: Contains window procedures for the main application windows.
//
// PLATFORMS: Windows CE
//
// FUNCTIONS:
// MainWndProc() - Message handler for the main application window
// Main_OnCommand() - Processes WM_COMMAND messages
// Main_OnDestroy() - Handles the WM_DESTROY message
// AboutDlgProc() - Message handler for the application's about
// dialog.
//
// COMMENTS:
//
//
#include "stdafx.h"
//----------------------------------------------------------------------------
// Global variables
HWND g_hwndTreeView = 0;
HWND hwndCB;
//----------------------------------------------------------------------------
// Application global variables
HINSTANCE g_hInstance = NULL;
#define DEFBKGDCOLOR (COLOR_WINDOW + 1)
//
// FUNCTION: Main_OnSize(HWND)
//
void Main_OnSize(HWND hwnd, UINT uMsg, WPARAM wParam,LPARAM lParam)
{
RECT rc;
GetClientRect(hwnd, &rc);
MoveWindow(g_hwndTreeView, rc.left, rc.top, rc.right, rc.bottom, TRUE);
}
//
// FUNCTION: AboutDlgProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the About dialog box
//
// PARAMETERS:
// hwnd - window handle of the dialog box
// uMsg - identifier of the message being handled
// wParam - additional info associated with the message
// lParam - additional info associated with the message
//
// RETURN VALUE:
// Except in response to the WM_INITDIALOG message, the dialog box
// procedure should return nonzero if it processes the message, and zero
// if it does not.
//
// COMMENTS:
//
LRESULT CALLBACK AboutDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam,LPARAM lParam)
{
SHINITDLGINFO shidi;
switch(uMsg)
{
case WM_INITDIALOG:
//On Pocket PC devices you normally create all Dialog's as fullscreen dialog's
// with an OK button in the upper corner.
// Create a Done button and size it.
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hwnd;
//initialzes the dialog based on the dwFlags parameter
SHInitDialog(&shidi);
// Should return nonzero to set focus to the first control in the
// dialog, or zero if this routine sets the focus manually.
return (TRUE);
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd, 0);
break;
case IDCANCEL:
EndDialog(hwnd, 0);
break;
}
return (TRUE);
}
return (FALSE);
}
//
// FUNCTION: Main_OnNotify(HWND, int, LPNMHDR)
//
// PURPOSE: Handles any notifications the treeview control spits out.
//
// PARAMETERS:
// hwnd - handle of the window receiving the notification
// idCtl - identifies the control sending the notification
// pnmh - points to a NMHDR struct with more inforamation regarding the
// notification
//
// RETURN VALUE:
// (LRESULT) Dependant on the specific notification. See Below.
//
// COMMENTS:
//
LRESULT Main_OnNotify(HWND hwnd, int idCtl, LPNMHDR pnmh)
{
HTREEITEM hti, htiNext;
TCHAR szDir[MAX_PATH];
switch (pnmh->code)
{
// A directory node has been collapsed. Now we can remove the child items
// from the node.
case TVN_ITEMEXPANDED:
{
LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pnmh;
if (pnmtv->action == TVE_COLLAPSE)
{
//OutputDebugString(TEXT("Item collapsed\r\n"));
// Now actually remove the child items within this directory
hti = TreeView_GetChild(pnmh->hwndFrom, pnmtv->itemNew.hItem);
while (hti)
{
htiNext = TreeView_GetNextSibling(pnmh->hwndFrom, hti);
TreeView_DeleteItem(pnmh->hwndFrom, hti);
hti = htiNext;
}
}
return (FALSE);
}
// A node is expanding or collapsing. We need to update the folder
// images to reflect either a closed or open folder depending on it's
// new state.
case TVN_ITEMEXPANDING:
{
// cast the NMHDR into a treeview notify structure
LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pnmh;
if (pnmtv->action == TVE_COLLAPSE)
{
//OutputDebugString(TEXT("Item collapsing\r\n"));
// Retrieve the image from the current item
pnmtv->itemNew.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
TreeView_GetItem(pnmh->hwndFrom, &(pnmtv->itemNew));
// Set the item's image to the closed folder
pnmtv->itemNew.iImage = IMAGE_CLOSED;
pnmtv->itemNew.iSelectedImage = IMAGE_CLOSED;
TreeView_SetItem(pnmh->hwndFrom, &(pnmtv->itemNew));
}
else
{
//OutputDebugString(TEXT("Item expanding\r\n"));
// Retrieve the image from the current item
pnmtv->itemNew.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
TreeView_GetItem(pnmh->hwndFrom, &(pnmtv->itemNew));
// Set the item's image to the closed folder
pnmtv->itemNew.iImage = IMAGE_OPEN;
pnmtv->itemNew.iSelectedImage = IMAGE_OPEN;
TreeView_SetItem(pnmh->hwndFrom, &(pnmtv->itemNew));
// We need to fill in the subdirectory just expanded
BuildDirectory(pnmtv->hdr.hwndFrom, pnmtv->itemNew, szDir);
GetDirectoryContents(pnmtv->hdr.hwndFrom,szDir,(HTREEITEM)pnmtv->itemNew.hItem);
}
return (FALSE); // return value is ignored
}
//Run the application or show a commandprompt if option is set
case NM_DBLCLK:
{
DWORD dwPos;
TV_HITTESTINFO tvhti;
POINT point;
HWND hwndTV = GetDlgItem(hwnd, IDC_TREEVIEW);
TV_ITEM tvi;
TCHAR szbufW[MAX_PATH];
TCHAR sztempW[MAX_PATH];
TCHAR outPath[MAX_PATH];
szbufW[0] = '\0';
sztempW[0] = '\0';
outPath[0]='\0';
// Find out where the cursor was
dwPos = GetMessagePos();
point.x = LOWORD(dwPos);
point.y = HIWORD(dwPos);
ScreenToClient(hwndTV, &point);
tvhti.pt = point;
tvi.hItem = TreeView_HitTest(hwndTV, &tvhti);
tvi.pszText = szbufW;
tvi.cchTextMax = MAX_PATH;
tvi.mask = TVIF_IMAGE | TVIF_HANDLE | TVIF_TEXT;
TreeView_GetItem(hwndTV, &tvi);
if (tvi.iImage == IMAGE_EXE){
HTREEITEM htv;
htv = tvi.hItem;
_tcsrev(szbufW);
if(_tcsncicmp(szbufW, _T("exe."),4) != 0)
return (0L);
_tcscat(szbufW, _T("\\"));
while (htv = TreeView_GetParent(hwndTV, htv)){
//Construct path
tvi.hItem = htv;
tvi.pszText = sztempW;
tvi.cchTextMax = MAX_PATH;
tvi.mask = TVIF_TEXT;
TreeView_GetItem(hwndTV, &tvi);
_tcsrev(sztempW);
if (_tcscmp(sztempW, _T("\\")) != 0) _tcscat(szbufW, sztempW);
if (szbufW[lstrlen(szbufW)-1] != '\\') _tcscat(szbufW, _T("\\"));
};
_tcsrev(szbufW);
CreateProcess(szbufW, NULL, NULL, NULL, FALSE, 0, NULL, NULL, NULL, NULL);
}
if (IsChoiceFile(tvi.pszText,L"7z"))
{
HTREEITEM htv;
htv = tvi.hItem;
_tcsrev(szbufW);
if(_tcsncicmp(szbufW, _T("z7."),3) != 0)
return (0L);
_tcscat(szbufW, _T("\\")); _tcscat(outPath,_T("\\"));
while (htv = TreeView_GetParent(hwndTV, htv)){
//Construct path
tvi.hItem = htv;
tvi.pszText = sztempW;
tvi.cchTextMax = MAX_PATH;
tvi.mask = TVIF_TEXT;
TreeView_GetItem(hwndTV, &tvi);
_tcsrev(sztempW);
if (_tcscmp(sztempW, _T("\\")) != 0) _tcscat(szbufW, sztempW);
if (szbufW[lstrlen(szbufW)-1] != '\\') _tcscat(szbufW, _T("\\"));
if (_tcscmp(sztempW, _T("\\")) != 0) _tcscat(outPath, sztempW);
if (outPath[lstrlen(outPath)-1] != '\\') _tcscat(outPath, _T("\\"));
};
_tcsrev(szbufW);
_tcsrev(outPath);
SendMessage(hwnd,WM_COMMONDEC,(WPARAM)outPath,(LPARAM)szbufW);
}
return (0L); // Return value is ignored
}
}
return (0L);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -