1 /* 2 * Regedit main function 3 * 4 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 #include "regedit.h" 22 23 BOOL ProcessCmdLine(LPWSTR lpCmdLine); 24 25 /******************************************************************************* 26 * Global Variables: 27 */ 28 29 HINSTANCE hInst; 30 HWND hFrameWnd; 31 HWND hStatusBar; 32 HMENU hMenuFrame; 33 HMENU hPopupMenus = 0; 34 UINT nClipboardFormat; 35 LPCWSTR strClipboardFormat = L"TODO: SET CORRECT FORMAT"; 36 37 #define MAX_LOADSTRING 100 38 WCHAR szTitle[MAX_LOADSTRING]; 39 WCHAR szFrameClass[MAX_LOADSTRING]; 40 WCHAR szChildClass[MAX_LOADSTRING]; 41 42 43 /******************************************************************************* 44 * 45 * 46 * FUNCTION: InitInstance(HANDLE, int) 47 * 48 * PURPOSE: Saves instance handle and creates main window 49 * 50 * COMMENTS: 51 * 52 * In this function, we save the instance handle in a global variable and 53 * create and display the main program window. 54 */ 55 56 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 57 { 58 BOOL AclUiAvailable; 59 HMENU hEditMenu; 60 INITCOMMONCONTROLSEX icce; 61 WNDCLASSEXW wcFrame; 62 WNDCLASSEXW wcChild; 63 ATOM hFrameWndClass; 64 65 ZeroMemory(&wcFrame, sizeof(WNDCLASSEXW)); 66 wcFrame.cbSize = sizeof(WNDCLASSEXW); 67 wcFrame.lpfnWndProc = FrameWndProc; 68 wcFrame.hInstance = hInstance; 69 wcFrame.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT)); 70 wcFrame.hIconSm = (HICON)LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT), 71 IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), 72 GetSystemMetrics(SM_CYSMICON), LR_SHARED); 73 wcFrame.hCursor = LoadCursorW(NULL, IDC_ARROW); 74 wcFrame.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); 75 wcFrame.lpszClassName = szFrameClass; 76 77 hFrameWndClass = RegisterClassExW(&wcFrame); /* register frame window class */ 78 79 ZeroMemory(&wcChild, sizeof(WNDCLASSEXW)); 80 wcChild.cbSize = sizeof(WNDCLASSEXW); 81 wcChild.lpfnWndProc = ChildWndProc; 82 wcChild.cbWndExtra = sizeof(HANDLE); 83 wcChild.hInstance = hInstance; 84 wcChild.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT)); 85 wcChild.hCursor = LoadCursorW(NULL, IDC_ARROW); 86 wcChild.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); 87 wcChild.lpszClassName = szChildClass; 88 wcChild.hIconSm = (HICON)LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT), 89 IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), 90 GetSystemMetrics(SM_CYSMICON), LR_SHARED); 91 92 RegisterClassExW(&wcChild); /* register child windows class */ 93 94 RegisterHexEditorClass(hInstance); 95 96 hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU)); 97 hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS)); 98 99 /* Initialize the Windows Common Controls DLL */ 100 /* NOTE: Windows sets 0xFFFF to icce.dwICC but we use better value. */ 101 icce.dwSize = sizeof(icce); 102 icce.dwICC = ICC_WIN95_CLASSES | ICC_STANDARD_CLASSES | ICC_USEREX_CLASSES; 103 InitCommonControlsEx(&icce); 104 105 hEditMenu = GetSubMenu(hMenuFrame, 1); 106 107 AclUiAvailable = InitializeAclUiDll(); 108 if(!AclUiAvailable) 109 { 110 /* hide the Edit/Permissions... menu entry */ 111 if(hEditMenu != NULL) 112 { 113 RemoveMenu(hEditMenu, ID_EDIT_PERMISSIONS, MF_BYCOMMAND); 114 /* remove the separator after the menu item */ 115 RemoveMenu(hEditMenu, 4, MF_BYPOSITION); 116 } 117 } 118 119 if(hEditMenu != NULL) 120 SetMenuDefaultItem(hEditMenu, ID_EDIT_MODIFY, MF_BYCOMMAND); 121 122 nClipboardFormat = RegisterClipboardFormatW(strClipboardFormat); 123 /* if (nClipboardFormat == 0) { 124 DWORD dwError = GetLastError(); 125 } */ 126 127 hFrameWnd = CreateWindowExW(WS_EX_WINDOWEDGE, (LPCWSTR)(UlongToPtr(hFrameWndClass)), szTitle, 128 WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 129 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 130 NULL, hMenuFrame, hInstance, NULL/*lpParam*/); 131 132 if (!hFrameWnd) 133 { 134 return FALSE; 135 } 136 137 /* Create the status bar */ 138 hStatusBar = CreateStatusWindowW(WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | SBT_NOBORDERS, 139 L"", hFrameWnd, STATUS_WINDOW); 140 if (hStatusBar) 141 { 142 /* Create the status bar panes */ 143 SetupStatusBar(hFrameWnd, FALSE); 144 CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND | MF_CHECKED); 145 } 146 147 LoadSettings(); 148 UpdateWindow(hFrameWnd); 149 return TRUE; 150 } 151 152 /******************************************************************************/ 153 154 /* 155 * We need to destroy the main menu before destroying the main window 156 * to avoid a memory leak. 157 */ 158 159 void DestroyMainMenu() 160 { 161 DestroyMenu(hMenuFrame); 162 } 163 164 /******************************************************************************/ 165 166 void ExitInstance(HINSTANCE hInstance) 167 { 168 UnregisterHexEditorClass(hInstance); 169 170 DestroyMenu(hPopupMenus); 171 UnloadAclUiDll(); 172 } 173 174 BOOL TranslateChildTabMessage(PMSG msg) 175 { 176 if (msg->message != WM_KEYDOWN) return FALSE; 177 178 /* Allow Ctrl+A on address bar */ 179 if ((msg->hwnd == g_pChildWnd->hAddressBarWnd) && 180 (msg->message == WM_KEYDOWN) && 181 (msg->wParam == L'A') && (GetKeyState(VK_CONTROL) < 0)) 182 { 183 SendMessageW(msg->hwnd, EM_SETSEL, 0, -1); 184 return TRUE; 185 } 186 187 if (msg->wParam != VK_TAB) return FALSE; 188 if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE; 189 PostMessageW(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0); 190 return TRUE; 191 } 192 193 int APIENTRY wWinMain(HINSTANCE hInstance, 194 HINSTANCE hPrevInstance, 195 LPWSTR lpCmdLine, 196 int nCmdShow) 197 { 198 MSG msg; 199 HACCEL hAccel; 200 201 UNREFERENCED_PARAMETER(hPrevInstance); 202 203 /* Initialize global strings */ 204 LoadStringW(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle)); 205 LoadStringW(hInstance, IDC_REGEDIT_FRAME, szFrameClass, COUNT_OF(szFrameClass)); 206 LoadStringW(hInstance, IDC_REGEDIT, szChildClass, COUNT_OF(szChildClass)); 207 208 if (ProcessCmdLine(lpCmdLine)) 209 { 210 return 0; 211 } 212 213 switch (GetUserDefaultUILanguage()) 214 { 215 case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT): 216 SetProcessDefaultLayout(LAYOUT_RTL); 217 break; 218 219 default: 220 break; 221 } 222 /* Store instance handle in our global variable */ 223 hInst = hInstance; 224 225 /* Perform application initialization */ 226 if (!InitInstance(hInstance, nCmdShow)) 227 { 228 return 0; 229 } 230 hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(ID_ACCEL)); 231 232 /* Main message loop */ 233 while (GetMessageW(&msg, NULL, 0, 0)) 234 { 235 if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg) && 236 !TranslateChildTabMessage(&msg)) 237 { 238 TranslateMessage(&msg); 239 DispatchMessageW(&msg); 240 } 241 } 242 243 ExitInstance(hInstance); 244 return (int)msg.wParam; 245 } 246 247 /* EOF */ 248