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

Annotation of /trunk/Src/wptProgressDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (hide annotations)
Mon Jan 31 11:02:21 2005 UTC (20 years, 1 month ago) by twoaday
File size: 3303 byte(s)
WinPT initial checkin.


1 twoaday 2 /* wptProgressDlg.cpp - Support for the GPG progress status
2     * Copyright (C) 2003, 2004 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     #include <commctrl.h>
23    
24     #include "../resource.h"
25     #include "wptGPG.h"
26     #include "wptTypes.h"
27     #include "wptCommonCtl.h"
28     #include "wptW32API.h"
29     #include "wptContext.h"
30     #include "wptVersion.h"
31    
32     static HWND progress_dlg = NULL;
33    
34     static BOOL CALLBACK
35     progress_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
36     {
37     static progress_filter_s * pfx = NULL;
38    
39     switch (msg) {
40     case WM_INITDIALOG:
41     pfx = (struct progress_filter_s *)lparam;
42     if (!pfx)
43     BUG (0);
44     progress_dlg = dlg;
45     pfx->dlg = dlg;
46     SendDlgItemMessage (dlg, IDC_PROGRESS_BAR, PBM_SETRANGE, 0, MAKELPARAM (0, 100));
47     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_TOTAL, pfx->total, FALSE);
48     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_CURR, pfx->curr, FALSE);
49     SetDlgItemText (pfx->dlg, IDC_PROGRESS_WHAT, pfx->what);
50     center_window2 (dlg, HWND_TOPMOST);
51     center_window (dlg);
52     SetForegroundWindow (dlg);
53     return TRUE;
54     }
55     return FALSE;
56     } /* progress_dlg_proc */
57    
58    
59     static DWORD WINAPI
60     progress_cb_thread (void * opaque)
61     {
62     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PROGRESS, GetActiveWindow (),
63     progress_dlg_proc, (LPARAM)opaque);
64     return TRUE;
65     } /* progress_cb_thread */
66    
67    
68     void
69     progress_cleanup (progress_filter_s * pfx)
70     {
71     EndDialog (progress_dlg, TRUE);
72     if (!pfx)
73     return;
74     if (pfx->dlg) {
75     EndDialog (pfx->dlg, TRUE);
76     pfx->dlg = NULL;
77     }
78     if (pfx->thread_hd) {
79     CloseHandle (pfx->thread_hd);
80     pfx->thread_hd = NULL;
81     }
82     pfx->curr = 0;
83     pfx->total = 0;
84     pfx->error = 0;
85     }
86    
87    
88     void
89     progress_callback (void * opaque, const char * what, int type, unsigned off, unsigned max)
90     {
91     struct progress_filter_s * pfx = (struct progress_filter_s *)opaque;
92     DWORD tid;
93    
94     if (!pfx || pfx->error)
95     return;
96     pfx->curr = off;
97     pfx->total = max;
98     pfx->what = what;
99     if (!off && !pfx->thread_hd) {
100     pfx->thread_hd = CreateThread (NULL, 0, progress_cb_thread, (void *)pfx, 0, &tid);
101     if (!pfx->thread_hd) {
102     msg_box (NULL, _("Could not create progress thread."), _("WinPT"), MB_ERR);
103     pfx->error = 1;
104     return;
105     }
106     }
107     else if (pfx->dlg) {
108     size_t n = pfx->curr * 100 / pfx->total;
109     SendDlgItemMessage (pfx->dlg, IDC_PROGRESS_BAR, PBM_SETPOS, (WPARAM)n, 0);
110     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_CURR, pfx->curr, FALSE);
111     }
112     if (off >= max)
113     progress_cleanup (pfx);
114     } /* progress_callback */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26