1 |
twoaday |
2 |
/* wptKeygenDlg.cpp - Key callback generation dialog |
2 |
|
|
* Copyright (C) 2001, 2002, 2003 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 |
|
|
* 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 |
|
|
static HWND dlg_hwnd = NULL; |
31 |
|
|
static int dlg_init = 0; |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
static BOOL CALLBACK |
35 |
|
|
keygen_cb_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam ) |
36 |
|
|
{ |
37 |
|
|
switch( msg ) { |
38 |
|
|
case WM_INITDIALOG: |
39 |
|
|
SetDlgItemText( dlg, IDC_KEYPROG_CB, "" ); |
40 |
|
|
SetForegroundWindow( dlg ); |
41 |
|
|
center_window( dlg ); |
42 |
|
|
dlg_hwnd = dlg; |
43 |
|
|
return TRUE; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
return FALSE; |
47 |
|
|
} /* keygen_cb_dlg_proc */ |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
static DWORD WINAPI |
51 |
|
|
keygen_cb_thread( void *opaque ) |
52 |
|
|
{ |
53 |
|
|
DialogBoxParam( glob_hinst, (LPCSTR)IDD_WINPT_KEYPROG, GetActiveWindow(), |
54 |
|
|
keygen_cb_dlg_proc, NULL ); |
55 |
|
|
ExitThread( 0 ); |
56 |
|
|
return 0; |
57 |
|
|
} /* keygen_cb_dlg_thread */ |
58 |
|
|
|
59 |
|
|
|
60 |
|
|
int |
61 |
|
|
keygen_cb_dlg_create( void ) |
62 |
|
|
{ |
63 |
|
|
DWORD tid; |
64 |
|
|
HANDLE thread_hd; |
65 |
|
|
SECURITY_ATTRIBUTES sec_attr; |
66 |
|
|
|
67 |
|
|
if( dlg_init == 1 ) |
68 |
|
|
return 0; |
69 |
|
|
|
70 |
|
|
memset( &sec_attr, 0, sizeof sec_attr ); |
71 |
|
|
sec_attr.bInheritHandle = FALSE; |
72 |
|
|
sec_attr.lpSecurityDescriptor = NULL; |
73 |
|
|
sec_attr.nLength = sizeof sec_attr; |
74 |
|
|
thread_hd = CreateThread( &sec_attr, 0, keygen_cb_thread, NULL, 0, &tid ); |
75 |
|
|
if( !thread_hd ) { |
76 |
|
|
msg_box( NULL, _("Could not create key generation thread"), _("Key Generation"), MB_ERR ); |
77 |
|
|
return WPTERR_GENERAL; |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
return 0; |
81 |
|
|
} /* keygen_cb_dlg_create */ |
82 |
|
|
|
83 |
|
|
void |
84 |
|
|
keygen_cb_dlg_destroy( void ) |
85 |
|
|
{ |
86 |
|
|
if( dlg_hwnd ) { |
87 |
|
|
EndDialog( dlg_hwnd, TRUE ); |
88 |
|
|
dlg_hwnd = NULL; |
89 |
|
|
} |
90 |
|
|
} /* keygen_cb_dlg_destroy */ |
91 |
|
|
|
92 |
|
|
|
93 |
|
|
void |
94 |
|
|
keygen_cb (void * opaque, const char * what, int type, unsigned curretn, unsigned total) |
95 |
|
|
{ |
96 |
|
|
static char cb[8192] = {0}; |
97 |
|
|
static int cb_pos = 0; |
98 |
|
|
|
99 |
|
|
if (!opaque && !what && !type && !curretn && !total) { |
100 |
|
|
memset (cb, 0, sizeof cb); |
101 |
|
|
cb_pos = 0; |
102 |
|
|
return; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
if (cb_pos >= (DIM (cb)-1)) |
106 |
|
|
cb_pos = 0; |
107 |
|
|
cb[cb_pos] = (char)type; |
108 |
|
|
cb_pos++; |
109 |
|
|
cb[cb_pos] = '\0'; |
110 |
|
|
|
111 |
|
|
SetDlgItemText (dlg_hwnd, IDC_KEYPROG_CB, cb); |
112 |
|
|
} /* keygen_cb */ |