ReactOS  0.4.15-dev-3297-g037c744
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;
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;
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;
85  wcChild.hCursor = LoadCursorW(NULL, IDC_ARROW);
86  wcChild.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
87  wcChild.lpszClassName = szChildClass;
91 
92  RegisterClassExW(&wcChild); /* register child windows class */
93 
95 
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);
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  {
114  /* remove the separator after the menu item */
115  RemoveMenu(hEditMenu, 4, MF_BYPOSITION);
116  }
117  }
118 
119  if(hEditMenu != NULL)
121 
123  /* if (nClipboardFormat == 0) {
124  DWORD dwError = GetLastError();
125  } */
126 
130  NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
131 
132  if (!hFrameWnd)
133  {
134  return FALSE;
135  }
136 
137  /* Create the status bar */
140  if (hStatusBar)
141  {
142  /* Create the status bar panes */
145  }
146 
147  LoadSettings();
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 
160 {
162 }
163 
164 /******************************************************************************/
165 
167 {
169 
171  UnloadAclUiDll();
172 }
173 
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;
190  return TRUE;
191 }
192 
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 */
207 
208  if (ProcessCmdLine(lpCmdLine))
209  {
210  return 0;
211  }
212 
213  switch (GetUserDefaultUILanguage())
214  {
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  }
231 
232  /* Main message loop */
233  while (GetMessageW(&msg, NULL, 0, 0))
234  {
237  {
240  }
241  }
242 
244  return (int)msg.wParam;
245 }
246 
247 /* EOF */
#define WS_CLIPSIBLINGS
Definition: pedump.c:618
#define ID_SWITCH_PANELS
Definition: resource.h:152
LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: childwnd.c:301
#define WS_EX_WINDOWEDGE
Definition: winuser.h:407
#define MAX_LOADSTRING
Definition: main.c:37
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:806
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:168
#define LR_SHARED
Definition: winuser.h:1090
void ExitInstance(HINSTANCE hInstance)
Definition: main.c:166
#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:3196
#define LAYOUT_RTL
Definition: wingdi.h:1371
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
WORD ATOM
Definition: dimm.idl:113
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
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
#define ZeroMemory
Definition: winbase.h:1664
#define SM_CYSMICON
Definition: winuser.h:1003
HICON hIcon
Definition: winuser.h:3198
#define VK_TAB
Definition: winuser.h:2175
#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 ICC_WIN95_CLASSES
Definition: commctrl.h:66
#define ID_VIEW_STATUSBAR
Definition: resource.h:57
#define COLOR_3DFACE
Definition: winuser.h:919
void LoadSettings(void)
Definition: settings.c:53
#define FALSE
Definition: types.h:117
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
HACCEL hAccel
Definition: main.c:47
unsigned int BOOL
Definition: ntddk_ex.h:94
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:153
HACCEL WINAPI LoadAcceleratorsW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
#define WM_KEYDOWN
Definition: winuser.h:1698
static HANDLE(WINAPI *pGetProcessHandleFromHwnd)(HWND)
#define ICC_USEREX_CLASSES
Definition: commctrl.h:68
HWND hStatusBar
Definition: main.c:31
#define UlongToPtr(u)
Definition: config.h:106
LPCWSTR lpszClassName
Definition: winuser.h:3202
SHORT WINAPI GetKeyState(_In_ int)
BOOL WINAPI SetProcessDefaultLayout(DWORD dwDefaultLayout)
Definition: window.c:1720
#define MF_CHECKED
Definition: winuser.h:132
#define COUNT_OF(a)
Definition: main.h:33
WCHAR szFrameClass[MAX_LOADSTRING]
Definition: main.c:39
__wchar_t WCHAR
Definition: xmlstorage.h:180
HBRUSH hbrBackground
Definition: winuser.h:3200
UINT cbSize
Definition: winuser.h:3192
HMENU hPopupMenus
Definition: main.c:33
void DestroyMainMenu()
Definition: main.c:159
HWND hWnd
Definition: main.h:60
#define EM_SETSEL
Definition: winuser.h:2001
#define IDR_REGEDIT_MENU
Definition: resource.h:41
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:39
HINSTANCE hInstance
Definition: main.c:36
#define IDC_REGEDIT_FRAME
Definition: resource.h:40
BOOL TranslateChildTabMessage(PMSG msg)
Definition: main.c:174
HINSTANCE hInstance
Definition: winuser.h:3197
#define SM_CXSMICON
Definition: winuser.h:1002
int WINAPI TranslateAcceleratorW(_In_ HWND, _In_ HACCEL, _In_ LPMSG)
static const WCHAR L[]
Definition: oid.c:1250
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)
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
#define ID_VIEW_MENU
Definition: resource.h:25
WCHAR szChildClass[MAX_LOADSTRING]
Definition: main.c:40
HCURSOR hCursor
Definition: winuser.h:3199
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
#define WM_COMMAND
Definition: winuser.h:1723
#define STATUS_WINDOW
Definition: main.h:26
WNDPROC lpfnWndProc
Definition: winuser.h:3194
BOOL WINAPI DestroyMenu(_In_ HMENU)
ATOM WINAPI RegisterHexEditorClass(HINSTANCE hInstance)
Definition: hexedit.c:69
BOOL ProcessCmdLine(LPWSTR lpCmdLine)
Definition: regedit.c:296
#define ID_EDIT_MODIFY
Definition: resource.h:65
HWND hFrameWnd
Definition: main.c:30
HWND WINAPI GetParent(_In_ HWND)
#define IDR_POPUP_MENUS
Definition: resource.h:48
HMENU hMenuFrame
Definition: main.c:32
LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Definition: framewnd.c:1349
BOOL WINAPI RemoveMenu(_In_ HMENU, _In_ UINT, _In_ UINT)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#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)
#define VK_CONTROL
Definition: winuser.h:2179
HICON hIconSm
Definition: winuser.h:3203
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
HWND hAddressBarWnd
Definition: main.h:63
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:419
#define ICC_STANDARD_CLASSES
Definition: commctrl.h:73
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
VOID UnloadAclUiDll(VOID)
Definition: security.c:830
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#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:1971
UINT nClipboardFormat
Definition: main.c:34
#define APIENTRY
Definition: api.h:79
LPCWSTR strClipboardFormat
Definition: main.c:35