[REGEDIT]
[reactos.git] / reactos / base / applications / regedit / main.c
index fa58e20..0afc57d 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <regedit.h>
 
-BOOL ProcessCmdLine(LPSTR lpCmdLine);
+BOOL ProcessCmdLine(LPWSTR lpCmdLine);
 
 
 /*******************************************************************************
@@ -33,14 +33,12 @@ HWND hStatusBar;
 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");
-
+LPCWSTR strClipboardFormat = L"TODO: SET CORRECT FORMAT";
 
 #define MAX_LOADSTRING  100
-TCHAR szTitle[MAX_LOADSTRING];
-TCHAR szFrameClass[MAX_LOADSTRING];
-TCHAR szChildClass[MAX_LOADSTRING];
+WCHAR szTitle[MAX_LOADSTRING];
+WCHAR szFrameClass[MAX_LOADSTRING];
+WCHAR szChildClass[MAX_LOADSTRING];
 
 
 /*******************************************************************************
@@ -60,46 +58,45 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
 {
     BOOL AclUiAvailable;
     HMENU hEditMenu;
-    TCHAR szBuffer[256];
 
-    WNDCLASSEX wcFrame;
-    WNDCLASSEX wcChild;
+    WNDCLASSEXW wcFrame;
+    WNDCLASSEXW wcChild;
     ATOM hFrameWndClass;
 
-    ZeroMemory(&wcFrame, sizeof(WNDCLASSEX));
-    wcFrame.cbSize = sizeof(WNDCLASSEX);
-    wcFrame.style = CS_HREDRAW | CS_VREDRAW;
+    ZeroMemory(&wcFrame, sizeof(WNDCLASSEXW));
+    wcFrame.cbSize = sizeof(WNDCLASSEXW);
     wcFrame.lpfnWndProc = FrameWndProc;
     wcFrame.hInstance = hInstance;
-    wcFrame.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT));
-    wcFrame.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT),
-                                       IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
-                                       GetSystemMetrics(SM_CYSMICON), LR_SHARED);
-    wcFrame.hCursor = LoadCursor(0, IDC_ARROW);
+    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.lpszClassName = szFrameClass;
 
-    hFrameWndClass = RegisterClassEx(&wcFrame); /* register frame window class */
+    hFrameWndClass = RegisterClassExW(&wcFrame); /* register frame window class */
 
-    ZeroMemory(&wcChild, sizeof(WNDCLASSEX));
-    wcChild.cbSize = sizeof(WNDCLASSEX);
-    wcChild.style = CS_HREDRAW | CS_VREDRAW;
+    ZeroMemory(&wcChild, sizeof(WNDCLASSEXW));
+    wcChild.cbSize = sizeof(WNDCLASSEXW);
     wcChild.lpfnWndProc = ChildWndProc;
     wcChild.cbWndExtra = sizeof(HANDLE);
     wcChild.hInstance = hInstance;
-    wcChild.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT));
-    wcChild.hCursor = LoadCursor(0, IDC_ARROW),
-    wcChild.lpszClassName =  szChildClass,
-    wcChild.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
-                                              GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
+    wcChild.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT));
+    wcChild.hCursor = LoadCursorW(NULL, IDC_ARROW);
+    wcChild.lpszClassName = szChildClass;
+    wcChild.hIconSm = (HICON)LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT),
+                                        IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
+                                        GetSystemMetrics(SM_CYSMICON), LR_SHARED);
 
-    RegisterClassEx(&wcChild); /* register child windows class */
+    RegisterClassExW(&wcChild); /* register child windows class */
 
     RegisterHexEditorClass(hInstance);
 
-    hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_REGEDIT_MENU));
-    hPopupMenus = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_POPUP_MENUS));
+    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);
@@ -107,61 +104,58 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
     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);
-      }
+        /* 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 = RegisterClipboardFormat(strClipboardFormat);
+    nClipboardFormat = RegisterClipboardFormatW(strClipboardFormat);
     /* if (nClipboardFormat == 0) {
         DWORD dwError = GetLastError();
     } */
 
