📄 main.c
字号:
// TEXT ("Software\\n2"), 0,
// KEY_SET_VALUE, &hKeyN2);
// if(rc != ERROR_SUCCESS)
// {
// MessageBox (NULL, TEXT("RegOpenKeyEx Failed"),
// TEXT("Key n2 not opened"), MB_OK);
// return FALSE;
// }
// //set a name and value under the open key
// rc = RegSetValueEx (hKeyN2, TEXT("OneDWORD"), 0,
// REG_DWORD , (LPBYTE)&dwRegVal,
// sizeof(dwRegVal));
// if (rc != ERROR_SUCCESS)
// {
// MessageBox (NULL, TEXT("RegSetValueEx Failed"),
// TEXT("Couldn't delete value"), MB_OK);
// }
// else
// {
// MessageBox (NULL, TEXT("Value OneDWORD Set"),
// TEXT("Single DWORD Registered"), MB_OK);
// }
// //always clean up after ourselves
// RegCloseKey( hKeyN2 );
}
break;
case IDD_REFRESH:
break;
}
}
//********************************************************************************
// FUNCTION: Main_OnNotify(HWND, int, LPNMHDR) WM_NOTIFY
//
// 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 h_wnd, int idCtl, LPNMHDR pnmh)
{
static char bIs_TVN_ITEMEXPANDING = FALSE;
static char bIs_TVN_SELCHANGED = FALSE;
switch (pnmh->code)
{
// 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:
{
LPNM_TREEVIEW pnmtv;
if (bIs_TVN_ITEMEXPANDING == TRUE)
return 0;
// cast the NMHDR into a treeview notify structure
pnmtv = (LPNM_TREEVIEW) pnmh;
if (pnmtv->itemNew.hItem == nTreeRootItem)
return 0;
//-------------------------------------------------
bIs_TVN_ITEMEXPANDING = TRUE;
if (pnmtv->action == TVE_COLLAPSE)
{
// 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 = nIMAGE_CLOSED;
pnmtv->itemNew.iSelectedImage = nIMAGE_CLOSED;
TreeView_SetItem (pnmh->hwndFrom, &(pnmtv->itemNew));
}
else
{
// 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 = nIMAGE_OPEN;
pnmtv->itemNew.iSelectedImage = nIMAGE_OPEN;
TreeView_SetItem (pnmh->hwndFrom, &(pnmtv->itemNew));
if ( ! (pnmtv->itemNew.state & TVIS_EXPANDEDONCE) )
{
// We need to fill in the subdirectory just expanded
SetCursor (LoadCursor(NULL, IDC_WAIT));
RegTree_BuildKey (pnmtv->hdr.hwndFrom, pnmtv->itemNew, &h_rootKey, sz_subKey);
RegTree_LoadKey (pnmtv->hdr.hwndFrom, (HTREEITEM)pnmtv->itemNew.hItem, h_rootKey, sz_subKey);
SetCursor (NULL);
}
}
bIs_TVN_ITEMEXPANDING = FALSE;
return 0; // return value is ignored
}
break;
case TVN_SELCHANGED:
{
// cast the NMHDR into a treeview notify structure
LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW) pnmh;
if (pnmtv->itemNew.hItem == pnmtv->itemOld.hItem)
return 0;
if (bIs_TVN_SELCHANGED == TRUE)
return 0;
bIs_TVN_SELCHANGED = TRUE;
SetCursor (LoadCursor(NULL, IDC_WAIT));
RegTree_BuildKey (pnmtv->hdr.hwndFrom, pnmtv->itemNew, &h_rootKey, sz_subKey);
RegList_LoadKey (hListWnd, h_rootKey, sz_subKey);
lstrcpy (szCurrSubKey, sz_subKey);
hCurrRootKey = h_rootKey;
SetCursor (NULL);
RegTree_GetRootPath (h_rootKey, sz_subKey);
if (h_rootKey)
lstrcat (sz_subKey, szCurrSubKey);
SetDlgItemText (h_wnd, IDC_PATH, sz_subKey);
bIs_TVN_SELCHANGED = FALSE;
}
break;
case TVN_KEYDOWN:
{
TV_KEYDOWN * pnkd = (TV_KEYDOWN FAR *) pnmh;
if (pnkd->wVKey == VK_DELETE)
{
HTREEITEM h_item = TreeView_GetSelection (pnmh->hwndFrom);
if (h_item == NULL)
break;
if (MessageBox (h_wnd, TEXT("Are you SURE you want to delete this KEY?"),
TEXT("Deleting"), MB_YESNO|MB_ICONQUESTION)==IDYES)
{
if (RegDeleteKey (hCurrRootKey, szCurrSubKey) != ERROR_SUCCESS)
{
MessageBox (h_wnd, TEXT("Can't delete the KEY."),
TEXT("Error"), MB_OK|MB_ICONEXCLAMATION);
break;
}
TreeView_DeleteItem (pnmh->hwndFrom, h_item);
}
}
}
break;
case LVN_KEYDOWN:
{
LV_KEYDOWN * pnkd = (LV_KEYDOWN FAR *) pnmh;
#if 0 //DEBUG
TCHAR ppp [80];
wsprintf (ppp, TEXT("0x%X"), pnkd->wVKey);
MessageBox (h_wnd, ppp, TEXT("Virtual Key"), MB_OK);
#endif
if (pnkd->wVKey == VK_DELETE)
{
UINT is_selected = ListView_GetSelectedCount (pnmh->hwndFrom);
if (is_selected)
{
int n_item = ListView_GetNextItem (pnmh->hwndFrom, -1, LVNI_ALL|LVNI_SELECTED);
if (n_item >= 0)
{
if (MessageBox (h_wnd, TEXT("Are you sure you want to delete this value?"),
TEXT("Deleting"), MB_YESNO|MB_ICONQUESTION)==IDYES)
{
HKEY h_key;
LV_ITEM listItem;
memset (&listItem, 0, sizeof (listItem));
listItem.pszText = sz_subKey;
listItem.cchTextMax = MAX_PATH*7;
listItem.iItem = n_item;
listItem.mask = LVIF_TEXT;
if (ListView_GetItem (pnmh->hwndFrom, &listItem) == FALSE)
break;
if (RegOpenKeyEx (hCurrRootKey, szCurrSubKey, 0, KEY_WRITE, &h_key) != ERROR_SUCCESS)
break;
if (RegDeleteValue (h_key, listItem.pszText) == ERROR_SUCCESS)
ListView_DeleteItem (pnmh->hwndFrom, n_item);
RegCloseKey (h_key);
}
}
}
}
else if (pnkd->wVKey == VK_RETURN)
RegList_EditSelectedValue (pnmh->hwndFrom, hCurrRootKey, szCurrSubKey);
}
break;
case NM_DBLCLK:
if (pnmh->hwndFrom == hListWnd)
RegList_EditSelectedValue (hListWnd, hCurrRootKey, szCurrSubKey);
break;
}
return 0;
}
//********************************************************************************************
//static BOOL WINAPI _aboutDialogHook (HWND h_wndDlg, UINT u_msg, WPARAM w_param, LPARAM l_param)
//{
// switch (u_msg)
// {
// case WM_COMMAND:
// switch (GET_WM_COMMAND_ID(w_param,l_param))
// {
// case IDCANCEL:
// EndDialog (h_wndDlg, 0);
// break;
// }
// break;
// }
// return 0;
//}
//********************************************************************************************
//Function for Adding keys to the registry
int len;
TCHAR *szbuf;
HWND hEditbox;
DWORD dwDisp;
HKEY hKey;
LPRECT rectl;
HKEY h_key;
BOOLEAN bool_isSubKeys = 0;
TCHAR psz_nextKey [MAX_PATH+1];
DWORD n_keyNameSize;
DWORD dw_index;
DWORD retCode;
TCHAR pRevCurrSubKey [MAX_PATH*8];
INT_PTR CALLBACK _addkey (HWND h_wndAdd, UINT u_msg, WPARAM w_param, LPARAM l_param)
{
switch (u_msg)
{
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(w_param,l_param))
{
case IDOK:
pRevCurrSubKey[2080]=szCurrSubKey[2080];
hEditbox = GetDlgItem(h_wndAdd, IDC_EDIT1);
len=GetWindowTextLength(hEditbox);
szbuf =(TCHAR*)GlobalAlloc(GPTR, len + 1);
GetWindowText(hEditbox, szbuf,len+1);
GetDlgItemText(hEditbox,IDC_EDIT1,(LPWSTR)szbuf, len + 1);
wcscat(szCurrSubKey,_T("\\"));
wcscat(szCurrSubKey, szbuf);
//Creating key for registry
rc= RegCreateKeyEx(hCurrRootKey,szCurrSubKey,0,TEXT(""),REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_ALL_ACCESS,NULL,&hKey,&dwDisp);
if (rc == ERROR_SUCCESS)
{
MessageBox(NULL,TEXT("KEY REGISTERED"),TEXT("NOTICE"),MB_OK);
}
else
{
MessageBox(NULL,TEXT("Failed"),TEXT("ERROR"),MB_OK);
}
//RegCloseKey(hKey);
//RegOpenKeyEx(hCurrRootKey,pRevCurrSubKey,0,KEY_EXECUTE,&h_key);
h_item=TreeView_GetSelection(hTreeWnd);//selecting the parent node
// retCode = RegOpenKeyEx (hCurrRootKey, hCurrRootKey, 0, KEY_EXECUTE, &h_key);
/*if (retCode != ERROR_SUCCESS)
return;*/
//for (dw_index = 0 ; ; dw_index ++) //--- Read all sub keys
//{
//n_keyNameSize = MAX_PATH;
//if (RegEnumKeyEx (hKey, dw_index, psz_nextKey, &n_keyNameSize, 0, NULL, NULL, NULL) != ERROR_SUCCESS)
//break;
//RegOpenKeyEx()
// RegOpenKeyEx(hCurrRootKey,pRevCurrSubKey,0,KEY_EXECUTE,&h_key);
//bool_isSubKeys = isParent (h_key, pRevCurrSubKey);
// DebugBreak();
Tree_AddItem (hTreeWnd, szbuf, h_item,FALSE);
RegCloseKey(hKey);
RegCloseKey(h_key);
RegCloseKey(szCurrSubKey);
RegCloseKey(pRevCurrSubKey);
RegCloseKey(hCurrRootKey);
case IDCANCEL:
EndDialog (h_wndAdd, 0);
break;
}
break;
}
return 0;
}
int len1;
TCHAR *szbuf1;
HWND hEditbox1;
DWORD dwDisp;
HKEY hKeyN2;
LPRECT rectl;
INT_PTR CALLBACK _string(HWND h_String, UINT u_msg, WPARAM w_param, LPARAM l_param)
{
switch (u_msg)
{
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(w_param,l_param))
{
case IDOK:
// DebugBreak();
hEditbox1 = GetDlgItem(h_String, IDC_EDIT2);
len1=GetWindowTextLength(hEditbox1);
szbuf1 =(TCHAR*)GlobalAlloc(GPTR, len1 + 1);
GetWindowText(hEditbox1, szbuf1,len1+1);
GetDlgItemText(hEditbox1,IDC_EDIT2,(LPWSTR)szbuf1, len1 + 1);
rc = RegOpenKeyEx (hCurrRootKey,szCurrSubKey
, 0,
KEY_SET_VALUE, &hKeyN2);
if(rc != ERROR_SUCCESS)
{
MessageBox (NULL, TEXT("RegOpenKeyEx Failed"),
TEXT("Key not opened"), MB_OK);
return FALSE;
}
//set a name and value under the open key
rc = RegSetValueEx (hKeyN2,szbuf1, 0,
REG_DWORD , (LPBYTE)&dwRegVal,
sizeof(dwRegVal));
if (rc != ERROR_SUCCESS)
{
MessageBox (NULL, TEXT("RegSetValueEx Failed"),
TEXT("Couldn't delete value"), MB_OK);
}
else
{
MessageBox (NULL, TEXT("String Name Added "),
TEXT("NOTICE"), MB_OK);
}
//always clean up after ourselves
RegCloseKey( hKeyN2 );
case IDCANCEL:
EndDialog (h_String, 0);
break;
}
break;
}
return 0;
}
INT_PTR CALLBACK _about(HWND h_Modify, UINT u_msg, WPARAM w_param, LPARAM l_param)
{
switch (u_msg)
{
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(w_param,l_param))
{
case IDOK:
case IDCANCEL:
EndDialog (h_Modify, 0);
break;
}
break;
}
return 0;
}
static BOOLEAN isParent (HKEY h_parent, TCHAR * psz_key)
{
DWORD n_numSubKeys; // address of buffer for number of subkeys
DWORD n_maxSubKeyLen;// address of buffer for longest subkey name length
DWORD n_maxClassLen; // address of buffer for longest class string length
DWORD n_numValues; // address of buffer for number of value entries
DWORD n_maxValueNameLen; // address of buffer for longest value name length
HKEY h_key; // handle of key to query
DWORD retCode = RegOpenKeyEx (h_parent, psz_key, 0, KEY_EXECUTE, &h_key);
if (retCode != ERROR_SUCCESS)
return FALSE;
n_numSubKeys = 0;
retCode = RegQueryInfoKey (h_key, NULL, NULL, NULL,
&n_numSubKeys, &n_maxSubKeyLen,
&n_maxClassLen,
&n_numValues, &n_maxValueNameLen, NULL,
NULL, NULL);
RegCloseKey (h_key);
return (n_numSubKeys != 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -