Regedit: Implemented accelerator keys
[reactos.git] / reactos / subsys / system / regedit / main.c
index 11c096d..174e3c8 100644 (file)
 #include <process.h>
 #include <stdio.h>
 #include <fcntl.h>
+#include <aclui.h>
+#include <cguid.h>
 
 #include "main.h"
 #include "hexedit.h"
 #include "security.h"
+#include "regproc.h"
 
 BOOL ProcessCmdLine(LPSTR lpCmdLine);
 
@@ -47,6 +50,7 @@ HMENU hMenuFrame;
 HMENU hPopupMenus = 0;
 UINT nClipboardFormat;
 LPCTSTR strClipboardFormat = _T("TODO: SET CORRECT FORMAT");
+const TCHAR g_szGeneralRegKey[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit");
 
 
 #define MAX_LOADSTRING  100
@@ -71,6 +75,8 @@ TCHAR szChildClass[MAX_LOADSTRING];
 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
 {
     BOOL AclUiAvailable;
+    HMENU hEditMenu;
+    TCHAR szBuffer[256];
 
     WNDCLASSEX wcFrame = {
                              sizeof(WNDCLASSEX),
@@ -116,12 +122,12 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
     /* Initialize the Windows Common Controls DLL */
     InitCommonControls();
 
+    hEditMenu = GetSubMenu(hMenuFrame, 1);
+
     AclUiAvailable = InitializeAclUiDll();
     if(!AclUiAvailable)
     {
-      HMENU hEditMenu;
       /* hide the Edit/Permissions... menu entry */
-      hEditMenu = GetSubMenu(hMenuFrame, 1);
       if(hEditMenu != NULL)
       {
         RemoveMenu(hEditMenu, ID_EDIT_PERMISSIONS, MF_BYCOMMAND);
@@ -130,6 +136,9 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
       }
     }
 
+    if(hEditMenu != NULL)
+        SetMenuDefaultItem(hEditMenu, ID_EDIT_MODIFY, MF_BYCOMMAND);
+
     nClipboardFormat = RegisterClipboardFormat(strClipboardFormat);
     /* if (nClipboardFormat == 0) {
         DWORD dwError = GetLastError();
@@ -152,6 +161,15 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
         SetupStatusBar(hFrameWnd, FALSE);
         CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
     }
+
+    /* Restore position */
+    if (RegQueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey,
+        _T("LastKey"),
+        szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])) == ERROR_SUCCESS)
+    {
+        SelectNode(g_pChildWnd->hTreeWnd, szBuffer);
+    }
+
     ShowWindow(hFrameWnd, nCmdShow);
     UpdateWindow(hFrameWnd);
     return TRUE;
@@ -159,10 +177,20 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
 
 /******************************************************************************/
 
+/* 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(hMenuFrame);
+    
+    DestroyMenu(hPopupMenus);
     UnloadAclUiDll();
 }
 
@@ -182,6 +210,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,
 {
     MSG msg;
     HACCEL hAccel;
+
     /*
         int hCrt;
         FILE *hf;
@@ -213,16 +242,17 @@ int APIENTRY WinMain(HINSTANCE hInstance,
     if (!InitInstance(hInstance, nCmdShow)) {
         return FALSE;
     }
-    hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDIT);
+    hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(ID_ACCEL));
 
     /* Main message loop */
     while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
-        if (!TranslateAccelerator(msg.hwnd, hAccel, &msg)
+        if (!TranslateAccelerator(hFrameWnd, hAccel, &msg)
             && !TranslateChildTabMessage(&msg)) {
             TranslateMessage(&msg);
             DispatchMessage(&msg);
         }
     }
+    
     ExitInstance(hInstance);
     return msg.wParam;
 }