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
);
26 /*******************************************************************************
34 HMENU hPopupMenus
= 0;
35 UINT nClipboardFormat
;
36 LPCWSTR strClipboardFormat
= L
"TODO: SET CORRECT FORMAT";
38 #define MAX_LOADSTRING 100
39 WCHAR szTitle
[MAX_LOADSTRING
];
40 WCHAR szFrameClass
[MAX_LOADSTRING
];
41 WCHAR szChildClass
[MAX_LOADSTRING
];
44 /*******************************************************************************
47 * FUNCTION: InitInstance(HANDLE, int)
49 * PURPOSE: Saves instance handle and creates main window
53 * In this function, we save the instance handle in a global variable and
54 * create and display the main program window.
57 BOOL
InitInstance(HINSTANCE hInstance
, int nCmdShow
)
66 ZeroMemory(&wcFrame
, sizeof(WNDCLASSEXW
));
67 wcFrame
.cbSize
= sizeof(WNDCLASSEXW
);
68 wcFrame
.lpfnWndProc
= FrameWndProc
;
69 wcFrame
.hInstance
= hInstance
;
70 wcFrame
.hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_REGEDIT
));
71 wcFrame
.hIconSm
= (HICON
)LoadImageW(hInstance
, MAKEINTRESOURCEW(IDI_REGEDIT
),
72 IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
),
73 GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
74 wcFrame
.hCursor
= LoadCursorW(NULL
, IDC_ARROW
);
75 wcFrame
.lpszClassName
= szFrameClass
;
77 hFrameWndClass
= RegisterClassExW(&wcFrame
); /* register frame window class */
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
.lpszClassName
= szChildClass
;
87 wcChild
.hIconSm
= (HICON
)LoadImageW(hInstance
, MAKEINTRESOURCEW(IDI_REGEDIT
),
88 IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
),
89 GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
91 RegisterClassExW(&wcChild
); /* register child windows class */
93 RegisterHexEditorClass(hInstance
);
95 hMenuFrame
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDR_REGEDIT_MENU
));
96 hPopupMenus
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDR_POPUP_MENUS
));
98 /* Initialize the Windows Common Controls DLL */
99 // TODO: Replace this call by InitCommonControlsEx(_something_)
100 InitCommonControls();
102 hEditMenu
= GetSubMenu(hMenuFrame
, 1);
104 AclUiAvailable
= InitializeAclUiDll();
107 /* hide the Edit/Permissions... menu entry */
108 if(hEditMenu
!= NULL
)
110 RemoveMenu(hEditMenu
, ID_EDIT_PERMISSIONS
, MF_BYCOMMAND
);
111 /* remove the separator after the menu item */
112 RemoveMenu(hEditMenu
, 4, MF_BYPOSITION
);
116 if(hEditMenu
!= NULL
)
117 SetMenuDefaultItem(hEditMenu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
119 nClipboardFormat
= RegisterClipboardFormatW(strClipboardFormat
);
120 /* if (nClipboardFormat == 0) {
121 DWORD dwError = GetLastError();
124 hFrameWnd
= CreateWindowExW(WS_EX_WINDOWEDGE
, (LPCWSTR
)(UlongToPtr(hFrameWndClass
)), szTitle
,
125 WS_OVERLAPPEDWINDOW
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
126 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
127 NULL
, hMenuFrame
, hInstance
, NULL
/*lpParam*/);
134 /* Create the status bar */
135 hStatusBar
= CreateStatusWindowW(WS_VISIBLE
| WS_CHILD
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| SBT_NOBORDERS
,
136 L
"", hFrameWnd
, STATUS_WINDOW
);
139 /* Create the status bar panes */
140 SetupStatusBar(hFrameWnd
, FALSE
);
141 CheckMenuItem(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
| MF_CHECKED
);
145 UpdateWindow(hFrameWnd
);
149 /******************************************************************************/
152 * We need to destroy the main menu before destroying the main window
153 * to avoid a memory leak.
156 void DestroyMainMenu()
158 DestroyMenu(hMenuFrame
);
161 /******************************************************************************/
163 void ExitInstance(HINSTANCE hInstance
)
165 UnregisterHexEditorClass(hInstance
);
167 DestroyMenu(hPopupMenus
);
171 BOOL
TranslateChildTabMessage(PMSG msg
)
173 if (msg
->message
!= WM_KEYDOWN
) return FALSE
;
175 /* Allow Ctrl+A on address bar */
176 if ((msg
->hwnd
== g_pChildWnd
->hAddressBarWnd
) &&
177 (msg
->message
== WM_KEYDOWN
) &&
178 (msg
->wParam
== L
'A') && (GetKeyState(VK_CONTROL
) < 0))
180 SendMessageW(msg
->hwnd
, EM_SETSEL
, 0, -1);
184 if (msg
->wParam
!= VK_TAB
) return FALSE
;
185 if (GetParent(msg
->hwnd
) != g_pChildWnd
->hWnd
) return FALSE
;
186 PostMessageW(g_pChildWnd
->hWnd
, WM_COMMAND
, ID_SWITCH_PANELS
, 0);
190 int APIENTRY
wWinMain(HINSTANCE hInstance
,
191 HINSTANCE hPrevInstance
,
198 UNREFERENCED_PARAMETER(hPrevInstance
);
200 if (ProcessCmdLine(lpCmdLine
))
205 /* Initialize global strings */
206 LoadStringW(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
207 LoadStringW(hInstance
, IDC_REGEDIT_FRAME
, szFrameClass
, MAX_LOADSTRING
);
208 LoadStringW(hInstance
, IDC_REGEDIT
, szChildClass
, MAX_LOADSTRING
);
210 /* Store instance handle in our global variable */
213 /* Perform application initialization */
214 if (!InitInstance(hInstance
, nCmdShow
))
218 hAccel
= LoadAcceleratorsW(hInstance
, MAKEINTRESOURCEW(ID_ACCEL
));
220 /* Main message loop */
221 while (GetMessageW(&msg
, NULL
, 0, 0))
223 if (!TranslateAcceleratorW(hFrameWnd
, hAccel
, &msg
) &&
224 !TranslateChildTabMessage(&msg
))
226 TranslateMessage(&msg
);
227 DispatchMessageW(&msg
);
231 ExitInstance(hInstance
);
232 return (int)msg
.wParam
;