set svn:eol-style to native for *.[ch]
[krb5.git] / src / windows / identity / ui / aboutwnd.c
1 /*
2  * Copyright (c) 2005 Massachusetts Institute of Technology
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24
25 /* $Id$ */
26
27 #include<khmapp.h>
28 #include<netidmgr_intver.h>
29 #include<tlhelp32.h>
30
31 #if DEBUG
32 #include<assert.h>
33 #endif
34
35 INT_PTR CALLBACK
36 about_dlg_proc(HWND hwnd,
37                UINT uMsg,
38                WPARAM wParam,
39                LPARAM lParam) {
40
41     switch(uMsg) {
42     case WM_INITDIALOG:
43         {
44             HANDLE hsnap;
45             HWND hw;
46
47             SetDlgItemText(hwnd, IDC_PRODUCT,
48                            TEXT(KH_VERSTR_PRODUCT_1033));
49             /* retain the original copyright strings */
50 #ifdef OVERRIDE_COPYRIGHT
51             SetDlgItemText(hwnd, IDC_COPYRIGHT,
52                            TEXT(KH_VERSTR_COPYRIGHT_1033));
53 #endif
54             SetDlgItemText(hwnd, IDC_BUILDINFO,
55                            TEXT(KH_VERSTR_BUILDINFO_1033));
56
57             hsnap = 
58                 CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,
59                                          0);
60
61             if (hsnap != INVALID_HANDLE_VALUE) {
62                 LVCOLUMN lvc;
63                 MODULEENTRY32 mod;
64                 RECT r;
65
66                 hw = GetDlgItem(hwnd, IDC_MODULES);
67 #ifdef DEBUG
68                 assert(hw != NULL);
69 #endif
70
71                 GetWindowRect(hw, &r);
72                 OffsetRect(&r, -r.left, -r.top);
73
74                 ZeroMemory(&lvc, sizeof(lvc));
75                 lvc.mask = LVCF_TEXT | LVCF_WIDTH;
76
77                 lvc.pszText = L"Name";
78                 lvc.cx = r.right / 4;
79
80                 ListView_InsertColumn(hw, 0, &lvc);
81
82                 lvc.pszText = L"Path";
83                 lvc.cx = (r.right * 3) / 4;
84                 ListView_InsertColumn(hw, 1, &lvc);
85
86                 ZeroMemory(&mod, sizeof(mod));
87                 mod.dwSize = sizeof(mod);
88
89                 /* done with columns, now for the actual data */
90                 if (!Module32First(hsnap, &mod))
91                     goto _done_with_modules;
92
93                 do {
94
95                     LVITEM lvi;
96                     int idx;
97
98                     ZeroMemory(&lvi, sizeof(lvi));
99
100                     lvi.mask = LVIF_TEXT;
101                     lvi.pszText = mod.szModule;
102                     idx = ListView_InsertItem(hw, &lvi);
103
104                     lvi.mask = LVIF_TEXT;
105                     lvi.iItem = idx;
106                     lvi.iSubItem = 1;
107                     lvi.pszText = mod.szExePath;
108                     ListView_SetItem(hw, &lvi);
109
110                     ZeroMemory(&mod, sizeof(mod));
111                     mod.dwSize = sizeof(mod);
112                 } while(Module32Next(hsnap, &mod));
113
114             _done_with_modules:
115                 CloseHandle(hsnap);
116             }
117
118             khm_add_dialog(hwnd);
119             khm_enter_modal(hwnd);
120         }
121         return FALSE;
122
123     case WM_DESTROY:
124         khm_del_dialog(hwnd);
125         return TRUE;
126
127     case WM_CLOSE:
128         khm_leave_modal();
129         DestroyWindow(hwnd);
130         return TRUE;
131
132     case WM_COMMAND:
133         if (wParam == MAKEWPARAM(IDOK, BN_CLICKED)) {
134             khm_leave_modal();
135             DestroyWindow(hwnd);
136         }
137         return TRUE;
138     }
139
140     return FALSE;
141 }
142
143 void
144 khm_create_about_window(void) {
145     HWND hwnd;
146     hwnd = CreateDialog(khm_hInstance,
147                         MAKEINTRESOURCE(IDD_ABOUT),
148                         khm_hwnd_main,
149                         about_dlg_proc);
150
151     ShowWindow(hwnd, SW_SHOW);
152     /* no need to keep track of the hwnd, since we add it to the
153        dialog chain in the dialog procedure */
154 }