-    hFrameWnd = CreateWindowEx(WS_EX_WINDOWEDGE, (LPCTSTR)(UlongToPtr(hFrameWndClass)), szTitle,
-                               WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
-                               CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
-                               NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
+    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) {
+    if (!hFrameWnd)
+    {
         return FALSE;
     }
 
     /* Create the status bar */
-    hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
-                                    _T(""), hFrameWnd, STATUS_WINDOW);
-    if (hStatusBar) {
+    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);
+        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);
+    LoadSettings();
     UpdateWindow(hFrameWnd);
     return TRUE;
 }
 
 /******************************************************************************/
 
-/* we need to destroy the main menu before destroying the main window
-   to avoid a memory leak */
+/*
+ * We need to destroy the main menu before destroying the main window
+ * to avoid a memory leak.
+ */
 
-void DestroyMainMenu() {
-       DestroyMenu(hMenuFrame);
+void DestroyMainMenu()
+{
+    DestroyMenu(hMenuFrame);
 }
 
 /******************************************************************************/
@@ -174,67 +168,69 @@ void ExitInstance(HINSTANCE hInstance)
     UnloadAclUiDll();
 }
 
-BOOL TranslateChildTabMessage(MSG *msg)
+BOOL TranslateChildTabMessage(PMSG msg)
 {
-  if (msg->message != WM_KEYDOWN) return FALSE;
-  if (msg->wParam != VK_TAB) return FALSE;
-  if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
-  PostMessage(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
-  return TRUE;
+    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(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
+    return TRUE;
 }
 
-int APIENTRY WinMain(HINSTANCE hInstance,
-                     HINSTANCE hPrevInstance,
-                     LPSTR     lpCmdLine,
-                     int       nCmdShow)
+int APIENTRY wWinMain(HINSTANCE hInstance,
+                      HINSTANCE hPrevInstance,
+                      LPWSTR    lpCmdLine,
+                      int       nCmdShow)
 {
     MSG msg;
     HACCEL hAccel;
 
     UNREFERENCED_PARAMETER(hPrevInstance);
 
-    /*
-        int hCrt;
-        FILE *hf;
-        AllocConsole();
-        hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
-        hf = _fdopen(hCrt, "w");
-        *stdout = *hf;
-        setvbuf(stdout, NULL, _IONBF, 0);
-
-       wprintf(L"command line exit, hInstance = %d\n", hInstance);
-       getch();
-       FreeConsole();
-        return 0;
-     */
-
-    if (ProcessCmdLine(lpCmdLine)) {
+    InfoMessageBox(NULL, MB_OK | MB_ICONERROR, L"Main", L"Main '%1'", lpCmdLine);
+    if (ProcessCmdLine(lpCmdLine))
+    {
         return 0;
     }
 
     /* Initialize global strings */
-    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
-    LoadString(hInstance, IDC_REGEDIT_FRAME, szFrameClass, MAX_LOADSTRING);
-    LoadString(hInstance, IDC_REGEDIT, szChildClass, MAX_LOADSTRING);
+    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
+    LoadStringW(hInstance, IDC_REGEDIT_FRAME, szFrameClass, MAX_LOADSTRING);
+    LoadStringW(hInstance, IDC_REGEDIT, szChildClass, MAX_LOADSTRING);
 
     /* Store instance handle in our global variable */
     hInst = hInstance;
 
     /* Perform application initialization */
-    if (!InitInstance(hInstance, nCmdShow)) {
+    if (!InitInstance(hInstance, nCmdShow))
+    {
         return FALSE;
     }
-    hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(ID_ACCEL));
+    hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(ID_ACCEL));
 
     /* Main message loop */
-    while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
-        if (!TranslateAccelerator(hFrameWnd, hAccel, &msg)
-            && !TranslateChildTabMessage(&msg)) {
+    while (GetMessageW(&msg, NULL, 0, 0))
+    {
+        if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg) &&
+            !TranslateChildTabMessage(&msg))
+        {
             TranslateMessage(&msg);
-            DispatchMessage(&msg);
+            DispatchMessageW(&msg);
         }
     }
 
     ExitInstance(hInstance);
-    return (int) msg.wParam;
+    return (int)msg.wParam;
 }
+
+/* EOF */