2 * Regedit main function
4 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
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.
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.
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
23 BOOL
ProcessCmdLine(LPWSTR lpCmdLine
);
25 /*******************************************************************************
33 HMENU hPopupMenus
= 0;
34 UINT nClipboardFormat
;
35 LPCWSTR strClipboardFormat
= L
"TODO: SET CORRECT FORMAT";
37 #define MAX_LOADSTRING 100
38 WCHAR szTitle
[MAX_LOADSTRING
];
39 WCHAR szFrameClass
[MAX_LOADSTRING
];
40 WCHAR szChildClass
[MAX_LOADSTRING
];
43 /*******************************************************************************
46 * FUNCTION: InitInstance(HANDLE, int)
48 * PURPOSE: Saves instance handle and creates main window
52 * In this function, we save the instance handle in a global variable and
53 * create and display the main program window.
56 BOOL
InitInstance(HINSTANCE hInstance
, int nCmdShow
)
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
.lpszClassName
= szFrameClass
;
76 hFrameWndClass
= RegisterClassExW(&wcFrame
); /* register frame window class */
78 ZeroMemory(&wcChild
, sizeof(WNDCLASSEXW
));
79 wcChild
.cbSize
= sizeof(WNDCLASSEXW
);
80 wcChild
.lpfnWndProc
= ChildWndProc
;
81 wcChild
.cbWndExtra
= sizeof(HANDLE
);
82 wcChild
.hInstance
= hInstance
;
83 wcChild
.hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_REGEDIT
));
84 wcChild
.hCursor
= LoadCursorW(NULL
, IDC_ARROW
);
85 wcChild
.lpszClassName
= szChildClass
;
86 wcChild
.hIconSm
= (HICON
)LoadImageW(hInstance
, MAKEINTRESOURCEW(IDI_REGEDIT
),
87 IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
),
88 GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
90 RegisterClassExW(&wcChild
); /* register child windows class */
92 RegisterHexEditorClass(hInstance
);
94 hMenuFrame
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDR_REGEDIT_MENU
));
95 hPopupMenus
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDR_POPUP_MENUS
));
97 /* Initialize the Windows Common Controls DLL */
98 // TODO: Replace this call by InitCommonControlsEx(_something_)
101 hEditMenu
= GetSubMenu(hMenuFrame
, 1);
103 AclUiAvailable
= InitializeAclUiDll();
106 /* hide the Edit/Permissions... menu entry */
107 if(hEditMenu
!= NULL
)
109 RemoveMenu(hEditMenu
, ID_EDIT_PERMISSIONS
, MF_BYCOMMAND
);
110 /* remove the separator after the menu item */
111 RemoveMenu(hEditMenu
, 4, MF_BYPOSITION
);
115 if(hEditMenu
!= NULL
)
116 SetMenuDefaultItem(hEditMenu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
118 nClipboardFormat
= RegisterClipboardFormatW(strClipboardFormat
);
119 /* if (nClipboardFormat == 0) {
120 DWORD dwError = GetLastError();
123 hFrameWnd
= CreateWindowExW(WS_EX_WINDOWEDGE
, (LPCWSTR
)(UlongToPtr(hFrameWndClass
)), szTitle
,
124 WS_OVERLAPPEDWINDOW
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
125 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
126 NULL
, hMenuFrame
, hInstance
, NULL
/*lpParam*/);
133 /* Create the status bar */
134 hStatusBar
= CreateStatusWindowW(WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| SBT_NOBORDERS
,
135 L
"", hFrameWnd
, STATUS_WINDOW
);
138 /* Create the status bar panes */
139 SetupStatusBar(hFrameWnd
, FALSE
);
140 CheckMenuItem(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
| MF_CHECKED
);
144 UpdateWindow(hFrameWnd
);
148 /******************************************************************************/
151 * We need to destroy the main menu before destroying the main window
152 * to avoid a memory leak.
155 void DestroyMainMenu()
157 DestroyMenu(hMenuFrame
);
160 /******************************************************************************/
162 void ExitInstance(HINSTANCE hInstance
)
164 UnregisterHexEditorClass(hInstance
);
166 DestroyMenu(hPopupMenus
);
170 BOOL
TranslateChildTabMessage(PMSG msg
)
172 if (msg
->message
!= WM_KEYDOWN
) return FALSE
;
174 /* Allow Ctrl+A on address bar */
175 if ((msg
->hwnd
== g_pChildWnd
->hAddressBarWnd
) &&
176 (msg
->message
== WM_KEYDOWN
) &&
177 (msg
->wParam
== L
'A') && (GetKeyState(VK_CONTROL
) < 0))
179 SendMessageW(msg
->hwnd
, EM_SETSEL
, 0, -1);
183 if (msg
->wParam
!= VK_TAB
) return FALSE
;
184 if (GetParent(msg
->hwnd
) != g_pChildWnd
->hWnd
) return FALSE
;
185 PostMessageW(g_pChildWnd
->hWnd
, WM_COMMAND
, ID_SWITCH_PANELS
, 0);
189 int APIENTRY
wWinMain(HINSTANCE hInstance
,
190 HINSTANCE hPrevInstance
,
197 UNREFERENCED_PARAMETER(hPrevInstance
);
199 if (ProcessCmdLine(lpCmdLine
))
204 /* Initialize global strings */
205 LoadStringW(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
206 LoadStringW(hInstance
, IDC_REGEDIT_FRAME
, szFrameClass
, MAX_LOADSTRING
);
207 LoadStringW(hInstance
, IDC_REGEDIT
, szChildClass
, MAX_LOADSTRING
);
210 switch (GetUserDefaultUILanguage())
212 case MAKELANGID(LANG_HEBREW
, SUBLANG_DEFAULT
):
213 SetProcessDefaultLayout(LAYOUT_RTL
);
219 /* Store instance handle in our global variable */
222 /* Perform application initialization */
223 if (!InitInstance(hInstance
, nCmdShow
))
227 hAccel
= LoadAcceleratorsW(hInstance
, MAKEINTRESOURCEW(ID_ACCEL
));
229 /* Main message loop */
230 while (GetMessageW(&msg
, NULL
, 0, 0))
232 if (!TranslateAcceleratorW(hFrameWnd
, hAccel
, &msg
) &&
233 !TranslateChildTabMessage(&msg
))
235 TranslateMessage(&msg
);
236 DispatchMessageW(&msg
);
240 ExitInstance(hInstance
);
241 return (int)msg
.wParam
;