2003-08-07 03:10:13 +00:00
/*
* Regedit frame window
*
* Copyright ( C ) 2002 Robert Dickenson < robd @ reactos . org >
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
2006-05-18 12:49:52 +00:00
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , USA
2003-08-07 03:10:13 +00:00
*/
# define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
# include <windows.h>
# include <commctrl.h>
# include <commdlg.h>
# include <cderr.h>
# include <shellapi.h>
# include "main.h"
2012-10-12 12:38:24 +00:00
# include "wine/debug.h"
2003-08-07 03:10:13 +00:00
2012-10-12 12:38:24 +00:00
WINE_DEFAULT_DEBUG_CHANNEL ( regedit ) ;
2003-08-07 03:10:13 +00:00
/********************************************************************************
* Global and Local Variables :
*/
2022-04-14 13:01:34 +00:00
static const WCHAR favoritesKey [ ] = L " Software \\ Microsoft \\ Windows \\ CurrentVersion \\ Applets \\ Regedit \\ Favorites " ;
2003-08-07 03:10:13 +00:00
static BOOL bInMenuLoop = FALSE ; /* Tells us if we are in the menu loop */
2008-08-22 22:44:29 +00:00
static WCHAR favoriteName [ 128 ] ;
2008-08-25 20:21:58 +00:00
static WCHAR searchString [ 128 ] ;
2005-10-26 12:07:55 +00:00
static int searchMask = SEARCH_KEYS | SEARCH_VALUES | SEARCH_CONTENT ;
2003-08-07 03:10:13 +00:00
2008-09-03 13:54:00 +00:00
static WCHAR FileNameBuffer [ _MAX_PATH ] ;
static WCHAR FileTitleBuffer [ _MAX_PATH ] ;
static WCHAR FilterBuffer [ _MAX_PATH ] ;
2017-05-24 10:41:50 +00:00
static WCHAR expandW [ 32 ] , collapseW [ 32 ] ;
2017-06-05 00:58:14 +00:00
static WCHAR modifyW [ 32 ] , modify_binaryW [ 64 ] ;
2007-02-07 22:48:29 +00:00
2003-08-07 03:10:13 +00:00
/*******************************************************************************
* Local module support methods
*/
static void resize_frame_rect ( HWND hWnd , PRECT prect )
{
2003-12-08 22:48:07 +00:00
if ( IsWindowVisible ( hStatusBar ) ) {
2017-07-27 12:26:09 +00:00
RECT rt ;
2003-12-08 22:48:07 +00:00
SetupStatusBar ( hWnd , TRUE ) ;
GetClientRect ( hStatusBar , & rt ) ;
prect - > bottom - = rt . bottom ;
}
2003-12-12 04:08:59 +00:00
MoveWindow ( g_pChildWnd - > hWnd , prect - > left , prect - > top , prect - > right , prect - > bottom , TRUE ) ;
2003-08-07 03:10:13 +00:00
}
2005-06-04 10:01:25 +00:00
static void resize_frame_client ( HWND hWnd )
2003-08-07 03:10:13 +00:00
{
2003-12-08 22:48:07 +00:00
RECT rect ;
2003-08-07 03:10:13 +00:00
2003-12-08 22:48:07 +00:00
GetClientRect ( hWnd , & rect ) ;
resize_frame_rect ( hWnd , & rect ) ;
2003-08-07 03:10:13 +00:00
}
/********************************************************************************/
static void OnEnterMenuLoop ( HWND hWnd )
{
int nParts ;
2008-08-26 17:55:35 +00:00
WCHAR empty = 0 ;
2003-08-07 03:10:13 +00:00
/* Update the status bar pane sizes */
nParts = - 1 ;
2009-03-02 22:33:19 +00:00
SendMessageW ( hStatusBar , SB_SETPARTS , 1 , ( LPARAM ) & nParts ) ;
2003-08-07 03:10:13 +00:00
bInMenuLoop = TRUE ;
2008-12-04 04:32:06 +00:00
SendMessageW ( hStatusBar , SB_SETTEXTW , 0 , ( LPARAM ) & empty ) ;
2003-08-07 03:10:13 +00:00
}
static void OnExitMenuLoop ( HWND hWnd )
{
bInMenuLoop = FALSE ;
/* Update the status bar pane sizes*/
2003-12-08 22:48:07 +00:00
SetupStatusBar ( hWnd , TRUE ) ;
UpdateStatusBar ( ) ;
2003-08-07 03:10:13 +00:00
}
2017-05-24 10:41:50 +00:00
static void update_expand_or_collapse_item ( HWND hwndTV , HTREEITEM selection , HMENU hMenu )
{
TVITEMW item ;
MENUITEMINFOW info ;
item . hItem = selection ;
item . mask = TVIF_CHILDREN | TVIF_HANDLE | TVIF_STATE ;
item . stateMask = TVIS_EXPANDED ;
SendMessageW ( hwndTV , TVM_GETITEMW , 0 , ( LPARAM ) & item ) ;
info . cbSize = sizeof ( MENUITEMINFOW ) ;
info . fMask = MIIM_FTYPE | MIIM_STRING | MIIM_STATE ;
info . fType = MFT_STRING ;
info . fState = MFS_ENABLED ;
info . dwTypeData = expandW ;
if ( ! item . cChildren )
{
info . fState = MFS_GRAYED ;
goto update ;
}
if ( item . state & TVIS_EXPANDED )
info . dwTypeData = collapseW ;
update :
SetMenuItemInfoW ( hMenu , ID_TREE_EXPAND_COLLAPSE , FALSE , & info ) ;
}
2017-06-02 10:57:58 +00:00
static void update_modify_items ( HMENU hMenu , int index )
{
unsigned int state = MF_ENABLED ;
2017-06-05 00:58:24 +00:00
if ( index = = - 1 )
2017-06-02 10:57:58 +00:00
state = MF_GRAYED ;
EnableMenuItem ( hMenu , ID_EDIT_MODIFY , state | MF_BYCOMMAND ) ;
2017-06-05 00:58:24 +00:00
EnableMenuItem ( hMenu , ID_EDIT_MODIFY_BIN , state | MF_BYCOMMAND ) ;
2017-06-02 10:57:58 +00:00
}
static void update_delete_and_rename_items ( HMENU hMenu , WCHAR * keyName , int index )
2017-05-31 13:07:15 +00:00
{
2017-05-31 13:07:25 +00:00
unsigned int state_d = MF_ENABLED , state_r = MF_ENABLED ;
2017-05-31 13:07:15 +00:00
if ( ! g_pChildWnd - > nFocusPanel )
{
if ( ! keyName | | ! * keyName )
2017-05-31 13:07:25 +00:00
state_d = state_r = MF_GRAYED ;
2017-05-31 13:07:15 +00:00
}
2017-06-02 10:57:58 +00:00
else if ( index < 1 )
2017-05-31 13:07:15 +00:00
{
2017-06-02 10:57:58 +00:00
state_r = MF_GRAYED ;
2017-05-31 13:07:25 +00:00
if ( index = = - 1 ) state_d = MF_GRAYED ;
2017-05-31 13:07:15 +00:00
}
2017-05-31 13:07:25 +00:00
EnableMenuItem ( hMenu , ID_EDIT_DELETE , state_d | MF_BYCOMMAND ) ;
EnableMenuItem ( hMenu , ID_EDIT_RENAME , state_r | MF_BYCOMMAND ) ;
2017-05-31 13:07:15 +00:00
}
2017-06-01 09:33:29 +00:00
static void update_new_items_and_copy_keyname ( HMENU hMenu , WCHAR * keyName )
2017-05-31 13:07:36 +00:00
{
2017-06-01 09:33:29 +00:00
unsigned int state = MF_ENABLED , i ;
unsigned int items [ ] = { ID_EDIT_NEW_KEY , ID_EDIT_NEW_STRINGVALUE , ID_EDIT_NEW_BINARYVALUE ,
2022-06-23 15:51:22 +00:00
ID_EDIT_NEW_DWORDVALUE , ID_EDIT_NEW_QWORDVALUE , ID_EDIT_NEW_MULTI_STRINGVALUE ,
2017-06-01 09:33:29 +00:00
ID_EDIT_NEW_EXPANDVALUE , ID_EDIT_COPYKEYNAME } ;
2017-05-31 13:07:36 +00:00
2017-06-01 09:32:48 +00:00
if ( ! keyName )
2017-05-31 13:07:36 +00:00
state = MF_GRAYED ;
2018-05-21 13:34:49 +00:00
for ( i = 0 ; i < ARRAY_SIZE ( items ) ; i + + )
2017-06-01 09:33:29 +00:00
EnableMenuItem ( hMenu , items [ i ] , state | MF_BYCOMMAND ) ;
2017-05-31 13:07:36 +00:00
}
2005-09-26 09:57:56 +00:00
static void UpdateMenuItems ( HMENU hMenu ) {
HWND hwndTV = g_pChildWnd - > hTreeWnd ;
HKEY hRootKey = NULL ;
2008-08-26 17:55:35 +00:00
LPWSTR keyName ;
2011-04-16 08:07:17 +00:00
HTREEITEM selection ;
2017-06-02 10:57:58 +00:00
int index ;
2011-04-16 08:07:17 +00:00
selection = ( HTREEITEM ) SendMessageW ( hwndTV , TVM_GETNEXTITEM , TVGN_CARET , 0 ) ;
keyName = GetItemPath ( hwndTV , selection , & hRootKey ) ;
2017-06-02 10:57:58 +00:00
index = SendMessageW ( g_pChildWnd - > hListWnd , LVM_GETNEXTITEM , - 1 ,
2021-06-08 12:55:31 +00:00
MAKELPARAM ( LVNI_SELECTED , 0 ) ) ;
2017-05-24 10:41:50 +00:00
update_expand_or_collapse_item ( hwndTV , selection , hMenu ) ;
2017-06-02 10:57:58 +00:00
update_modify_items ( hMenu , index ) ;
update_delete_and_rename_items ( hMenu , keyName , index ) ;
2017-06-01 09:33:29 +00:00
update_new_items_and_copy_keyname ( hMenu , keyName ) ;
2005-09-26 09:57:56 +00:00
EnableMenuItem ( hMenu , ID_FAVORITES_ADDTOFAVORITES , ( hRootKey ? MF_ENABLED : MF_GRAYED ) | MF_BYCOMMAND ) ;
EnableMenuItem ( hMenu , ID_FAVORITES_REMOVEFAVORITE ,
( GetMenuItemCount ( hMenu ) > 2 ? MF_ENABLED : MF_GRAYED ) | MF_BYCOMMAND ) ;
2008-08-26 17:55:35 +00:00
2022-07-07 11:55:37 +00:00
free ( keyName ) ;
2005-09-26 09:57:56 +00:00
}
2017-06-05 00:58:14 +00:00
static void add_remove_modify_menu_items ( HMENU hMenu )
{
if ( ! g_pChildWnd - > nFocusPanel )
{
while ( GetMenuItemCount ( hMenu ) > 9 )
DeleteMenu ( hMenu , 0 , MF_BYPOSITION ) ;
}
else if ( GetMenuItemCount ( hMenu ) < 10 )
{
InsertMenuW ( hMenu , 0 , MF_BYPOSITION | MF_SEPARATOR , 0 , 0 ) ;
InsertMenuW ( hMenu , 0 , MF_BYPOSITION | MF_STRING , ID_EDIT_MODIFY_BIN , modify_binaryW ) ;
InsertMenuW ( hMenu , 0 , MF_BYPOSITION | MF_STRING , ID_EDIT_MODIFY , modifyW ) ;
}
}
2017-06-06 08:01:07 +00:00
static int add_favourite_key_items ( HMENU hMenu , HWND hList )
2005-09-26 09:57:56 +00:00
{
2017-06-05 00:57:53 +00:00
HKEY hkey ;
LONG rc ;
2017-06-06 08:01:07 +00:00
DWORD num_values , max_value_len , value_len , type , i = 0 ;
2017-06-05 00:57:53 +00:00
WCHAR * value_name ;
rc = RegOpenKeyExW ( HKEY_CURRENT_USER , favoritesKey , 0 , KEY_READ , & hkey ) ;
2017-06-06 08:01:07 +00:00
if ( rc ! = ERROR_SUCCESS ) return 0 ;
2017-06-05 00:57:53 +00:00
rc = RegQueryInfoKeyW ( hkey , NULL , NULL , NULL , NULL , NULL , NULL , & num_values ,
& max_value_len , NULL , NULL , NULL ) ;
if ( rc ! = ERROR_SUCCESS )
{
2022-02-04 08:57:23 +00:00
ERR ( " RegQueryInfoKey failed: %ld \n " , rc ) ;
2017-06-05 00:57:53 +00:00
goto exit ;
}
if ( ! num_values ) goto exit ;
max_value_len + + ;
2022-07-07 11:55:37 +00:00
value_name = malloc ( max_value_len * sizeof ( WCHAR ) ) ;
2017-06-05 00:57:53 +00:00
2017-06-06 08:01:07 +00:00
if ( hMenu ) AppendMenuW ( hMenu , MF_SEPARATOR , 0 , 0 ) ;
2017-06-05 00:57:53 +00:00
for ( i = 0 ; i < num_values ; i + + )
{
value_len = max_value_len ;
rc = RegEnumValueW ( hkey , i , value_name , & value_len , NULL , & type , NULL , NULL ) ;
if ( rc = = ERROR_SUCCESS & & type = = REG_SZ )
2017-06-06 08:01:07 +00:00
{
if ( hMenu )
AppendMenuW ( hMenu , MF_ENABLED | MF_STRING , ID_FAVORITE_FIRST + i , value_name ) ;
else if ( hList )
SendMessageW ( hList , LB_ADDSTRING , 0 , ( LPARAM ) value_name ) ;
}
2017-06-05 00:57:53 +00:00
}
2022-07-07 11:55:37 +00:00
free ( value_name ) ;
2017-06-05 00:57:53 +00:00
exit :
RegCloseKey ( hkey ) ;
2017-06-06 08:01:07 +00:00
return i ;
2017-06-05 00:57:53 +00:00
}
static void OnInitMenuPopup ( HWND hWnd , HMENU hMenu )
{
2017-06-05 00:58:14 +00:00
if ( hMenu = = GetSubMenu ( hMenuFrame , ID_EDIT_MENU ) )
add_remove_modify_menu_items ( hMenu ) ;
else if ( hMenu = = GetSubMenu ( hMenuFrame , ID_FAVORITES_MENU ) )
2017-06-05 00:57:53 +00:00
{
while ( GetMenuItemCount ( hMenu ) > 2 )
2005-09-26 09:57:56 +00:00
DeleteMenu ( hMenu , 2 , MF_BYPOSITION ) ;
2017-06-05 00:57:53 +00:00
2017-06-06 08:01:07 +00:00
add_favourite_key_items ( hMenu , NULL ) ;
2005-09-26 09:57:56 +00:00
}
2017-06-05 00:57:53 +00:00
2005-09-26 09:57:56 +00:00
UpdateMenuItems ( hMenu ) ;
}
2003-08-07 03:10:13 +00:00
static void OnMenuSelect ( HWND hWnd , UINT nItemID , UINT nFlags , HMENU hSysMenu )
{
2008-08-26 17:55:35 +00:00
WCHAR str [ 100 ] ;
2003-08-07 03:10:13 +00:00
2008-08-26 17:55:35 +00:00
str [ 0 ] = 0 ;
2003-08-07 03:10:13 +00:00
if ( nFlags & MF_POPUP ) {
if ( hSysMenu ! = GetMenu ( hWnd ) ) {
if ( nItemID = = 2 ) nItemID = 5 ;
}
}
2008-08-26 17:55:35 +00:00
if ( LoadStringW ( hInst , nItemID , str , 100 ) ) {
2003-08-07 03:10:13 +00:00
/* load appropriate string*/
2008-08-26 17:55:35 +00:00
LPWSTR lpsz = str ;
2003-08-07 03:10:13 +00:00
/* first newline terminates actual string*/
2019-04-01 09:47:50 +00:00
lpsz = wcschr ( lpsz , ' \n ' ) ;
2003-08-07 03:10:13 +00:00
if ( lpsz ! = NULL )
* lpsz = ' \0 ' ;
}
2008-08-26 17:55:35 +00:00
SendMessageW ( hStatusBar , SB_SETTEXTW , 0 , ( LPARAM ) str ) ;
2003-08-07 03:10:13 +00:00
}
void SetupStatusBar ( HWND hWnd , BOOL bResize )
{
RECT rc ;
int nParts ;
GetClientRect ( hWnd , & rc ) ;
nParts = rc . right ;
2003-12-08 22:48:07 +00:00
/* nParts = -1;*/
if ( bResize )
2008-08-26 17:55:35 +00:00
SendMessageW ( hStatusBar , WM_SIZE , 0 , 0 ) ;
SendMessageW ( hStatusBar , SB_SETPARTS , 1 , ( LPARAM ) & nParts ) ;
2005-03-21 11:23:40 +00:00
UpdateStatusBar ( ) ;
2003-08-07 03:10:13 +00:00
}
void UpdateStatusBar ( void )
{
2008-08-30 22:57:41 +00:00
LPWSTR fullPath = GetItemFullPath ( g_pChildWnd - > hTreeWnd , NULL , TRUE ) ;
2008-08-26 17:55:35 +00:00
SendMessageW ( hStatusBar , SB_SETTEXTW , 0 , ( LPARAM ) fullPath ) ;
2022-07-07 11:55:37 +00:00
free ( fullPath ) ;
2003-08-07 03:10:13 +00:00
}
static void toggle_child ( HWND hWnd , UINT cmd , HWND hchild )
{
2003-12-08 22:48:07 +00:00
BOOL vis = IsWindowVisible ( hchild ) ;
HMENU hMenuView = GetSubMenu ( hMenuFrame , ID_VIEW_MENU ) ;
2003-08-07 03:10:13 +00:00
2003-12-08 22:48:07 +00:00
CheckMenuItem ( hMenuView , cmd , vis ? MF_BYCOMMAND : MF_BYCOMMAND | MF_CHECKED ) ;
ShowWindow ( hchild , vis ? SW_HIDE : SW_SHOW ) ;
resize_frame_client ( hWnd ) ;
2003-08-07 03:10:13 +00:00
}
static BOOL CheckCommDlgError ( HWND hWnd )
{
2003-12-08 22:48:07 +00:00
DWORD dwErrorCode = CommDlgExtendedError ( ) ;
switch ( dwErrorCode ) {
case CDERR_DIALOGFAILURE :
break ;
case CDERR_FINDRESFAILURE :
break ;
case CDERR_NOHINSTANCE :
break ;
case CDERR_INITIALIZATION :
break ;
case CDERR_NOHOOK :
break ;
case CDERR_LOCKRESFAILURE :
break ;
case CDERR_NOTEMPLATE :
break ;
case CDERR_LOADRESFAILURE :
break ;
case CDERR_STRUCTSIZE :
break ;
case CDERR_LOADSTRFAILURE :
break ;
case FNERR_BUFFERTOOSMALL :
break ;
case CDERR_MEMALLOCFAILURE :
break ;
case FNERR_INVALIDFILENAME :
break ;
case CDERR_MEMLOCKFAILURE :
break ;
case FNERR_SUBCLASSFAILURE :
break ;
default :
break ;
}
return TRUE ;
2003-08-07 03:10:13 +00:00
}
2008-09-03 13:54:00 +00:00
static void ExportRegistryFile_StoreSelection ( HWND hdlg , OPENFILENAMEW * pOpenFileName )
2006-10-03 08:07:34 +00:00
{
if ( IsDlgButtonChecked ( hdlg , IDC_EXPORT_SELECTED ) )
{
2008-09-03 13:54:00 +00:00
INT len = SendDlgItemMessageW ( hdlg , IDC_EXPORT_PATH , WM_GETTEXTLENGTH , 0 , 0 ) ;
2022-07-07 11:55:37 +00:00
pOpenFileName - > lCustData = ( LPARAM ) malloc ( ( len + 1 ) * sizeof ( WCHAR ) ) ;
2008-09-03 13:54:00 +00:00
SendDlgItemMessageW ( hdlg , IDC_EXPORT_PATH , WM_GETTEXT , len + 1 , pOpenFileName - > lCustData ) ;
2006-10-03 08:07:34 +00:00
}
else
2017-08-02 12:35:51 +00:00
{
2022-07-07 11:55:37 +00:00
pOpenFileName - > lCustData = ( LPARAM ) malloc ( sizeof ( WCHAR ) ) ;
2017-08-02 12:35:51 +00:00
* ( WCHAR * ) pOpenFileName - > lCustData = 0 ;
}
2006-10-03 08:07:34 +00:00
}
2009-02-08 12:20:47 +00:00
static UINT_PTR CALLBACK ExportRegistryFile_OFNHookProc ( HWND hdlg , UINT uiMsg , WPARAM wParam , LPARAM lParam )
2003-08-07 03:10:13 +00:00
{
2008-09-03 13:54:00 +00:00
static OPENFILENAMEW * pOpenFileName ;
OFNOTIFYW * pOfNotify ;
2003-08-07 03:10:13 +00:00
switch ( uiMsg ) {
case WM_INITDIALOG :
2008-09-03 13:54:00 +00:00
pOpenFileName = ( OPENFILENAMEW * ) lParam ;
2003-08-07 03:10:13 +00:00
break ;
2006-10-03 08:07:34 +00:00
case WM_COMMAND :
if ( LOWORD ( wParam ) = = IDC_EXPORT_PATH & & HIWORD ( wParam ) = = EN_UPDATE )
CheckRadioButton ( hdlg , IDC_EXPORT_ALL , IDC_EXPORT_SELECTED , IDC_EXPORT_SELECTED ) ;
break ;
2003-08-07 03:10:13 +00:00
case WM_NOTIFY :
2008-09-03 13:54:00 +00:00
pOfNotify = ( OFNOTIFYW * ) lParam ;
2006-10-03 08:07:34 +00:00
switch ( pOfNotify - > hdr . code )
{
case CDN_INITDONE :
2008-08-30 22:57:41 +00:00
{
2008-10-03 21:21:15 +00:00
BOOL export_branch = FALSE ;
2008-09-03 13:54:00 +00:00
WCHAR * path = GetItemFullPath ( g_pChildWnd - > hTreeWnd , NULL , FALSE ) ;
SendDlgItemMessageW ( hdlg , IDC_EXPORT_PATH , WM_SETTEXT , 0 , ( LPARAM ) path ) ;
2014-11-18 09:25:22 +00:00
if ( path & & path [ 0 ] )
2008-10-03 21:21:15 +00:00
export_branch = TRUE ;
2022-07-07 11:55:37 +00:00
free ( path ) ;
2008-10-03 21:21:15 +00:00
CheckRadioButton ( hdlg , IDC_EXPORT_ALL , IDC_EXPORT_SELECTED , export_branch ? IDC_EXPORT_SELECTED : IDC_EXPORT_ALL ) ;
2006-10-03 08:07:34 +00:00
break ;
2008-08-30 22:57:41 +00:00
}
2006-10-03 08:07:34 +00:00
case CDN_FILEOK :
ExportRegistryFile_StoreSelection ( hdlg , pOpenFileName ) ;
break ;
}
2003-08-07 03:10:13 +00:00
break ;
default :
break ;
}
return 0L ;
}
2008-09-03 13:54:00 +00:00
static BOOL InitOpenFileName ( HWND hWnd , OPENFILENAMEW * pofn )
2003-08-07 03:10:13 +00:00
{
2008-09-03 13:54:00 +00:00
memset ( pofn , 0 , sizeof ( OPENFILENAMEW ) ) ;
pofn - > lStructSize = sizeof ( OPENFILENAMEW ) ;
2003-08-07 03:10:13 +00:00
pofn - > hwndOwner = hWnd ;
pofn - > hInstance = hInst ;
2006-08-23 12:11:39 +00:00
if ( FilterBuffer [ 0 ] = = 0 )
2011-01-13 20:09:47 +00:00
{
WCHAR filter_reg [ MAX_PATH ] , filter_reg4 [ MAX_PATH ] , filter_all [ MAX_PATH ] ;
LoadStringW ( hInst , IDS_FILEDIALOG_FILTER_REG , filter_reg , MAX_PATH ) ;
LoadStringW ( hInst , IDS_FILEDIALOG_FILTER_REG4 , filter_reg4 , MAX_PATH ) ;
LoadStringW ( hInst , IDS_FILEDIALOG_FILTER_ALL , filter_all , MAX_PATH ) ;
2022-04-14 13:01:34 +00:00
swprintf ( FilterBuffer , ARRAY_SIZE ( FilterBuffer ) , L " %s%c*.reg%c%s%c*.reg%c%s%c*.*%c " ,
2019-04-11 08:04:28 +00:00
filter_reg , 0 , 0 , filter_reg4 , 0 , 0 , filter_all , 0 , 0 ) ;
2011-01-13 20:09:47 +00:00
}
2006-08-23 12:11:39 +00:00
pofn - > lpstrFilter = FilterBuffer ;
2017-09-18 08:27:43 +00:00
pofn - > nFilterIndex = 1 ;
2003-08-07 03:10:13 +00:00
pofn - > lpstrFile = FileNameBuffer ;
pofn - > nMaxFile = _MAX_PATH ;
pofn - > lpstrFileTitle = FileTitleBuffer ;
pofn - > nMaxFileTitle = _MAX_PATH ;
pofn - > Flags = OFN_HIDEREADONLY ;
2006-10-03 08:05:05 +00:00
/* some other fields may be set by the caller */
2003-12-08 22:48:07 +00:00
return TRUE ;
2003-08-07 03:10:13 +00:00
}
2011-04-16 08:07:17 +00:00
static BOOL import_registry_filename ( LPWSTR filename )
2008-07-09 21:39:08 +00:00
{
2008-07-13 12:50:34 +00:00
BOOL Success ;
2022-04-14 13:01:34 +00:00
FILE * reg_file = _wfopen ( filename , L " rb " ) ;
2008-07-09 21:39:08 +00:00
if ( ! reg_file )
return FALSE ;
2008-07-13 12:50:34 +00:00
Success = import_registry_file ( reg_file ) ;
if ( fclose ( reg_file ) ! = 0 )
Success = FALSE ;
return Success ;
2008-07-09 21:39:08 +00:00
}
2003-08-07 03:10:13 +00:00
static BOOL ImportRegistryFile ( HWND hWnd )
{
2008-09-03 13:54:00 +00:00
OPENFILENAMEW ofn ;
WCHAR title [ 128 ] ;
2017-02-09 11:12:03 +00:00
HKEY root_key = NULL ;
WCHAR * key_path ;
2003-08-07 03:10:13 +00:00
InitOpenFileName ( hWnd , & ofn ) ;
2009-05-06 06:41:15 +00:00
ofn . Flags | = OFN_ENABLESIZING ;
2018-05-21 13:34:49 +00:00
LoadStringW ( hInst , IDS_FILEDIALOG_IMPORT_TITLE , title , ARRAY_SIZE ( title ) ) ;
2006-08-23 12:11:39 +00:00
ofn . lpstrTitle = title ;
2008-09-03 13:54:00 +00:00
if ( GetOpenFileNameW ( & ofn ) ) {
2017-02-09 11:08:20 +00:00
if ( ! import_registry_filename ( ofn . lpstrFile ) ) {
messagebox ( hWnd , MB_OK | MB_ICONERROR , IDS_APP_TITLE , IDS_IMPORT_FAILED , ofn . lpstrFile ) ;
2003-08-07 03:10:13 +00:00
return FALSE ;
2017-02-09 11:08:20 +00:00
} else {
messagebox ( hWnd , MB_OK | MB_ICONINFORMATION , IDS_APP_TITLE ,
IDS_IMPORT_SUCCESSFUL , ofn . lpstrFile ) ;
}
2003-08-07 03:10:13 +00:00
} else {
CheckCommDlgError ( hWnd ) ;
}
2008-01-04 16:14:19 +00:00
RefreshTreeView ( g_pChildWnd - > hTreeWnd ) ;
2017-02-09 11:12:03 +00:00
key_path = GetItemPath ( g_pChildWnd - > hTreeWnd , 0 , & root_key ) ;
RefreshListView ( g_pChildWnd - > hListWnd , root_key , key_path , NULL ) ;
2022-07-07 11:55:37 +00:00
free ( key_path ) ;
2017-02-09 11:12:03 +00:00
2003-12-08 22:48:07 +00:00
return TRUE ;
2003-08-07 03:10:13 +00:00
}
2008-10-03 21:21:15 +00:00
static BOOL ExportRegistryFile ( HWND hWnd )
2003-08-07 03:10:13 +00:00
{
2008-09-03 13:54:00 +00:00
OPENFILENAMEW ofn ;
WCHAR title [ 128 ] ;
2003-08-07 03:10:13 +00:00
InitOpenFileName ( hWnd , & ofn ) ;
2018-05-21 13:34:49 +00:00
LoadStringW ( hInst , IDS_FILEDIALOG_EXPORT_TITLE , title , ARRAY_SIZE ( title ) ) ;
2006-08-23 12:11:39 +00:00
ofn . lpstrTitle = title ;
2023-03-09 10:30:26 +00:00
ofn . lpstrDefExt = L " reg " ;
2006-10-03 08:07:34 +00:00
ofn . Flags = OFN_ENABLETEMPLATE | OFN_ENABLEHOOK | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT ;
2006-10-03 08:05:05 +00:00
ofn . lpfnHook = ExportRegistryFile_OFNHookProc ;
2008-09-03 13:54:00 +00:00
ofn . lpTemplateName = MAKEINTRESOURCEW ( IDD_EXPORT_TEMPLATE ) ;
if ( GetSaveFileNameW ( & ofn ) ) {
2003-08-07 03:10:13 +00:00
BOOL result ;
2008-09-14 00:21:23 +00:00
result = export_registry_key ( ofn . lpstrFile , ( LPWSTR ) ofn . lCustData , ofn . nFilterIndex ) ;
2003-08-07 03:10:13 +00:00
if ( ! result ) {
2023-03-09 10:22:48 +00:00
FIXME ( " Registry export failed. \n " ) ;
2003-08-07 03:10:13 +00:00
return FALSE ;
}
} else {
CheckCommDlgError ( hWnd ) ;
}
2003-12-08 22:48:07 +00:00
return TRUE ;
2003-08-07 03:10:13 +00:00
}
2008-08-10 10:43:06 +00:00
static BOOL PrintRegistryHive ( HWND hWnd , LPCWSTR path )
2003-08-07 03:10:13 +00:00
{
# if 1
2008-08-10 10:43:06 +00:00
PRINTDLGW pd ;
2003-08-07 03:10:13 +00:00
2011-04-16 08:07:17 +00:00
ZeroMemory ( & pd , sizeof ( PRINTDLGW ) ) ;
pd . lStructSize = sizeof ( PRINTDLGW ) ;
2003-08-07 03:10:13 +00:00
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 ;
2008-08-10 10:43:06 +00:00
if ( PrintDlgW ( & pd ) ) {
2012-10-12 12:38:24 +00:00
FIXME ( " printing is not yet implemented. \n " ) ;
2003-08-07 03:10:13 +00:00
/* GDI calls to render output. */
DeleteDC ( pd . hDC ) ; /* Delete DC when done.*/
}
# else
HRESULT hResult ;
2008-08-10 10:43:06 +00:00
PRINTDLGEXW pd ;
2003-08-07 03:10:13 +00:00
2008-08-10 10:43:06 +00:00
hResult = PrintDlgExW ( & pd ) ;
2003-08-07 03:10:13 +00:00
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. */
2012-10-12 12:38:24 +00:00
FIXME ( " printing is not yet implemented. \n " ) ;
2003-08-07 03:10:13 +00:00
break ;
case PD_RESULT_CANCEL :
/*The user clicked the Cancel button. The information in the PRINTDLGEX structure is unchanged. */
break ;
case PD_RESULT_PRINT :
2012-10-12 12:38:24 +00:00
FIXME ( " printing is not yet implemented. \n " ) ;
2003-08-07 03:10:13 +00:00
/*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 ;
}
2008-08-10 11:52:44 +00:00
static BOOL CopyKeyName ( HWND hWnd , LPCWSTR keyName )
2003-08-07 03:10:13 +00:00
{
BOOL result ;
result = OpenClipboard ( hWnd ) ;
if ( result ) {
result = EmptyClipboard ( ) ;
if ( result ) {
2008-08-10 11:52:44 +00:00
int len = ( lstrlenW ( keyName ) + 1 ) * sizeof ( WCHAR ) ;
2005-09-26 09:57:56 +00:00
HANDLE hClipData = GlobalAlloc ( GHND , len ) ;
LPVOID pLoc = GlobalLock ( hClipData ) ;
2008-08-10 11:52:44 +00:00
lstrcpyW ( pLoc , keyName ) ;
2005-09-26 09:57:56 +00:00
GlobalUnlock ( hClipData ) ;
2017-01-15 14:17:37 +00:00
SetClipboardData ( CF_UNICODETEXT , hClipData ) ;
2003-08-07 03:10:13 +00:00
} else {
/* error emptying clipboard*/
/* DWORD dwError = GetLastError(); */
;
}
if ( ! CloseClipboard ( ) ) {
/* error closing clipboard*/
/* DWORD dwError = GetLastError(); */
;
}
} else {
/* error opening clipboard*/
/* DWORD dwError = GetLastError(); */
;
}
return result ;
}
2005-10-26 12:07:55 +00:00
static INT_PTR CALLBACK find_dlgproc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
HWND hwndValue = GetDlgItem ( hwndDlg , IDC_VALUE_NAME ) ;
switch ( uMsg ) {
case WM_INITDIALOG :
EnableWindow ( GetDlgItem ( hwndDlg , IDOK ) , FALSE ) ;
CheckDlgButton ( hwndDlg , IDC_FIND_KEYS , searchMask & SEARCH_KEYS ? BST_CHECKED : BST_UNCHECKED ) ;
CheckDlgButton ( hwndDlg , IDC_FIND_VALUES , searchMask & SEARCH_VALUES ? BST_CHECKED : BST_UNCHECKED ) ;
CheckDlgButton ( hwndDlg , IDC_FIND_CONTENT , searchMask & SEARCH_CONTENT ? BST_CHECKED : BST_UNCHECKED ) ;
CheckDlgButton ( hwndDlg , IDC_FIND_WHOLE , searchMask & SEARCH_WHOLE ? BST_CHECKED : BST_UNCHECKED ) ;
2008-08-25 20:21:58 +00:00
SendMessageW ( hwndValue , EM_SETLIMITTEXT , 127 , 0 ) ;
SetWindowTextW ( hwndValue , searchString ) ;
2005-10-26 12:07:55 +00:00
return TRUE ;
case WM_COMMAND :
switch ( LOWORD ( wParam ) ) {
case IDC_VALUE_NAME :
if ( HIWORD ( wParam ) = = EN_UPDATE ) {
2008-08-25 20:21:58 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDOK ) , GetWindowTextLengthW ( hwndValue ) > 0 ) ;
2005-10-26 12:07:55 +00:00
return TRUE ;
}
break ;
case IDOK :
2008-08-25 20:21:58 +00:00
if ( GetWindowTextLengthW ( hwndValue ) > 0 ) {
2005-10-26 12:07:55 +00:00
int mask = 0 ;
if ( IsDlgButtonChecked ( hwndDlg , IDC_FIND_KEYS ) ) mask | = SEARCH_KEYS ;
if ( IsDlgButtonChecked ( hwndDlg , IDC_FIND_VALUES ) ) mask | = SEARCH_VALUES ;
if ( IsDlgButtonChecked ( hwndDlg , IDC_FIND_CONTENT ) ) mask | = SEARCH_CONTENT ;
if ( IsDlgButtonChecked ( hwndDlg , IDC_FIND_WHOLE ) ) mask | = SEARCH_WHOLE ;
searchMask = mask ;
2008-08-25 20:21:58 +00:00
GetWindowTextW ( hwndValue , searchString , 128 ) ;
2005-10-26 12:07:55 +00:00
EndDialog ( hwndDlg , IDOK ) ;
}
return TRUE ;
case IDCANCEL :
EndDialog ( hwndDlg , IDCANCEL ) ;
return TRUE ;
}
break ;
}
return FALSE ;
}
2005-09-26 09:57:56 +00:00
static INT_PTR CALLBACK addtofavorites_dlgproc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
HWND hwndValue = GetDlgItem ( hwndDlg , IDC_VALUE_NAME ) ;
switch ( uMsg ) {
case WM_INITDIALOG :
2008-05-21 22:00:12 +00:00
{
2017-06-05 00:58:04 +00:00
HTREEITEM selected ;
TVITEMW item ;
WCHAR buf [ 128 ] ;
selected = ( HTREEITEM ) SendMessageW ( g_pChildWnd - > hTreeWnd , TVM_GETNEXTITEM , TVGN_CARET , 0 ) ;
item . mask = TVIF_HANDLE | TVIF_TEXT ;
item . hItem = selected ;
item . pszText = buf ;
2018-05-21 13:34:49 +00:00
item . cchTextMax = ARRAY_SIZE ( buf ) ;
2017-06-05 00:58:04 +00:00
SendMessageW ( g_pChildWnd - > hTreeWnd , TVM_GETITEMW , 0 , ( LPARAM ) & item ) ;
2008-05-21 22:00:12 +00:00
2005-09-26 09:57:56 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDOK ) , FALSE ) ;
2017-06-05 00:58:04 +00:00
SetWindowTextW ( hwndValue , buf ) ;
2008-08-22 22:44:29 +00:00
SendMessageW ( hwndValue , EM_SETLIMITTEXT , 127 , 0 ) ;
2005-09-26 09:57:56 +00:00
return TRUE ;
2008-05-21 22:00:12 +00:00
}
2005-09-26 09:57:56 +00:00
case WM_COMMAND :
switch ( LOWORD ( wParam ) ) {
case IDC_VALUE_NAME :
if ( HIWORD ( wParam ) = = EN_UPDATE ) {
2011-04-16 08:07:17 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDOK ) , GetWindowTextLengthW ( hwndValue ) > 0 ) ;
2005-09-26 09:57:56 +00:00
return TRUE ;
}
break ;
case IDOK :
2008-08-22 22:44:29 +00:00
if ( GetWindowTextLengthW ( hwndValue ) > 0 ) {
GetWindowTextW ( hwndValue , favoriteName , 128 ) ;
2005-09-26 09:57:56 +00:00
EndDialog ( hwndDlg , IDOK ) ;
}
return TRUE ;
case IDCANCEL :
EndDialog ( hwndDlg , IDCANCEL ) ;
return TRUE ;
}
break ;
}
return FALSE ;
}
static INT_PTR CALLBACK removefavorite_dlgproc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
HWND hwndList = GetDlgItem ( hwndDlg , IDC_NAME_LIST ) ;
switch ( uMsg ) {
2017-06-06 08:01:07 +00:00
case WM_INITDIALOG :
if ( ! add_favourite_key_items ( NULL , hwndList ) )
2005-09-26 09:57:56 +00:00
return FALSE ;
2008-08-22 22:44:29 +00:00
SendMessageW ( hwndList , LB_SETCURSEL , 0 , 0 ) ;
2005-09-26 09:57:56 +00:00
return TRUE ;
case WM_COMMAND :
switch ( LOWORD ( wParam ) ) {
case IDC_NAME_LIST :
if ( HIWORD ( wParam ) = = LBN_SELCHANGE ) {
EnableWindow ( GetDlgItem ( hwndDlg , IDOK ) , lParam ! = - 1 ) ;
return TRUE ;
}
break ;
case IDOK : {
2008-09-02 17:26:44 +00:00
int pos = SendMessageW ( hwndList , LB_GETCURSEL , 0 , 0 ) ;
int len = SendMessageW ( hwndList , LB_GETTEXTLEN , pos , 0 ) ;
2005-09-26 09:57:56 +00:00
if ( len > 0 ) {
2022-07-07 11:55:37 +00:00
WCHAR * lpName = malloc ( ( len + 1 ) * sizeof ( WCHAR ) ) ;
2008-08-22 22:44:29 +00:00
SendMessageW ( hwndList , LB_GETTEXT , pos , ( LPARAM ) lpName ) ;
2005-09-26 09:57:56 +00:00
if ( len > 127 )
lpName [ 127 ] = ' \0 ' ;
2008-08-22 22:44:29 +00:00
lstrcpyW ( favoriteName , lpName ) ;
2005-09-26 09:57:56 +00:00
EndDialog ( hwndDlg , IDOK ) ;
2022-07-07 11:55:37 +00:00
free ( lpName ) ;
2005-09-26 09:57:56 +00:00
}
return TRUE ;
}
case IDCANCEL :
EndDialog ( hwndDlg , IDCANCEL ) ;
return TRUE ;
}
break ;
}
return FALSE ;
}
2003-08-07 03:10:13 +00:00
/*******************************************************************************
*
* FUNCTION : _CmdWndProc ( HWND , unsigned , WORD , LONG )
*
* PURPOSE : Processes WM_COMMAND messages for the main frame window .
*
*/
static BOOL _CmdWndProc ( HWND hWnd , UINT message , WPARAM wParam , LPARAM lParam )
{
2004-01-16 02:21:23 +00:00
HKEY hKeyRoot = 0 ;
2004-01-06 20:38:56 +00:00
DWORD valueType ;
2003-12-03 20:25:24 +00:00
2005-09-26 09:57:56 +00:00
if ( LOWORD ( wParam ) > = ID_FAVORITE_FIRST & & LOWORD ( wParam ) < = ID_FAVORITE_LAST ) {
HKEY hKey ;
2008-08-22 22:44:29 +00:00
if ( RegOpenKeyExW ( HKEY_CURRENT_USER , favoritesKey ,
2005-09-26 09:57:56 +00:00
0 , KEY_READ , & hKey ) = = ERROR_SUCCESS ) {
2008-08-22 22:44:29 +00:00
WCHAR namebuf [ KEY_MAX_LEN ] ;
2005-09-26 09:57:56 +00:00
BYTE valuebuf [ 4096 ] ;
DWORD ksize = KEY_MAX_LEN , vsize = sizeof ( valuebuf ) , type = 0 ;
2008-08-22 22:44:29 +00:00
if ( RegEnumValueW ( hKey , LOWORD ( wParam ) - ID_FAVORITE_FIRST , namebuf , & ksize , NULL ,
2005-09-26 09:57:56 +00:00
& type , valuebuf , & vsize ) = = ERROR_SUCCESS ) {
2008-08-22 22:44:29 +00:00
SendMessageW ( g_pChildWnd - > hTreeWnd , TVM_SELECTITEM , TVGN_CARET ,
( LPARAM ) FindPathInTree ( g_pChildWnd - > hTreeWnd , ( WCHAR * ) valuebuf ) ) ;
2005-09-26 09:57:56 +00:00
}
RegCloseKey ( hKey ) ;
}
return TRUE ;
}
2003-12-08 22:48:07 +00:00
switch ( LOWORD ( wParam ) ) {
2003-08-07 03:10:13 +00:00
case ID_REGISTRY_IMPORTREGISTRYFILE :
ImportRegistryFile ( hWnd ) ;
break ;
2008-05-17 20:20:55 +00:00
case ID_EDIT_EXPORT :
2003-08-07 03:10:13 +00:00
case ID_REGISTRY_EXPORTREGISTRYFILE :
2008-10-03 21:21:15 +00:00
ExportRegistryFile ( hWnd ) ;
2003-08-07 03:10:13 +00:00
break ;
case ID_REGISTRY_PRINT :
2008-08-10 10:43:06 +00:00
{
const WCHAR empty = 0 ;
2008-08-21 08:32:11 +00:00
PrintRegistryHive ( hWnd , & empty ) ;
2003-08-07 03:10:13 +00:00
break ;
2008-08-10 10:43:06 +00:00
}
2004-01-05 21:14:19 +00:00
case ID_EDIT_DELETE :
2008-10-08 21:39:31 +00:00
{
HWND hWndDelete = GetFocus ( ) ;
if ( hWndDelete = = g_pChildWnd - > hTreeWnd ) {
2008-08-30 22:57:41 +00:00
WCHAR * keyPath = GetItemPath ( g_pChildWnd - > hTreeWnd , 0 , & hKeyRoot ) ;
2004-05-04 02:55:28 +00:00
if ( keyPath = = 0 | | * keyPath = = 0 ) {
2008-08-28 14:18:44 +00:00
MessageBeep ( MB_ICONHAND ) ;
} else if ( DeleteKey ( hWnd , hKeyRoot , keyPath ) ) {
2004-03-15 20:19:38 +00:00
DeleteNode ( g_pChildWnd - > hTreeWnd , 0 ) ;
2004-05-04 02:55:28 +00:00
}
2022-07-07 11:55:37 +00:00
free ( keyPath ) ;
2008-10-08 21:39:31 +00:00
} else if ( hWndDelete = = g_pChildWnd - > hListWnd ) {
2017-06-16 13:06:59 +00:00
unsigned int num_selected , index , focus_idx ;
2017-05-29 08:20:55 +00:00
WCHAR * keyPath ;
2018-05-28 13:48:06 +00:00
num_selected = SendMessageW ( g_pChildWnd - > hListWnd , LVM_GETSELECTEDCOUNT , 0 , 0L ) ;
if ( ! num_selected )
2017-05-29 08:20:55 +00:00
break ;
2018-05-28 13:48:06 +00:00
else if ( num_selected = = 1 )
index = IDS_DELETE_VALUE_TEXT ;
else
index = IDS_DELETE_VALUE_TEXT_MULTIPLE ;
2017-05-29 08:20:55 +00:00
2018-05-28 13:48:06 +00:00
if ( messagebox ( hWnd , MB_YESNO | MB_ICONEXCLAMATION , IDS_DELETE_VALUE_TITLE , index ) ! = IDYES )
break ;
2008-08-31 14:58:27 +00:00
2017-05-29 08:20:55 +00:00
keyPath = GetItemPath ( g_pChildWnd - > hTreeWnd , 0 , & hKeyRoot ) ;
2017-06-16 13:06:59 +00:00
focus_idx = SendMessageW ( g_pChildWnd - > hListWnd , LVM_GETNEXTITEM , - 1 , MAKELPARAM ( LVNI_FOCUSED , 0 ) ) ;
2017-05-29 08:20:55 +00:00
index = SendMessageW ( g_pChildWnd - > hListWnd , LVM_GETNEXTITEM , - 1 , MAKELPARAM ( LVNI_SELECTED , 0 ) ) ;
2017-06-16 13:06:59 +00:00
2017-05-29 08:20:55 +00:00
while ( index ! = - 1 )
2008-08-09 00:25:34 +00:00
{
2017-05-29 08:20:55 +00:00
WCHAR * valueName = GetItemText ( g_pChildWnd - > hListWnd , index ) ;
2018-05-28 13:48:06 +00:00
if ( ! DeleteValue ( hWnd , hKeyRoot , keyPath , valueName ) )
2017-05-29 08:20:55 +00:00
{
2022-07-07 11:55:37 +00:00
free ( valueName ) ;
2017-05-29 08:20:55 +00:00
break ;
}
2022-07-07 11:55:37 +00:00
free ( valueName ) ;
2017-05-29 08:20:55 +00:00
SendMessageW ( g_pChildWnd - > hListWnd , LVM_DELETEITEM , index , 0L ) ;
2017-06-16 13:06:59 +00:00
/* the default value item is always visible, so add it back in */
if ( ! index )
{
AddEntryToList ( g_pChildWnd - > hListWnd , NULL , REG_SZ , NULL , 0 , 0 ) ;
if ( ! focus_idx )
{
LVITEMW item ;
item . state = item . stateMask = LVIS_FOCUSED ;
SendMessageW ( g_pChildWnd - > hListWnd , LVM_SETITEMSTATE , 0 , ( LPARAM ) & item ) ;
}
}
2017-05-29 08:20:55 +00:00
index = SendMessageW ( g_pChildWnd - > hListWnd , LVM_GETNEXTITEM , - 1 , MAKELPARAM ( LVNI_SELECTED , 0 ) ) ;
2008-08-09 00:25:34 +00:00
}
2022-07-07 11:55:37 +00:00
free ( keyPath ) ;
2008-10-08 21:39:31 +00:00
} else if ( IsChild ( g_pChildWnd - > hTreeWnd , hWndDelete ) | |
IsChild ( g_pChildWnd - > hListWnd , hWndDelete ) ) {
2011-04-16 08:07:17 +00:00
SendMessageW ( hWndDelete , WM_KEYDOWN , VK_DELETE , 0 ) ;
2008-10-08 21:39:31 +00:00
}
2004-01-05 21:14:19 +00:00
break ;
2008-10-08 21:39:31 +00:00
}
2003-12-03 20:25:24 +00:00
case ID_EDIT_MODIFY :
2016-12-19 10:10:55 +00:00
case ID_EDIT_MODIFY_BIN :
2008-08-27 18:40:31 +00:00
{
2018-07-16 12:20:46 +00:00
WCHAR * valueName = GetValueName ( g_pChildWnd - > hListWnd ) ;
WCHAR * keyPath = GetItemPath ( g_pChildWnd - > hTreeWnd , 0 , & hKeyRoot ) ;
2017-05-29 08:20:44 +00:00
ModifyValue ( hWnd , hKeyRoot , keyPath , valueName ) ;
2022-07-07 11:55:37 +00:00
free ( keyPath ) ;
free ( valueName ) ;
2003-12-08 22:48:07 +00:00
break ;
2008-08-27 18:40:31 +00:00
}
2005-10-26 12:07:55 +00:00
case ID_EDIT_FIND :
case ID_EDIT_FINDNEXT :
{
HTREEITEM hItem ;
if ( LOWORD ( wParam ) = = ID_EDIT_FIND & &
2011-04-16 08:07:17 +00:00
DialogBoxW ( 0 , MAKEINTRESOURCEW ( IDD_FIND ) , hWnd , find_dlgproc ) ! = IDOK )
2005-10-26 12:07:55 +00:00
break ;
if ( ! * searchString )
break ;
2011-04-16 08:07:17 +00:00
hItem = ( HTREEITEM ) SendMessageW ( g_pChildWnd - > hTreeWnd , TVM_GETNEXTITEM , TVGN_CARET , 0 ) ;
2005-10-26 12:07:55 +00:00
if ( hItem ) {
2011-04-16 08:07:17 +00:00
int row = SendMessageW ( g_pChildWnd - > hListWnd , LVM_GETNEXTITEM , - 1 , MAKELPARAM ( LVNI_FOCUSED , 0 ) ) ;
HCURSOR hcursorOld = SetCursor ( LoadCursorW ( NULL , ( LPCWSTR ) IDC_WAIT ) ) ;
2005-10-26 12:07:55 +00:00
hItem = FindNext ( g_pChildWnd - > hTreeWnd , hItem , searchString , searchMask , & row ) ;
SetCursor ( hcursorOld ) ;
if ( hItem ) {
2008-09-02 17:26:44 +00:00
SendMessageW ( g_pChildWnd - > hTreeWnd , TVM_SELECTITEM , TVGN_CARET , ( LPARAM ) hItem ) ;
2005-10-26 12:07:55 +00:00
InvalidateRect ( g_pChildWnd - > hTreeWnd , NULL , TRUE ) ;
UpdateWindow ( g_pChildWnd - > hTreeWnd ) ;
if ( row ! = - 1 ) {
2011-04-16 08:07:17 +00:00
LVITEMW item ;
item . state = 0 ;
item . stateMask = LVIS_FOCUSED | LVIS_SELECTED ;
SendMessageW ( g_pChildWnd - > hListWnd , LVM_SETITEMSTATE , ( UINT ) - 1 , ( LPARAM ) & item ) ;
item . state = LVIS_FOCUSED | LVIS_SELECTED ;
item . stateMask = LVIS_FOCUSED | LVIS_SELECTED ;
SendMessageW ( g_pChildWnd - > hListWnd , LVM_SETITEMSTATE , row , ( LPARAM ) & item ) ;
2005-10-26 12:07:55 +00:00
SetFocus ( g_pChildWnd - > hListWnd ) ;
} else {
SetFocus ( g_pChildWnd - > hTreeWnd ) ;
}
} else {
2017-02-01 12:57:04 +00:00
messagebox ( hWnd , MB_OK | MB_ICONINFORMATION , IDS_APP_TITLE , IDS_NOTFOUND , searchString ) ;
2005-10-26 12:07:55 +00:00
}
}
break ;
}
2003-08-07 03:10:13 +00:00
case ID_EDIT_COPYKEYNAME :
2005-09-26 09:57:56 +00:00
{
2008-08-30 22:57:41 +00:00
LPWSTR fullPath = GetItemFullPath ( g_pChildWnd - > hTreeWnd , NULL , FALSE ) ;
2005-09-26 09:57:56 +00:00
if ( fullPath ) {
CopyKeyName ( hWnd , fullPath ) ;
2022-07-07 11:55:37 +00:00
free ( fullPath ) ;
2005-09-26 09:57:56 +00:00
}
2003-08-07 03:10:13 +00:00
break ;
2005-09-26 09:57:56 +00:00
}
2004-01-03 00:33:56 +00:00
case ID_EDIT_NEW_KEY :
2008-08-21 21:49:34 +00:00
{
WCHAR newKeyW [ MAX_NEW_KEY_LEN ] ;
2008-08-30 22:57:41 +00:00
WCHAR * keyPath = GetItemPath ( g_pChildWnd - > hTreeWnd , 0 , & hKeyRoot ) ;
2008-08-28 14:18:44 +00:00
if ( CreateKey ( hWnd , hKeyRoot , keyPath , newKeyW ) ) {
2008-08-21 21:49:34 +00:00
if ( InsertNode ( g_pChildWnd - > hTreeWnd , 0 , newKeyW ) )
StartKeyRename ( g_pChildWnd - > hTreeWnd ) ;
}
2022-07-07 11:55:37 +00:00
free ( keyPath ) ;
2008-08-21 21:49:34 +00:00
}
2004-01-03 00:33:56 +00:00
break ;
2004-01-06 20:38:56 +00:00
case ID_EDIT_NEW_STRINGVALUE :
valueType = REG_SZ ;
goto create_value ;
2011-04-01 08:39:50 +00:00
case ID_EDIT_NEW_EXPANDVALUE :
valueType = REG_EXPAND_SZ ;
goto create_value ;
2007-03-30 15:14:03 +00:00
case ID_EDIT_NEW_MULTI_STRINGVALUE :
valueType = REG_MULTI_SZ ;
goto create_value ;
2004-01-06 20:38:56 +00:00
case ID_EDIT_NEW_BINARYVALUE :
valueType = REG_BINARY ;
goto create_value ;
case ID_EDIT_NEW_DWORDVALUE :
valueType = REG_DWORD ;
2022-06-23 15:51:22 +00:00
goto create_value ;
case ID_EDIT_NEW_QWORDVALUE :
valueType = REG_QWORD ;
2004-01-06 20:38:56 +00:00
/* fall through */
create_value :
2008-08-28 14:18:44 +00:00
{
2008-08-30 22:57:41 +00:00
WCHAR * keyPath = GetItemPath ( g_pChildWnd - > hTreeWnd , 0 , & hKeyRoot ) ;
2008-08-28 14:18:44 +00:00
WCHAR newKey [ MAX_NEW_KEY_LEN ] ;
2017-05-29 08:20:34 +00:00
if ( CreateValue ( hWnd , hKeyRoot , keyPath , valueType , newKey ) )
2004-05-04 02:55:28 +00:00
StartValueRename ( g_pChildWnd - > hListWnd ) ;
2022-07-07 11:55:37 +00:00
free ( keyPath ) ;
2008-08-28 14:18:44 +00:00
}
2004-03-15 20:19:38 +00:00
break ;
2004-01-13 23:18:12 +00:00
case ID_EDIT_RENAME :
2008-08-28 14:18:44 +00:00
{
2008-08-30 22:57:41 +00:00
WCHAR * keyPath = GetItemPath ( g_pChildWnd - > hTreeWnd , 0 , & hKeyRoot ) ;
2022-06-30 11:08:54 +00:00
if ( ! keyPath ) {
2008-08-28 14:18:44 +00:00
MessageBeep ( MB_ICONHAND ) ;
2022-06-30 11:08:54 +00:00
break ;
} else if ( * keyPath & & GetFocus ( ) = = g_pChildWnd - > hTreeWnd ) {
2008-08-28 14:18:44 +00:00
StartKeyRename ( g_pChildWnd - > hTreeWnd ) ;
} else if ( GetFocus ( ) = = g_pChildWnd - > hListWnd ) {
StartValueRename ( g_pChildWnd - > hListWnd ) ;
}
2022-07-07 11:55:37 +00:00
free ( keyPath ) ;
2004-01-13 23:18:12 +00:00
break ;
2017-05-24 10:41:50 +00:00
}
case ID_TREE_EXPAND_COLLAPSE :
{
HTREEITEM selected = ( HTREEITEM ) SendMessageW ( g_pChildWnd - > hTreeWnd , TVM_GETNEXTITEM , TVGN_CARET , 0 ) ;
SendMessageW ( g_pChildWnd - > hTreeWnd , TVM_EXPAND , TVE_TOGGLE , ( LPARAM ) selected ) ;
break ;
}
2003-08-07 03:10:13 +00:00
case ID_REGISTRY_PRINTERSETUP :
/*PRINTDLG pd;*/
/*PrintDlg(&pd);*/
/*PAGESETUPDLG psd;*/
/*PageSetupDlg(&psd);*/
break ;
case ID_REGISTRY_OPENLOCAL :
break ;
case ID_REGISTRY_EXIT :
DestroyWindow ( hWnd ) ;
break ;
2005-09-26 09:57:56 +00:00
case ID_FAVORITES_ADDTOFAVORITES :
{
HKEY hKey ;
2008-08-30 22:57:41 +00:00
LPWSTR lpKeyPath = GetItemFullPath ( g_pChildWnd - > hTreeWnd , NULL , FALSE ) ;
2005-09-26 09:57:56 +00:00
if ( lpKeyPath ) {
2011-04-16 08:07:17 +00:00
if ( DialogBoxW ( 0 , MAKEINTRESOURCEW ( IDD_ADDFAVORITE ) , hWnd , addtofavorites_dlgproc ) = = IDOK ) {
2008-08-22 22:44:29 +00:00
if ( RegCreateKeyExW ( HKEY_CURRENT_USER , favoritesKey ,
2005-09-26 09:57:56 +00:00
0 , NULL , 0 ,
KEY_READ | KEY_WRITE , NULL , & hKey , NULL ) = = ERROR_SUCCESS ) {
2008-08-22 22:44:29 +00:00
RegSetValueExW ( hKey , favoriteName , 0 , REG_SZ , ( BYTE * ) lpKeyPath , ( lstrlenW ( lpKeyPath ) + 1 ) * sizeof ( WCHAR ) ) ;
2005-09-26 09:57:56 +00:00
RegCloseKey ( hKey ) ;
}
}
2022-07-07 11:55:37 +00:00
free ( lpKeyPath ) ;
2005-09-26 09:57:56 +00:00
}
break ;
}
case ID_FAVORITES_REMOVEFAVORITE :
{
2011-04-16 08:07:17 +00:00
if ( DialogBoxW ( 0 , MAKEINTRESOURCEW ( IDD_DELFAVORITE ) , hWnd , removefavorite_dlgproc ) = = IDOK ) {
2005-09-26 09:57:56 +00:00
HKEY hKey ;
2008-08-22 22:44:29 +00:00
if ( RegOpenKeyExW ( HKEY_CURRENT_USER , favoritesKey ,
2005-09-26 09:57:56 +00:00
0 , KEY_READ | KEY_WRITE , & hKey ) = = ERROR_SUCCESS ) {
2008-08-22 22:44:29 +00:00
RegDeleteValueW ( hKey , favoriteName ) ;
2005-09-26 09:57:56 +00:00
RegCloseKey ( hKey ) ;
}
}
break ;
}
2003-08-07 03:10:13 +00:00
case ID_VIEW_REFRESH :
2008-08-27 18:40:31 +00:00
{
2008-08-30 22:57:41 +00:00
WCHAR * keyPath = GetItemPath ( g_pChildWnd - > hTreeWnd , 0 , & hKeyRoot ) ;
2005-01-10 16:03:22 +00:00
RefreshTreeView ( g_pChildWnd - > hTreeWnd ) ;
2008-08-28 14:18:44 +00:00
RefreshListView ( g_pChildWnd - > hListWnd , hKeyRoot , keyPath , NULL ) ;
2022-07-07 11:55:37 +00:00
free ( keyPath ) ;
2008-08-27 18:40:31 +00:00
}
2003-08-07 03:10:13 +00:00
break ;
2003-12-12 04:08:59 +00:00
/*case ID_OPTIONS_TOOLBAR:*/
/* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/
/* break;*/
2003-12-08 22:48:07 +00:00
case ID_VIEW_STATUSBAR :
toggle_child ( hWnd , LOWORD ( wParam ) , hStatusBar ) ;
2003-08-07 03:10:13 +00:00
break ;
case ID_HELP_HELPTOPICS :
2008-08-10 10:43:06 +00:00
{
2022-04-14 13:01:34 +00:00
WinHelpW ( hWnd , L " regedit " , HELP_FINDER , 0 ) ;
2003-08-07 03:10:13 +00:00
break ;
2008-08-10 10:43:06 +00:00
}
2003-08-07 03:10:13 +00:00
case ID_HELP_ABOUT :
ShowAboutBox ( hWnd ) ;
break ;
2004-01-16 01:59:05 +00:00
case ID_VIEW_SPLIT : {
RECT rt ;
POINT pt , pts ;
GetClientRect ( g_pChildWnd - > hWnd , & rt ) ;
pt . x = rt . left + g_pChildWnd - > nSplitPos ;
pt . y = ( rt . bottom / 2 ) ;
pts = pt ;
if ( ClientToScreen ( g_pChildWnd - > hWnd , & pts ) ) {
SetCursorPos ( pts . x , pts . y ) ;
2011-04-16 08:07:17 +00:00
SetCursor ( LoadCursorW ( 0 , ( LPCWSTR ) IDC_SIZEWE ) ) ;
2008-09-02 17:26:44 +00:00
SendMessageW ( g_pChildWnd - > hWnd , WM_LBUTTONDOWN , 0 , MAKELPARAM ( pt . x , pt . y ) ) ;
2004-01-16 01:59:05 +00:00
}
return TRUE ;
}
2003-08-07 03:10:13 +00:00
default :
2004-01-16 02:21:23 +00:00
return FALSE ;
2003-12-08 22:48:07 +00:00
}
2004-01-16 02:21:23 +00:00
return TRUE ;
2003-08-07 03:10:13 +00:00
}
/********************************************************************************
*
* FUNCTION : FrameWndProc ( HWND , unsigned , WORD , LONG )
*
* PURPOSE : Processes messages for the main frame window .
*
* WM_COMMAND - process the application menu
* WM_DESTROY - post a quit message and return
*
*/
LRESULT CALLBACK FrameWndProc ( HWND hWnd , UINT message , WPARAM wParam , LPARAM lParam )
{
switch ( message ) {
2003-12-12 04:08:59 +00:00
case WM_CREATE :
2022-04-14 13:01:34 +00:00
CreateWindowExW ( 0 , szChildClass , L " regedit child window " , WS_CHILD | WS_VISIBLE ,
2011-04-16 08:06:48 +00:00
CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT , CW_USEDEFAULT ,
hWnd , NULL , hInst , 0 ) ;
2018-05-21 13:34:49 +00:00
LoadStringW ( hInst , IDS_EXPAND , expandW , ARRAY_SIZE ( expandW ) ) ;
LoadStringW ( hInst , IDS_COLLAPSE , collapseW , ARRAY_SIZE ( collapseW ) ) ;
LoadStringW ( hInst , IDS_EDIT_MODIFY , modifyW , ARRAY_SIZE ( modifyW ) ) ;
LoadStringW ( hInst , IDS_EDIT_MODIFY_BIN , modify_binaryW , ARRAY_SIZE ( modify_binaryW ) ) ;
2003-08-07 03:10:13 +00:00
break ;
case WM_COMMAND :
2003-12-12 04:08:59 +00:00
if ( ! _CmdWndProc ( hWnd , message , wParam , lParam ) )
2011-04-16 08:06:48 +00:00
return DefWindowProcW ( hWnd , message , wParam , lParam ) ;
2003-08-07 03:10:13 +00:00
break ;
2004-05-04 02:55:28 +00:00
case WM_ACTIVATE :
if ( LOWORD ( hWnd ) )
SetFocus ( g_pChildWnd - > hWnd ) ;
break ;
2003-08-07 03:10:13 +00:00
case WM_SIZE :
resize_frame_client ( hWnd ) ;
break ;
case WM_TIMER :
break ;
case WM_ENTERMENULOOP :
OnEnterMenuLoop ( hWnd ) ;
break ;
case WM_EXITMENULOOP :
OnExitMenuLoop ( hWnd ) ;
break ;
2005-09-26 09:57:56 +00:00
case WM_INITMENUPOPUP :
if ( ! HIWORD ( lParam ) )
2017-06-05 00:57:53 +00:00
OnInitMenuPopup ( hWnd , ( HMENU ) wParam ) ;
2005-09-26 09:57:56 +00:00
break ;
2003-08-07 03:10:13 +00:00
case WM_MENUSELECT :
OnMenuSelect ( hWnd , LOWORD ( wParam ) , HIWORD ( wParam ) , ( HMENU ) lParam ) ;
break ;
case WM_DESTROY :
2008-08-10 10:43:06 +00:00
{
2022-04-14 13:01:34 +00:00
WinHelpW ( hWnd , L " regedit " , HELP_QUIT , 0 ) ;
2003-08-07 03:10:13 +00:00
PostQuitMessage ( 0 ) ;
2008-08-10 10:43:06 +00:00
}
2003-08-07 03:10:13 +00:00
default :
2011-04-16 08:06:48 +00:00
return DefWindowProcW ( hWnd , message , wParam , lParam ) ;
2003-12-08 22:48:07 +00:00
}
return 0 ;
2003-08-07 03:10:13 +00:00
}