ReactOS  0.4.12-dev-75-g00dd17e
main.c
Go to the documentation of this file.
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 
35 LPCWSTR strClipboardFormat = L"TODO: SET CORRECT FORMAT";
36 
37 #define MAX_LOADSTRING 100
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 
57 {
58  BOOL AclUiAvailable;
59  HMENU hEditMenu;
60 
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),
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),
91 
92  RegisterClassExW(&wcChild); /* register child windows class */
93 
94  RegisterHexEditorClass(hInstance);
95 
98 
99  /* Initialize the Windows Common Controls DLL */
100  // TODO: Replace this call by InitCommonControlsEx(_something_)
102 
103  hEditMenu = GetSubMenu(hMenuFrame, 1);
104 
105  AclUiAvailable = InitializeAclUiDll();
106  if(!AclUiAvailable)
107  {
108  /* hide the Edit/Permissions... menu entry */
109  if(hEditMenu != NULL)
110  {
112  /* remove the separator after the menu item */
113  RemoveMenu(hEditMenu, 4, MF_BYPOSITION);
114  }
115  }
116 
117  if(hEditMenu != NULL)
119 
121  /* if (nClipboardFormat == 0) {
122  DWORD dwError = GetLastError();
123  } */
124 
125  hFrameWnd = CreateWindowExW(WS_EX_WINDOWEDGE, (LPCWSTR)(UlongToPtr(hFrameWndClass)), szTitle,
128  NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
129 
130  if (!hFrameWnd)
131  {
132  return FALSE;
133  }
134 
135  /* Create the status bar */
137  L"", hFrameWnd, STATUS_WINDOW);
138  if (hStatusBar)
139  {
140  /* Create the status bar panes */
141  SetupStatusBar(hFrameWnd, FALSE);
143  }
144 
145  LoadSettings();
146  UpdateWindow(hFrameWnd);
147  return TRUE;
148 }
149 
150 /******************************************************************************/
151 
152 /*
153  * We need to destroy the main menu before destroying the main window
154  * to avoid a memory leak.
155  */
156 
158 {
160 }
161 
162 /******************************************************************************/
163 
165 {
166  UnregisterHexEditorClass(hInstance);
167 
169  UnloadAclUiDll();
170 }
171 
173 {
174  if (msg->message != WM_KEYDOWN) return FALSE;
175 
176  /* Allow Ctrl+A on address bar */
177  if ((msg->hwnd == g_pChildWnd->hAddressBarWnd) &&
178  (msg->message == WM_KEYDOWN) &&
179  (msg->wParam == L'A') && (GetKeyState(VK_CONTROL) < 0))
180  {
181  SendMessageW(msg->hwnd, EM_SETSEL, 0, -1);
182  return TRUE;
183  }
184 
185  if (msg->wParam != VK_TAB) return FALSE;
186  if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
188  return TRUE;
189 }
190 
192  HINSTANCE hPrevInstance,
193  LPWSTR lpCmdLine,
194  int nCmdShow)
195 {
196  MSG msg;
197  HACCEL hAccel;
198 
199  UNREFERENCED_PARAMETER(hPrevInstance);
200 
201  /* Initialize global strings */
205 
206  if (ProcessCmdLine(lpCmdLine))
207  {
208  return 0;
209  }
210 
211  switch (GetUserDefaultUILanguage())
212  {
215  break;
216 
217  default:
218  break;
219  }
220  /* Store instance handle in our global variable */
221  hInst = hInstance;
222 
223  /* Perform application initialization */
224  if (!InitInstance(hInstance, nCmdShow))
225  {
226  return 0;
227  }
228  hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(ID_ACCEL));
229 
230  /* Main message loop */
231  while (GetMessageW(&msg, NULL, 0, 0))
232  {
233  if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg) &&
235  {
236  TranslateMessage(&msg);
237  DispatchMessageW(&msg);
238  }
239  }
240 
241  ExitInstance(hInstance);
242  return (int)msg.wParam;
243 }
244 
245 /* EOF */
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define ID_SWITCH_PANELS
Definition: resource.h:151
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: childwnd.c:385
#define WS_EX_WINDOWEDGE
Definition: winuser.h:407
#define MAX_LOADSTRING
Definition: main.c:37
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:561
BOOL WINAPI TranslateMessage(_In_ const MSG *)
static HICON
Definition: imagelist.c:84
#define IDI_REGEDIT
Definition: resource.h:35
void SetupStatusBar(HWND hWnd, BOOL bResize)
Definition: framewnd.c:167
#define TRUE
Definition: types.h:120
#define LR_SHARED
Definition: winuser.h:1090
void ExitInstance(HINSTANCE hInstance)
Definition: main.c:164
#define IMAGE_ICON
Definition: winuser.h:212
ChildWnd * g_pChildWnd
Definition: childwnd.c:23
#define MF_BYCOMMAND
Definition: winuser.h:202
int cbWndExtra
Definition: winuser.h:3173
#define LAYOUT_RTL
Definition: wingdi.h:1352
WORD ATOM
Definition: dimm.idl:113
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
__wchar_t WCHAR
Definition: xmlstorage.h:180
UINT WINAPI RegisterClipboardFormatW(_In_ LPCWSTR)
BOOL InitializeAclUiDll(VOID)
Definition: security.c:811
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define SUBLANG_DEFAULT
Definition: nls.h:168
WCHAR szTitle[MAX_LOADSTRING]
Definition: main.c:38
BOOL WINAPI UpdateWindow(_In_ HWND)
BOOL WINAPI UnregisterHexEditorClass(HINSTANCE hInstance)
Definition: hexedit.c:90
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define ZeroMemory
Definition: winbase.h:1635
#define SM_CYSMICON
Definition: winuser.h:1003
HICON hIcon
Definition: winuser.h:3175
WPARAM wParam
Definition: winuser.h:3069
#define VK_TAB
Definition: winuser.h:2153
#define WS_CHILD
Definition: pedump.c:617
struct _WNDCLASSEXW WNDCLASSEXW
#define WS_CLIPCHILDREN
Definition: pedump.c:619
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define LANG_HEBREW
Definition: nls.h:67
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
HINSTANCE hInst
Definition: main.c:29
#define ID_VIEW_STATUSBAR
Definition: resource.h:56
#define COLOR_3DFACE
Definition: winuser.h:919
void LoadSettings(void)
Definition: settings.c:53
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
HACCEL hAccel
Definition: main.c:47
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
#define MF_BYPOSITION
Definition: winuser.h:203
HWND WINAPI CreateStatusWindowW(LONG style, LPCWSTR text, HWND parent, UINT wid)
Definition: commctrl.c:795
#define CW_USEDEFAULT
Definition: winuser.h:225
#define ID_EDIT_PERMISSIONS
Definition: resource.h:152
HACCEL WINAPI LoadAcceleratorsW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
#define APIENTRY
Definition: nt_native.h:48
UINT msg
Definition: msvc.h:92
smooth NULL
Definition: ftsmooth.c:416
#define WM_KEYDOWN
Definition: winuser.h:1691
static HANDLE(WINAPI *pGetProcessHandleFromHwnd)(HWND)
HWND hStatusBar
Definition: main.c:31
LPCWSTR lpszClassName
Definition: winuser.h:3179
SHORT WINAPI GetKeyState(_In_ int)
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1686
#define MF_CHECKED
Definition: winuser.h:132
#define UlongToPtr(ul)
Definition: basetsd.h:98
#define COUNT_OF(a)
Definition: main.h:33
WCHAR szFrameClass[MAX_LOADSTRING]
Definition: main.c:39
unsigned int BOOL
Definition: ntddk_ex.h:94
HBRUSH hbrBackground
Definition: winuser.h:3177
UINT cbSize
Definition: winuser.h:3169
HMENU hPopupMenus
Definition: main.c:33
void DestroyMainMenu()
Definition: main.c:157
HWND hWnd
Definition: main.h:59
#define EM_SETSEL
Definition: winuser.h:1979
#define IDR_REGEDIT_MENU
Definition: resource.h:40
unsigned int UINT
Definition: ndis.h:50
int WINAPI GetSystemMetrics(_In_ int)
DWORD WINAPI CheckMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2074
#define IDC_REGEDIT
Definition: resource.h:38
HINSTANCE hInstance
Definition: main.c:36
#define IDC_REGEDIT_FRAME
Definition: resource.h:39
BOOL TranslateChildTabMessage(PMSG msg)
Definition: main.c:172
HINSTANCE hInstance
Definition: winuser.h:3174
#define SM_CXSMICON
Definition: winuser.h:1002
int WINAPI TranslateAcceleratorW(_In_ HWND, _In_ HACCEL, _In_ LPMSG)
static const WCHAR L[]
Definition: oid.c:1087
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define ID_VIEW_MENU
Definition: resource.h:25
WCHAR szChildClass[MAX_LOADSTRING]
Definition: main.c:40
HCURSOR hCursor
Definition: winuser.h:3176
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define WM_COMMAND
Definition: winuser.h:1716
#define STATUS_WINDOW
Definition: main.h:26
WNDPROC lpfnWndProc
Definition: winuser.h:3171
BOOL WINAPI DestroyMenu(_In_ HMENU)
ATOM WINAPI RegisterHexEditorClass(HINSTANCE hInstance)
Definition: hexedit.c:69
BOOL ProcessCmdLine(LPWSTR lpCmdLine)
Definition: regedit.c:281
#define ID_EDIT_MODIFY
Definition: resource.h:64
HWND hFrameWnd
Definition: main.c:30
HWND WINAPI GetParent(_In_ HWND)
#define IDR_POPUP_MENUS
Definition: resource.h:47
HMENU hMenuFrame
Definition: main.c:32
LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: framewnd.c:1304
BOOL WINAPI RemoveMenu(_In_ HMENU, _In_ UINT, _In_ UINT)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDS_APP_TITLE
Definition: resource.h:10
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
BOOL WINAPI SetMenuDefaultItem(_In_ HMENU, _In_ UINT, _In_ UINT)
HWND hwnd
Definition: winuser.h:3067
#define VK_CONTROL
Definition: winuser.h:2157
HICON hIconSm
Definition: winuser.h:3180
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
HWND hAddressBarWnd
Definition: main.h:62
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
Definition: main.c:56
#define ID_ACCEL
Definition: resources.h:13
HMENU WINAPI LoadMenuW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define MAKELANGID(p, s)
Definition: nls.h:15
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2044
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
Definition: main.c:420
VOID WINAPI InitCommonControls(void)
Definition: commctrl.c:863
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
VOID UnloadAclUiDll(VOID)
Definition: security.c:830
WCHAR * LPWSTR
Definition: xmlstorage.h:184
UINT message
Definition: winuser.h:3068
#define WS_VISIBLE
Definition: pedump.c:620
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
#define SBT_NOBORDERS
Definition: commctrl.h:1941
UINT nClipboardFormat
Definition: main.c:34
LPCWSTR strClipboardFormat
Definition: main.c:35