user32/tests: Avoid side-effect in an assert.
[wine.git] / programs / winecfg / about.c
blob09cc0151574b8f18318661ebb5be0a6aab938380
1 /*
2 * WineCfg about panel
4 * Copyright 2002 Jaco Greeff
5 * Copyright 2003 Dimitrie O. Paun
6 * Copyright 2003 Mike Hearn
7 * Copyright 2010 Joel Holdsworth
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #define COBJMACROS
27 #include "config.h"
29 #include <windows.h>
30 #include <commctrl.h>
31 #include <shellapi.h>
33 #include "resource.h"
34 #include "winecfg.h"
37 static HICON logo = NULL;
38 static HFONT titleFont = NULL;
40 INT_PTR CALLBACK
41 AboutDlgProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
43 HWND hWnd;
44 HDC hDC;
45 RECT rcClient, rcRect;
46 char *owner, *org;
48 switch (uMsg)
50 case WM_NOTIFY:
51 switch(((LPNMHDR)lParam)->code)
53 case PSN_APPLY:
54 /*save registration info to registry */
55 owner = get_text(hDlg, IDC_ABT_OWNER);
56 org = get_text(hDlg, IDC_ABT_ORG);
58 set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion",
59 "RegisteredOwner", owner ? owner : "");
60 set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion",
61 "RegisteredOrganization", org ? org : "");
62 set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
63 "RegisteredOwner", owner ? owner : "");
64 set_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
65 "RegisteredOrganization", org ? org : "");
66 apply();
68 HeapFree(GetProcessHeap(), 0, owner);
69 HeapFree(GetProcessHeap(), 0, org);
70 break;
72 case NM_CLICK:
73 case NM_RETURN:
74 if(wParam == IDC_ABT_WEB_LINK)
75 ShellExecuteA(NULL, "open", PACKAGE_URL, NULL, NULL, SW_SHOW);
76 break;
78 break;
80 case WM_INITDIALOG:
82 hDC = GetDC(hDlg);
84 /* read owner and organization info from registry, load it into text box */
85 owner = get_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
86 "RegisteredOwner", "");
87 org = get_reg_key(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion",
88 "RegisteredOrganization", "");
90 SetDlgItemTextA(hDlg, IDC_ABT_OWNER, owner);
91 SetDlgItemTextA(hDlg, IDC_ABT_ORG, org);
93 SendMessageW(GetParent(hDlg), PSM_UNCHANGED, 0, 0);
95 HeapFree(GetProcessHeap(), 0, owner);
96 HeapFree(GetProcessHeap(), 0, org);
98 /* prepare the panel */
99 hWnd = GetDlgItem(hDlg, IDC_ABT_PANEL);
100 if(hWnd)
102 GetClientRect(hDlg, &rcClient);
103 GetClientRect(hWnd, &rcRect);
104 MoveWindow(hWnd, 0, 0, rcClient.right, rcRect.bottom, FALSE);
106 logo = LoadImageW((HINSTANCE)GetWindowLongPtrW(hDlg, GWLP_HINSTANCE),
107 MAKEINTRESOURCEW(IDI_LOGO), IMAGE_ICON, 0, 0, LR_SHARED);
110 /* prepare the title text */
111 hWnd = GetDlgItem(hDlg, IDC_ABT_TITLE_TEXT);
112 if(hWnd)
114 static const WCHAR tahomaW[] = {'T','a','h','o','m','a',0};
115 titleFont = CreateFontW(
116 -MulDiv(24, GetDeviceCaps(hDC, LOGPIXELSY), 72),
117 0, 0, 0, 0, FALSE, 0, 0, 0, 0, 0, 0, 0, tahomaW);
118 SendMessageW(hWnd, WM_SETFONT, (WPARAM)titleFont, TRUE);
119 SetWindowTextA(hWnd, PACKAGE_NAME);
121 SetDlgItemTextA(hDlg, IDC_ABT_PANEL_TEXT, PACKAGE_VERSION);
123 /* prepare the web link */
124 SetDlgItemTextA(hDlg, IDC_ABT_WEB_LINK, "<a href=\"" PACKAGE_URL "\">" PACKAGE_URL "</a>");
126 ReleaseDC(hDlg, hDC);
128 break;
130 case WM_DESTROY:
131 if(logo)
133 DestroyIcon(logo);
134 logo = NULL;
137 if(titleFont)
139 DeleteObject(titleFont);
140 titleFont = NULL;
143 break;
145 case WM_COMMAND:
146 switch(HIWORD(wParam))
148 case EN_CHANGE:
149 /* enable apply button */
150 SendMessageW(GetParent(hDlg), PSM_CHANGED, 0, 0);
151 break;
153 break;
155 case WM_DRAWITEM:
156 if(wParam == IDC_ABT_PANEL)
158 LPDRAWITEMSTRUCT pDIS = (LPDRAWITEMSTRUCT)lParam;
159 FillRect(pDIS->hDC, &pDIS->rcItem, (HBRUSH) (COLOR_WINDOW+1));
160 DrawIconEx(pDIS->hDC, 0, 0, logo, 0, 0, 0, 0, DI_IMAGE);
161 DrawEdge(pDIS->hDC, &pDIS->rcItem, EDGE_SUNKEN, BF_BOTTOM);
163 break;
165 case WM_CTLCOLORSTATIC:
166 switch(GetDlgCtrlID((HWND)lParam))
168 case IDC_ABT_TITLE_TEXT:
169 /* set the title to a wine color */
170 SetTextColor((HDC)wParam, 0x0000007F);
171 case IDC_ABT_PANEL_TEXT:
172 case IDC_ABT_LICENSE_TEXT:
173 case IDC_ABT_WEB_LINK:
174 return (INT_PTR)CreateSolidBrush(GetSysColor(COLOR_WINDOW));
176 break;
179 return FALSE;