/[winpt]/trunk/Src/wptKeygenCBDlg.cpp
ViewVC logotype

Contents of /trunk/Src/wptKeygenCBDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 333 - (show annotations)
Tue Oct 13 10:51:21 2009 UTC (15 years, 4 months ago) by twoaday
File size: 3127 byte(s)


1 /* wptKeygenDlg.cpp - Key callback generation dialog
2 * Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz
3 *
4 * This file is part of WinPT.
5 *
6 * WinPT is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * WinPT 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
14 * GNU General Public License for more details.
15 *
16 */
17 #ifdef HAVE_CONFIG_H
18 #include <config.h>
19 #endif
20
21 #include <windows.h>
22
23 #include "resource.h"
24 #include "wptTypes.h"
25 #include "wptW32API.h"
26 #include "wptVersion.h"
27 #include "wptNLS.h"
28 #include "wptErrors.h"
29
30 /* Handle to the progress dialog. */
31 static HWND dlg_hwnd = NULL;
32
33
34 /* Dialog box param for the keygen progress. */
35 static BOOL CALLBACK
36 keygen_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
37 {
38 switch (msg) {
39 case WM_INITDIALOG:
40 SetDlgItemText (dlg, IDC_KEYPROG_CB, "");
41 SetForegroundWindow (dlg);
42 SetWindowText (dlg, _("Key Generation - Progress Dialog"));
43 center_window (dlg, NULL);
44 dlg_hwnd = dlg;
45 return TRUE;
46
47 case WM_DESTROY:
48 dlg_hwnd = NULL;
49 break;
50 }
51
52 return FALSE;
53 }
54
55
56 /* Thread to start the progress dialog (async). */
57 static DWORD WINAPI
58 keygen_cb_thread (void *opaque)
59 {
60 DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYPROG,
61 GetActiveWindow (), keygen_cb_dlg_proc, 0);
62 ExitThread (0);
63 return 0;
64 }
65
66
67 /* Create the progress thread. */
68 int
69 keygen_cb_dlg_create (void)
70 {
71 DWORD tid;
72 HANDLE thread_hd;
73 SECURITY_ATTRIBUTES sec_attr;
74
75 memset (&sec_attr, 0, sizeof sec_attr);
76 sec_attr.bInheritHandle = FALSE;
77 sec_attr.lpSecurityDescriptor = NULL;
78 sec_attr.nLength = sizeof sec_attr;
79 thread_hd = CreateThread (&sec_attr, 0, keygen_cb_thread, NULL, 0, &tid);
80 if (!thread_hd) {
81 msg_box (NULL, "Could not create key generation thread",
82 _("Key Generation"), MB_ERR);
83 return WPTERR_GENERAL;
84 }
85
86 return 0;
87 }
88
89
90 /* GPGME progress callback function. */
91 void
92 keygen_cb (void *opaque, const char *what, int type, int curretn, int total)
93 {
94 static char cb[8192] = {0};
95 static int cb_pos = 0;
96
97 if (!opaque && !what && !type && !curretn && !total) {
98 memset (cb, 0, sizeof (cb));
99 cb_pos = 0;
100 return;
101 }
102
103 if (cb_pos >= (DIM (cb)-1)) {
104 SetDlgItemText (dlg_hwnd, IDC_KEYPROG_CB, "");
105 cb_pos = 0;
106 }
107 cb[cb_pos] = (char)type;
108 cb_pos++;
109 cb[cb_pos] = '\0';
110
111 SetDlgItemText (dlg_hwnd, IDC_KEYPROG_CB, cb);
112 if (GetForegroundWindow () != dlg_hwnd)
113 SetForegroundWindow (dlg_hwnd);
114 }
115
116
117 /* Destroy the progress dialog and cleanup.
118 If flush is 1 reset the callback state. */
119 void
120 keygen_cb_dlg_destroy (int flush)
121 {
122 if (dlg_hwnd) {
123 EndDialog (dlg_hwnd, TRUE);
124 dlg_hwnd = NULL;
125 }
126 if (flush)
127 keygen_cb (NULL, NULL, 0, 0, 0);
128 }
129

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26