wined3d: Use ARB_texture_rg for WINED3DFMT_R16G16_UNORM textures when available.
[wine] / programs / regedit / main.c
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 St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define WIN32_LEAN_AND_MEAN     /* Exclude rarely-used stuff from Windows headers */
22 #include <windows.h>
23 #include <commctrl.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <fcntl.h>
27
28 #define REGEDIT_DECLARE_FUNCTIONS
29 #include "main.h"
30
31 WCHAR g_pszDefaultValueName[64];
32
33 BOOL ProcessCmdLine(LPSTR lpCmdLine);
34
35 static const WCHAR hkey_local_machine[] = {'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0};
36 static const WCHAR hkey_users[] = {'H','K','E','Y','_','U','S','E','R','S',0};
37 static const WCHAR hkey_classes_root[] = {'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T',0};
38 static const WCHAR hkey_current_config[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','C','O','N','F','I','G',0};
39 static const WCHAR hkey_current_user[] = {'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R',0};
40 static const WCHAR hkey_dyn_data[] = {'H','K','E','Y','_','D','Y','N','_','D','A','T','A',0};
41
42 const WCHAR *reg_class_namesW[] = {hkey_local_machine, hkey_users,
43                                    hkey_classes_root, hkey_current_config,
44                                    hkey_current_user, hkey_dyn_data
45                                   };
46
47 /*******************************************************************************
48  * Global Variables:
49  */
50
51 HINSTANCE hInst;
52 HWND hFrameWnd;
53 HWND hStatusBar;
54 HMENU hMenuFrame;
55 HMENU hPopupMenus = 0;
56 UINT nClipboardFormat;
57 const WCHAR strClipboardFormat[] = {'T','O','D','O',':',' ','S','E','T',' ','C','O','R','R','E','C','T',' ','F','O','R','M','A','T',0};
58
59
60 #define MAX_LOADSTRING  100
61 WCHAR szTitle[MAX_LOADSTRING];
62 const WCHAR szFrameClass[] = {'R','E','G','E','D','I','T','_','F','R','A','M','E',0};
63 const WCHAR szChildClass[] = {'R','E','G','E','D','I','T',0};
64
65 static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
66 {
67     WCHAR empty = 0;
68     WNDCLASSEXW wndclass = {0};
69
70     /* Frame class */
71     wndclass.cbSize = sizeof(WNDCLASSEXW);
72     wndclass.style = CS_HREDRAW | CS_VREDRAW;
73     wndclass.lpfnWndProc = FrameWndProc;
74     wndclass.hInstance = hInstance;
75     wndclass.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT));
76     wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
77     wndclass.lpszClassName = szFrameClass;
78     wndclass.hIconSm = LoadImageW(hInstance, MAKEINTRESOURCEW(IDI_REGEDIT), IMAGE_ICON,
79                                   GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
80     RegisterClassExW(&wndclass);
81
82     /* Child class */
83     wndclass.lpfnWndProc = ChildWndProc;
84     wndclass.cbWndExtra = sizeof(HANDLE);
85     wndclass.lpszClassName = szChildClass;
86     RegisterClassExW(&wndclass);
87
88     hMenuFrame = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_REGEDIT_MENU));
89     hPopupMenus = LoadMenuW(hInstance, MAKEINTRESOURCEW(IDR_POPUP_MENUS));
90
91     /* Initialize the Windows Common Controls DLL */
92     InitCommonControls();
93
94     /* register our hex editor control */
95     HexEdit_Register();
96
97     nClipboardFormat = RegisterClipboardFormatW(strClipboardFormat);
98
99     hFrameWnd = CreateWindowExW(0, szFrameClass, szTitle,
100                                 WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
101                                 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
102                                 NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
103
104     if (!hFrameWnd) {
105         return FALSE;
106     }
107
108     /* Create the status bar */
109     hStatusBar = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
110                                     &empty, hFrameWnd, STATUS_WINDOW);
111     if (hStatusBar) {
112         /* Create the status bar panes */
113         SetupStatusBar(hFrameWnd, FALSE);
114         CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
115     }
116     ShowWindow(hFrameWnd, nCmdShow);
117     UpdateWindow(hFrameWnd);
118     return TRUE;
119 }
120
121 /******************************************************************************/
122
123 static void ExitInstance(void)
124 {
125     DestroyMenu(hMenuFrame);
126 }
127
128 static BOOL TranslateChildTabMessage(MSG *msg)
129 {
130     if (msg->message != WM_KEYDOWN) return FALSE;
131     if (msg->wParam != VK_TAB) return FALSE;
132     if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
133     PostMessageW(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
134     return TRUE;
135 }
136
137 int APIENTRY WinMain(HINSTANCE hInstance,
138                      HINSTANCE hPrevInstance,
139                      LPSTR     lpCmdLine,
140                      int       nCmdShow)
141 {
142     MSG msg;
143     HACCEL hAccel;
144
145     if (ProcessCmdLine(lpCmdLine)) {
146         return 0;
147     }
148
149     /* Initialize global strings */
150     LoadStringW(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
151     LoadStringW(hInstance, IDS_REGISTRY_DEFAULT_VALUE, g_pszDefaultValueName, COUNT_OF(g_pszDefaultValueName));
152
153     /* Store instance handle in our global variable */
154     hInst = hInstance;
155
156     /* Perform application initialization */
157     if (!InitInstance(hInstance, nCmdShow)) {
158         return FALSE;
159     }
160     hAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(IDC_REGEDIT));
161
162     /* Main message loop */
163     while (GetMessageW(&msg, NULL, 0, 0)) {
164         if (!TranslateAcceleratorW(hFrameWnd, hAccel, &msg)
165            && !TranslateChildTabMessage(&msg)) {
166             TranslateMessage(&msg);
167             DispatchMessageW(&msg);
168         }
169     }
170     ExitInstance();
171     return msg.wParam;
172 }