📄 framewnd.c
字号:
hwndExportBranch = GetDlgItem(hdlg, IDC_EXPORT_BRANCH);
if (hwndExportBranch)
SendMessage(hwndExportBranch, BM_SETCHECK, pszSelectedKey[0] ? BST_CHECKED : BST_UNCHECKED, 0);
hwndExportBranchText = GetDlgItem(hdlg, IDC_EXPORT_BRANCH_TEXT);
if (hwndExportBranchText)
SetWindowText(hwndExportBranchText, pszSelectedKey);
break;
case WM_NOTIFY:
if (((NMHDR *) lParam)->code == CDN_FILEOK)
{
pOfnNotify = (OFNOTIFY *) lParam;
pszSelectedKey = (LPTSTR) pOfnNotify->lpOFN->lCustData;
hwndExportBranch = GetDlgItem(hdlg, IDC_EXPORT_BRANCH);
hwndExportBranchText = GetDlgItem(hdlg, IDC_EXPORT_BRANCH_TEXT);
if (hwndExportBranch && hwndExportBranchText
&& (SendMessage(hwndExportBranch, BM_GETCHECK, 0, 0) == BST_CHECKED))
{
GetWindowText(hwndExportBranchText, pszSelectedKey, _MAX_PATH);
}
else
{
pszSelectedKey[0] = '\0';
}
}
break;
}
return iResult;
}
BOOL ExportRegistryFile(HWND hWnd)
{
OPENFILENAME ofn;
TCHAR ExportKeyPath[_MAX_PATH];
TCHAR Caption[128];
HKEY hKeyRoot;
LPCTSTR pszKeyPath;
/* Figure out which key path we are exporting */
pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot);
RegKeyGetName(ExportKeyPath, sizeof(ExportKeyPath) / sizeof(ExportKeyPath[0]),
hKeyRoot, pszKeyPath);
InitOpenFileName(hWnd, &ofn);
LoadString(hInst, IDS_EXPORT_REG_FILE, Caption, sizeof(Caption)/sizeof(TCHAR));
ofn.lpstrTitle = Caption;
ofn.lCustData = (LPARAM) ExportKeyPath;
ofn.Flags = OFN_ENABLETEMPLATE | OFN_EXPLORER | OFN_ENABLEHOOK;
ofn.lpfnHook = ExportRegistryFile_OFNHookProc;
ofn.lpTemplateName = MAKEINTRESOURCE(IDD_EXPORTRANGE);
if (GetSaveFileName(&ofn)) {
BOOL result;
LPSTR pszExportKeyPath;
#ifdef UNICODE
CHAR buffer[_MAX_PATH];
WideCharToMultiByte(CP_ACP, 0, ExportKeyPath, -1, buffer, sizeof(buffer), NULL, NULL);
pszExportKeyPath = buffer;
#else
pszExportKeyPath = ExportKeyPath;
#endif
result = export_registry_key(ofn.lpstrFile, pszExportKeyPath);
if (!result) {
/*printf("Can't open file \"%s\"\n", ofn.lpstrFile);*/
return FALSE;
}
#if 0
TCHAR filename[MAX_PATH];
filename[0] = '\0';
get_file_name(&s, filename, MAX_PATH);
if (!filename[0]) {
printf("No file name is specified\n%s", usage);
return FALSE;
/*exit(1);*/
}
if (s[0]) {
TCHAR reg_key_name[KEY_MAX_LEN];
get_file_name(&s, reg_key_name, KEY_MAX_LEN);
export_registry_key((CHAR)filename, reg_key_name);
} else {
export_registry_key(filename, NULL);
}
#endif
} else {
CheckCommDlgError(hWnd);
}
return TRUE;
}
BOOL PrintRegistryHive(HWND hWnd, LPTSTR path)
{
#if 1
PRINTDLG pd;
UNREFERENCED_PARAMETER(path);
ZeroMemory(&pd, sizeof(PRINTDLG));
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hWnd;
pd.hDevMode = NULL; /* Don't forget to free or store hDevMode*/
pd.hDevNames = NULL; /* Don't forget to free or store hDevNames*/
pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
pd.nCopies = 1;
pd.nFromPage = 0xFFFF;
pd.nToPage = 0xFFFF;
pd.nMinPage = 1;
pd.nMaxPage = 0xFFFF;
if (PrintDlg(&pd)) {
/* GDI calls to render output. */
DeleteDC(pd.hDC); /* Delete DC when done.*/
}
#else
HRESULT hResult;
PRINTDLGEX pd;
hResult = PrintDlgEx(&pd);
if (hResult == S_OK) {
switch (pd.dwResultAction) {
case PD_RESULT_APPLY:
/*The user clicked the Apply button and later clicked the Cancel button. This indicates that the user wants to apply the changes made in the property sheet, but does not yet want to print. The PRINTDLGEX structure contains the information specified by the user at the time the Apply button was clicked. */
break;
case PD_RESULT_CANCEL:
/*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
break;
case PD_RESULT_PRINT:
/*The user clicked the Print button. The PRINTDLGEX structure contains the information specified by the user. */
break;
default:
break;
}
} else {
switch (hResult) {
case E_OUTOFMEMORY:
/*Insufficient memory. */
break;
case E_INVALIDARG:
/* One or more arguments are invalid. */
break;
case E_POINTER:
/*Invalid pointer. */
break;
case E_HANDLE:
/*Invalid handle. */
break;
case E_FAIL:
/*Unspecified error. */
break;
default:
break;
}
return FALSE;
}
#endif
return TRUE;
}
static void ChooseFavorite(LPCTSTR pszFavorite)
{
HKEY hKey = NULL;
TCHAR szFavoritePath[512];
DWORD cbData, dwType;
if (RegOpenKeyEx(HKEY_CURRENT_USER, s_szFavoritesRegKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
goto done;
cbData = (sizeof(szFavoritePath) / sizeof(szFavoritePath[0])) - 1;
memset(szFavoritePath, 0, sizeof(szFavoritePath));
if (RegQueryValueEx(hKey, pszFavorite, NULL, &dwType, (LPBYTE) szFavoritePath, &cbData) != ERROR_SUCCESS)
goto done;
if (dwType == REG_SZ)
SelectNode(g_pChildWnd->hTreeWnd, szFavoritePath);
done:
if (hKey)
RegCloseKey(hKey);
}
BOOL CopyKeyName(HWND hWnd, HKEY hRootKey, LPCTSTR keyName)
{
BOOL bClipboardOpened = FALSE;
BOOL bSuccess = FALSE;
TCHAR szBuffer[512];
HGLOBAL hGlobal;
LPTSTR s;
if (!OpenClipboard(hWnd))
goto done;
bClipboardOpened = TRUE;
if (!EmptyClipboard())
goto done;
if (!RegKeyGetName(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), hRootKey, keyName))
goto done;
hGlobal = GlobalAlloc(GMEM_MOVEABLE, (_tcslen(szBuffer) + 1) * sizeof(TCHAR));
if (!hGlobal)
goto done;
s = GlobalLock(hGlobal);
_tcscpy(s, szBuffer);
GlobalUnlock(hGlobal);
#ifdef UNICODE
SetClipboardData(CF_UNICODETEXT, hGlobal);
#else
SetClipboardData(CF_TEXT, hGlobal);
#endif
bSuccess = TRUE;
done:
if (bClipboardOpened)
CloseClipboard();
return bSuccess;
}
static BOOL CreateNewValue(HKEY hRootKey, LPCTSTR pszKeyPath, DWORD dwType)
{
TCHAR szNewValueFormat[128];
TCHAR szNewValue[128];
int iIndex = 1;
BYTE data[128];
DWORD dwExistingType, cbData;
LONG lResult;
HKEY hKey;
LVFINDINFO lvfi;
if (RegOpenKey(hRootKey, pszKeyPath, &hKey) != ERROR_SUCCESS)
return FALSE;
LoadString(hInst, IDS_NEW_VALUE, szNewValueFormat, sizeof(szNewValueFormat)
/ sizeof(szNewValueFormat[0]));
do
{
_sntprintf(szNewValue, sizeof(szNewValue) / sizeof(szNewValue[0]),
szNewValueFormat, iIndex++);
cbData = sizeof(data);
lResult = RegQueryValueEx(hKey, szNewValue, NULL, &dwExistingType, data, &cbData);
}
while(lResult == ERROR_SUCCESS);
switch(dwType) {
case REG_DWORD:
cbData = sizeof(DWORD);
break;
case REG_SZ:
case REG_EXPAND_SZ:
cbData = sizeof(TCHAR);
break;
case REG_MULTI_SZ:
cbData = sizeof(TCHAR) * 2;
break;
case REG_QWORD:
cbData = sizeof(DWORD) * 2;
break;
default:
cbData = 0;
break;
}
memset(data, 0, cbData);
lResult = RegSetValueEx(hKey, szNewValue, 0, dwType, data, cbData);
if (lResult != ERROR_SUCCESS)
return FALSE;
RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath);
/* locate the newly added value, and get ready to rename it */
memset(&lvfi, 0, sizeof(lvfi));
lvfi.flags = LVFI_STRING;
lvfi.psz = szNewValue;
iIndex = ListView_FindItem(g_pChildWnd->hListWnd, -1, &lvfi);
if (iIndex >= 0)
(void)ListView_EditLabel(g_pChildWnd->hListWnd, iIndex);
return TRUE;
}
static HRESULT
InitializeRemoteRegistryPicker(OUT IDsObjectPicker **pDsObjectPicker)
{
HRESULT hRet;
*pDsObjectPicker = NULL;
hRet = CoCreateInstance(&CLSID_DsObjectPicker,
NULL,
CLSCTX_INPROC_SERVER,
&IID_IDsObjectPicker,
(LPVOID*)pDsObjectPicker);
if (SUCCEEDED(hRet))
{
DSOP_INIT_INFO InitInfo;
static DSOP_SCOPE_INIT_INFO Scopes[] =
{
{
sizeof(DSOP_SCOPE_INIT_INFO),
DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE | DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE |
DSOP_SCOPE_TYPE_GLOBAL_CATALOG | DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN |
DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN | DSOP_SCOPE_TYPE_WORKGROUP |
DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN | DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN,
0,
{
{
DSOP_FILTER_COMPUTERS,
0,
0
},
DSOP_DOWNLEVEL_FILTER_COMPUTERS
},
NULL,
NULL,
S_OK
},
};
InitInfo.cbSize = sizeof(InitInfo);
InitInfo.pwzTargetComputer = NULL;
InitInfo.cDsScopeInfos = sizeof(Scopes) / sizeof(Scopes[0]);
InitInfo.aDsScopeInfos = Scopes;
InitInfo.flOptions = 0;
InitInfo.cAttributesToFetch = 0;
InitInfo.apwzAttributeNames = NULL;
hRet = (*pDsObjectPicker)->lpVtbl->Initialize(*pDsObjectPicker,
&InitInfo);
if (FAILED(hRet))
{
/* delete the object picker in case initialization failed! */
(*pDsObjectPicker)->lpVtbl->Release(*pDsObjectPicker);
}
}
return hRet;
}
static HRESULT
InvokeRemoteRegistryPickerDialog(IN IDsObjectPicker *pDsObjectPicker,
IN HWND hwndParent OPTIONAL,
OUT LPTSTR lpBuffer,
IN UINT uSize)
{
IDataObject *pdo = NULL;
HRESULT hRet;
hRet = pDsObjectPicker->lpVtbl->InvokeDialog(pDsObjectPicker,
hwndParent,
&pdo);
if (hRet == S_OK)
{
STGMEDIUM stm;
FORMATETC fe;
fe.cfFormat = (CLIPFORMAT) RegisterClipboardFormat(CFSTR_DSOP_DS_SELECTION_LIST);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -