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

Annotation of /trunk/Src/wptKeygenCBDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Fri Sep 30 10:10:16 2005 UTC (19 years, 5 months ago) by twoaday
File size: 3119 byte(s)
Almost finished phase 1 of the WinPT GPGME port.
Still need more cleanup, comments and tests.


1 twoaday 2 /* wptKeygenDlg.cpp - Key callback generation dialog
2 twoaday 23 * Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz
3 twoaday 2 *
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     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
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 twoaday 23 /* Handle to the progress dialog. */
31 twoaday 2 static HWND dlg_hwnd = NULL;
32    
33    
34 twoaday 23 /* Dialog box param for the keygen progress. */
35 twoaday 2 static BOOL CALLBACK
36 twoaday 23 keygen_cb_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
37 twoaday 2 {
38 twoaday 23 switch (msg) {
39 twoaday 2 case WM_INITDIALOG:
40     SetDlgItemText( dlg, IDC_KEYPROG_CB, "" );
41     SetForegroundWindow( dlg );
42 twoaday 23 center_window( dlg, NULL );
43 twoaday 2 dlg_hwnd = dlg;
44     return TRUE;
45 twoaday 23
46     case WM_DESTROY:
47     dlg_hwnd = NULL;
48 twoaday 2 }
49    
50     return FALSE;
51 twoaday 23 }
52 twoaday 2
53    
54 twoaday 23 /* Thread to start the progress dialog (async). */
55 twoaday 2 static DWORD WINAPI
56 twoaday 23 keygen_cb_thread (void *opaque)
57 twoaday 2 {
58 twoaday 23 DialogBoxParam (glob_hinst, (LPCSTR)IDD_WINPT_KEYPROG, GetActiveWindow (),
59     keygen_cb_dlg_proc, NULL);
60     ExitThread (0);
61 twoaday 2 return 0;
62 twoaday 23 }
63 twoaday 2
64    
65 twoaday 23 /* Create the progress thread. */
66 twoaday 2 int
67 twoaday 23 keygen_cb_dlg_create (void)
68 twoaday 2 {
69     DWORD tid;
70     HANDLE thread_hd;
71     SECURITY_ATTRIBUTES sec_attr;
72    
73 twoaday 23 memset (&sec_attr, 0, sizeof sec_attr);
74 twoaday 2 sec_attr.bInheritHandle = FALSE;
75     sec_attr.lpSecurityDescriptor = NULL;
76     sec_attr.nLength = sizeof sec_attr;
77 twoaday 23 thread_hd = CreateThread (&sec_attr, 0, keygen_cb_thread, NULL, 0, &tid);
78     if (!thread_hd) {
79     msg_box (NULL, _("Could not create key generation thread"), _("Key Generation"), MB_ERR);
80 twoaday 2 return WPTERR_GENERAL;
81     }
82    
83     return 0;
84 twoaday 23 }
85 twoaday 2
86 twoaday 23 /* Destroy the progress dialog and cleanup. */
87 twoaday 2 void
88 twoaday 23 keygen_cb_dlg_destroy (void)
89 twoaday 2 {
90 twoaday 23 if (dlg_hwnd) {
91     EndDialog (dlg_hwnd, TRUE);
92 twoaday 2 dlg_hwnd = NULL;
93     }
94 twoaday 23 }
95 twoaday 2
96    
97 twoaday 23 /* GPGME progress callback function. */
98 twoaday 2 void
99 twoaday 23 keygen_cb (void * opaque, const char * what, int type, int curretn, int total)
100 twoaday 2 {
101     static char cb[8192] = {0};
102     static int cb_pos = 0;
103    
104     if (!opaque && !what && !type && !curretn && !total) {
105     memset (cb, 0, sizeof cb);
106     cb_pos = 0;
107     return;
108     }
109    
110     if (cb_pos >= (DIM (cb)-1))
111     cb_pos = 0;
112     cb[cb_pos] = (char)type;
113     cb_pos++;
114     cb[cb_pos] = '\0';
115    
116     SetDlgItemText (dlg_hwnd, IDC_KEYPROG_CB, cb);
117 twoaday 23 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26