reactos/base/applications/regedit/main.c
Joachim Henze 9facbf6b7f [0.4.11][REGEDIT] Port back several improvements and crash-fixes
0.4.15-dev-5985-g 31fdaca8c0 [REGEDIT] Strip redundant include, minor formatting (#5264)
0.4.15-dev-5970-g 9d7d3314b3 [REGEDIT] Check whether pszSelectKey is NULL on CDN_FILEOK (#5255)
0.4.15-dev-5898-g 84e580b67e [REGEDIT] Fix ListView selection and finding (#5150)
(superseded) 0.4.15-dev-5802-g cce3eb9393 Fix buffer read past end problem. (#5146) CORE-15896 and CORE-18230
partially 0.4.15-dev-5753-g 1ee9ea4518 [REGEDIT] Avoid buffer overflow in SelectNode. CORE-18602 (I left the wscpy-replacement at the end for the fixed size strings, as they would increase binary size, and are totally safe)
partially 0.4.15-dev-5308-g 5daf5cd057 [REGEDIT] Use shell icons for the tree view (#4841) CORE-10764
0.4.15-dev-4850-g 568383c9b9 [REGEDIT] Fix issue at Find registry key (#4341)
partially 0.4.15-dev-2265-g bebdfda8b7 [REGEDIT]... Use newer file open dialog (#3571)
0.4.15-dev-1470-g 9de8787187 [REGEDIT] Display search finished messagebox when using Find Next (F3) menu item (#3371) CORE-17368
0.4.15-dev-1302-g 6aae5f4fdd [REGEDIT] Make "finished find" messagebox owned by Regedit window (#3369) CORE-17367
0.4.15-dev-169-g 0461de33c5 [REGEDIT] Fix HeapFree() on the wrong variable (#2736)
0.4.14-dev-1484-g c832112771 [REGEDIT] Fix tree view popup menu issues CORE-16887
0.4.14-dev-1468-g 763de230b2 [REGEDIT] Fix inconsistent menu state for 'Permissions' CORE-16889
a more efficient solution than 0.4.14-dev-1467-g b280615b85 [REGEDIT] Crash on selecting 'New' on root item 'My computer' CORE-16888
0.4.14-dev-1466-g 13dd917589 [REGEDIT] CORE-16892 fr-FR Translation update
0.4.13-dev-464-g 6b95727282 [REGEDIT] Adjust ListView column widths (#1663) CORE-15187
0.4.12-dev-47-g 63a0ac0461 [REGEDIT] Set background brush to child window (#1122) CORE-15442

a few fragments only of 0.4.15-dev-5304-g 36a7f0dc7c [REGEDIT] framewnd.c resize_frame_rect(), main.h strip externs before func declarations and reordering, treeview.c InitTreeViewImageLists()

also port back a few selected translation improvements, and strip the suggestions-feature in older branches <= 0.4.13 which does not exist in 2k3sp2.
2023-05-01 19:52:24 +02:00

246 lines
7.5 KiB
C

/*
* Regedit main function
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "regedit.h"
BOOL ProcessCmdLine(LPWSTR lpCmdLine);
/*******************************************************************************
* Global Variables:
*/
HINSTANCE hInst;
HWND hFrameWnd;
HWND hStatusBar;
HMENU hMenuFrame;
HMENU hPopupMenus = 0;
UINT nClipboardFormat;
LPCWSTR strClipboardFormat = L"TODO: SET CORRECT FORMAT";
#define MAX_LOADSTRING 100
WCHAR szTitle[MAX_LOADSTRING];
WCHAR szFrameClass[MAX_LOADSTRING];
WCHAR szChildClass[MAX_LOADSTRING];
/*******************************************************************************
*
*
* FUNCTION: InitInstance(HANDLE, int)
*
* PURPOSE: Saves instance handle and creates main window
*
* COMMENTS:
*
* In this function, we save the instance handle in a global variable and
* create and display the main program window.
*/
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
BOOL AclUiAvailable;
HMENU hEditMenu;
WNDCLASSEXW wcFrame;
WNDCLASSEXW wcChild;
ATOM hFrameWndClass;
ZeroMemory(&wcFrame, sizeof(WNDCLASSEXW));
wcFrame.cbSize = sizeof(WNDCLASSEXW);
wcFrame.lpfnWndProc = FrameWndProc;
wcFrame.hInstance = hInstance;
wcFrame.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT));
wcFrame.hIconSm = (HICON)LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT),
IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON), LR_SHARED);
wcFrame.hCursor = LoadCursorW(NULL, IDC_ARROW);
wcFrame.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
wcFrame.lpszClassName = szFrameClass;
hFrameWndClass = RegisterClassExW(&wcFrame); /* register frame window class */
ZeroMemory(&wcChild, sizeof(WNDCLASSEXW));
wcChild.cbSize = sizeof(WNDCLASSEXW);
wcChild.lpfnWndProc = ChildWndProc;
wcChild.cbWndExtra = sizeof(HANDLE);
wcChild.hInstance = hInstance;
wcChild.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT));
wcChild.hCursor = LoadCursorW(NULL, IDC_ARROW);
wcChild.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
wcChild.lpszClassName = szChildClass;
wcChild.hIconSm = (HICON)LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT),
IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON), LR_SHARED);
RegisterClassExW(&wcChild); /* register child windows class */
RegisterHexEditorClass(hInstance);
hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU));
hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS));
/* Initialize the Windows Common Controls DLL */
// TODO: Replace this call by InitCommonControlsEx(_something_)
InitCommonControls();
hEditMenu = GetSubMenu(hMenuFrame, 1);
AclUiAvailable = InitializeAclUiDll();
if(!AclUiAvailable)
{
/* hide the Edit/Permissions... menu entry */
if(hEditMenu != NULL)
{
RemoveMenu(hEditMenu, ID_EDIT_PERMISSIONS, MF_BYCOMMAND);
/* remove the separator after the menu item */
RemoveMenu(hEditMenu, 4, MF_BYPOSITION);
}
}
if(hEditMenu != NULL)
SetMenuDefaultItem(hEditMenu, ID_EDIT_MODIFY, MF_BYCOMMAND);
nClipboardFormat = RegisterClipboardFormatW(strClipboardFormat);
/* if (nClipboardFormat == 0) {
DWORD dwError = GetLastError();
} */
hFrameWnd = CreateWindowExW(WS_EX_WINDOWEDGE, (LPCWSTR)(UlongToPtr(hFrameWndClass)), szTitle,
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
if (!hFrameWnd)
{
return FALSE;
}
/* Create the status bar */
hStatusBar = CreateStatusWindowW(WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | SBT_NOBORDERS,
L"", hFrameWnd, STATUS_WINDOW);
if (hStatusBar)
{
/* Create the status bar panes */
SetupStatusBar(hFrameWnd, FALSE);
CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND | MF_CHECKED);
}
LoadSettings();
UpdateWindow(hFrameWnd);
return TRUE;
}
/******************************************************************************/
/*
* We need to destroy the main menu before destroying the main window
* to avoid a memory leak.
*/
void DestroyMainMenu()
{
DestroyMenu(hMenuFrame);
}
/******************************************************************************/
void ExitInstance(HINSTANCE hInstance)
{
UnregisterHexEditorClass(hInstance);
DestroyMenu(hPopupMenus);
UnloadAclUiDll();
}
BOOL TranslateChildTabMessage(PMSG msg)
{
if (msg->message != WM_KEYDOWN) return FALSE;
/* Allow Ctrl+A on address bar */
if ((msg->hwnd == g_pChildWnd->hAddressBarWnd) &&
(msg->message == WM_KEYDOWN) &&
(msg->wParam == L'A') && (GetKeyState(VK_CONTROL) < 0))
{
SendMessageW(msg->hwnd, EM_SETSEL, 0, -1);
return TRUE;
}
if (msg->wParam != VK_TAB) return FALSE;
if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
PostMessageW(hFrameWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
return TRUE;
}
int APIENTRY wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HACCEL hAccel;
UNREFERENCED_PARAMETER(hPrevInstance);
/* Initialize global strings */
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
LoadStringW(hInstance, IDC_REGEDIT_FRAME, szFrameClass, COUNT_OF(szFrameClass));
LoadStringW(hInstance, IDC_REGEDIT, szChildClass, COUNT_OF(szChildClass));
if (ProcessCmdLine(lpCmdLine))
{
return 0;
}
switch (GetUserDefaultUILanguage())
{
case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
SetProcessDefaultLayout(LAYOUT_RTL);
break;
default:
break;
}
/* Store instance handle in our global variable */
hInst = hInstance;
/* Perform application initialization */
if (!InitInstance(hInstance, nCmdShow))
{
return 0;
}
hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(ID_ACCEL));
/* Main message loop */
while (GetMessageW(&msg, NULL, 0, 0))
{
if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg) &&
!TranslateChildTabMessage(&msg))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
ExitInstance(hInstance);
return (int)msg.wParam;
}
/* EOF */