Use Interlocked* functions in AddRef and Release.
[wine.git] / programs / regedit / main.c
blob457ed7b3a418bfa7210a711d212fce49ea19adbf
1 /*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 <tchar.h>
26 #include <process.h>
27 #include <stdio.h>
28 #include <fcntl.h>
30 #define REGEDIT_DECLARE_FUNCTIONS
31 #include "main.h"
33 LPCSTR g_pszDefaultValueName = _T("(Default)");
35 BOOL ProcessCmdLine(LPSTR lpCmdLine);
38 /*******************************************************************************
39 * Global Variables:
42 HINSTANCE hInst;
43 HWND hFrameWnd;
44 HWND hStatusBar;
45 HMENU hMenuFrame;
46 HMENU hPopupMenus = 0;
47 UINT nClipboardFormat;
48 LPCTSTR strClipboardFormat = _T("TODO: SET CORRECT FORMAT");
51 #define MAX_LOADSTRING 100
52 TCHAR szTitle[MAX_LOADSTRING];
53 TCHAR szFrameClass[MAX_LOADSTRING];
54 TCHAR szChildClass[MAX_LOADSTRING];
57 /*******************************************************************************
60 * FUNCTION: InitInstance(HANDLE, int)
62 * PURPOSE: Saves instance handle and creates main window
64 * COMMENTS:
66 * In this function, we save the instance handle in a global variable and
67 * create and display the main program window.
70 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
72 WNDCLASSEX wcFrame = {
73 sizeof(WNDCLASSEX),
74 CS_HREDRAW | CS_VREDRAW/*style*/,
75 FrameWndProc,
76 0/*cbClsExtra*/,
77 0/*cbWndExtra*/,
78 hInstance,
79 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
80 LoadCursor(0, IDC_ARROW),
81 0/*hbrBackground*/,
82 0/*lpszMenuName*/,
83 szFrameClass,
84 (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
85 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
87 ATOM hFrameWndClass = RegisterClassEx(&wcFrame); /* register frame window class */
89 WNDCLASSEX wcChild = {
90 sizeof(WNDCLASSEX),
91 CS_HREDRAW | CS_VREDRAW/*style*/,
92 ChildWndProc,
93 0/*cbClsExtra*/,
94 sizeof(HANDLE)/*cbWndExtra*/,
95 hInstance,
96 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
97 LoadCursor(0, IDC_ARROW),
98 0/*hbrBackground*/,
99 0/*lpszMenuName*/,
100 szChildClass,
101 (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
102 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
105 ATOM hChildWndClass = RegisterClassEx(&wcChild); /* register child windows class */
106 hChildWndClass = hChildWndClass; /* warning eater */
108 hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_REGEDIT_MENU));
109 hPopupMenus = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_POPUP_MENUS));
111 /* Initialize the Windows Common Controls DLL */
112 InitCommonControls();
114 nClipboardFormat = RegisterClipboardFormat(strClipboardFormat);
115 /* if (nClipboardFormat == 0) {
116 DWORD dwError = GetLastError();
117 } */
119 hFrameWnd = CreateWindowEx(0, (LPCTSTR)(int)hFrameWndClass, szTitle,
120 WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
121 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
122 NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
124 if (!hFrameWnd) {
125 return FALSE;
128 /* Create the status bar */
129 hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
130 _T(""), hFrameWnd, STATUS_WINDOW);
131 if (hStatusBar) {
132 /* Create the status bar panes */
133 SetupStatusBar(hFrameWnd, FALSE);
134 CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
136 ShowWindow(hFrameWnd, nCmdShow);
137 UpdateWindow(hFrameWnd);
138 return TRUE;
141 /******************************************************************************/
143 void ExitInstance(void)
145 DestroyMenu(hMenuFrame);
148 BOOL TranslateChildTabMessage(MSG *msg)
150 if (msg->message != WM_KEYDOWN) return FALSE;
151 if (msg->wParam != VK_TAB) return FALSE;
152 if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
153 PostMessage(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
154 return TRUE;
157 int APIENTRY WinMain(HINSTANCE hInstance,
158 HINSTANCE hPrevInstance,
159 LPSTR lpCmdLine,
160 int nCmdShow)
162 MSG msg;
163 HACCEL hAccel;
165 if (ProcessCmdLine(lpCmdLine)) {
166 return 0;
169 /* Initialize global strings */
170 LoadString(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle));
171 LoadString(hInstance, IDC_REGEDIT_FRAME, szFrameClass, COUNT_OF(szFrameClass));
172 LoadString(hInstance, IDC_REGEDIT, szChildClass, COUNT_OF(szChildClass));
174 /* Store instance handle in our global variable */
175 hInst = hInstance;
177 /* Perform application initialization */
178 if (!InitInstance(hInstance, nCmdShow)) {
179 return FALSE;
181 hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDIT);
183 /* Main message loop */
184 while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
185 if (!TranslateAccelerator(hFrameWnd, hAccel, &msg)
186 && !TranslateChildTabMessage(&msg)) {
187 TranslateMessage(&msg);
188 DispatchMessage(&msg);
191 ExitInstance();
192 return msg.wParam;