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 LPCTSTR strClipboardFormat
= _T("TODO: SET CORRECT FORMAT");
38 #define MAX_LOADSTRING 100
39 TCHAR szTitle
[MAX_LOADSTRING
];
40 TCHAR szFrameClass
[MAX_LOADSTRING
];
41 TCHAR 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(WNDCLASSEX
));
67 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
68 wcFrame
.lpfnWndProc
= FrameWndProc
;
69 wcFrame
.hInstance
= hInstance
;
70 wcFrame
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
));
71 wcFrame
.hIconSm
= (HICON
)LoadImage(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
),
72 IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
),
73 GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
74 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
75 wcFrame
.lpszClassName
= szFrameClass
;
77 hFrameWndClass
= RegisterClassEx(&wcFrame
); /* register frame window class */
79 ZeroMemory(&wcChild
, sizeof(WNDCLASSEX
));
80 wcChild
.cbSize
= sizeof(WNDCLASSEX
);
81 wcChild
.lpfnWndProc
= ChildWndProc
;
82 wcChild
.cbWndExtra
= sizeof(HANDLE
);
83 wcChild
.hInstance
= hInstance
;
84 wcChild
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
));
85 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
),
86 wcChild
.lpszClassName
= szChildClass
,
87 wcChild
.hIconSm
= (HICON
)LoadImage(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
), IMAGE_ICON
,
88 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
90 RegisterClassEx(&wcChild
); /* register child windows class */
92 RegisterHexEditorClass(hInstance
);
94 hMenuFrame
= LoadMenu(hInstance
, MAKEINTRESOURCE(IDR_REGEDIT_MENU
));
95 hPopupMenus
= LoadMenu(hInstance
, MAKEINTRESOURCE(IDR_POPUP_MENUS
));
97 /* Initialize the Windows Common Controls DLL */
100 hEditMenu
= GetSubMenu(hMenuFrame
, 1);
102 AclUiAvailable
= InitializeAclUiDll();
105 /* hide the Edit/Permissions... menu entry */
106 if(hEditMenu
!= NULL
)
108 RemoveMenu(hEditMenu
, ID_EDIT_PERMISSIONS
, MF_BYCOMMAND
);
109 /* remove the separator after the menu item */
110 RemoveMenu(hEditMenu
, 4, MF_BYPOSITION
);
114 if(hEditMenu
!= NULL
)
115 SetMenuDefaultItem(hEditMenu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
117 nClipboardFormat
= RegisterClipboardFormat(strClipboardFormat
);
118 /* if (nClipboardFormat == 0) {
119 DWORD dwError = GetLastError();
122 hFrameWnd
= CreateWindowEx(WS_EX_WINDOWEDGE
, (LPCTSTR
)(UlongToPtr(hFrameWndClass
)), szTitle
,
123 WS_OVERLAPPEDWINDOW
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
124 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
125 NULL
, hMenuFrame
, hInstance
, NULL
/*lpParam*/);
132 /* Create the status bar */
133 hStatusBar
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|SBT_NOBORDERS
,
134 _T(""), hFrameWnd
, STATUS_WINDOW
);
137 /* Create the status bar panes */
138 SetupStatusBar(hFrameWnd
, FALSE
);
139 CheckMenuItem(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
143 UpdateWindow(hFrameWnd
);
147 /******************************************************************************/
149 /* we need to destroy the main menu before destroying the main window
150 to avoid a memory leak */
152 void DestroyMainMenu()
154 DestroyMenu(hMenuFrame
);
157 /******************************************************************************/
159 void ExitInstance(HINSTANCE hInstance
)
161 UnregisterHexEditorClass(hInstance
);
163 DestroyMenu(hPopupMenus
);
167 BOOL
TranslateChildTabMessage(MSG
*msg
)
169 if (msg
->message
!= WM_KEYDOWN
) return FALSE
;
171 /* Allow Ctrl+A on address bar */
172 if ((msg
->hwnd
== g_pChildWnd
->hAddressBarWnd
) &&
173 (msg
->message
== WM_KEYDOWN
) &&
174 (msg
->wParam
== 'A') && (GetKeyState(VK_CONTROL
) < 0))
176 SendMessage(msg
->hwnd
, EM_SETSEL
, 0, -1);
180 if (msg
->wParam
!= VK_TAB
) return FALSE
;
181 if (GetParent(msg
->hwnd
) != g_pChildWnd
->hWnd
) return FALSE
;
182 PostMessage(g_pChildWnd
->hWnd
, WM_COMMAND
, ID_SWITCH_PANELS
, 0);
186 int APIENTRY
wWinMain(HINSTANCE hInstance
,
187 HINSTANCE hPrevInstance
,
194 UNREFERENCED_PARAMETER(hPrevInstance
);
196 if (ProcessCmdLine(lpCmdLine
))
201 /* Initialize global strings */
202 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
203 LoadString(hInstance
, IDC_REGEDIT_FRAME
, szFrameClass
, MAX_LOADSTRING
);
204 LoadString(hInstance
, IDC_REGEDIT
, szChildClass
, MAX_LOADSTRING
);
206 /* Store instance handle in our global variable */
209 /* Perform application initialization */
210 if (!InitInstance(hInstance
, nCmdShow
))
214 hAccel
= LoadAccelerators(hInstance
, MAKEINTRESOURCE(ID_ACCEL
));
216 /* Main message loop */
217 while (GetMessage(&msg
, (HWND
)NULL
, 0, 0))
219 if (!TranslateAccelerator(hFrameWnd
, hAccel
, &msg
)
220 && !TranslateChildTabMessage(&msg
))
222 TranslateMessage(&msg
);
223 DispatchMessage(&msg
);
227 ExitInstance(hInstance
);
228 return (int) msg
.wParam
;