1 /*
2  * Progress dialog
3  *
4  * Copyright 2014              Huw Campbell
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #ifndef _PROGRESSDIALOG_H_
22 #define _PROGRESSDIALOG_H_
23 
24 class CProgressDialog :
25     public CComCoClass<CProgressDialog, &CLSID_ProgressDialog>,
26     public CComObjectRootEx<CComMultiThreadModelNoCS>,
27     public IProgressDialog,
28     public IOleWindow
29 {
30 public:
31     CRITICAL_SECTION cs;
32     HWND hwnd;
33     DWORD dwFlags;
34     DWORD dwUpdate;
35     LPWSTR lines[3];
36     LPWSTR cancelMsg;
37     LPWSTR title;
38     BOOL isCancelled;
39     ULONGLONG ullCompleted;
40     ULONGLONG ullTotal;
41     HWND hwndDisabledParent;
42     void set_progress_marquee();
43     void update_dialog(DWORD dwUpdate);
44     void end_dialog();
45 
46     UINT clockHand;
47     struct progressMark {
48         ULONGLONG ullMark;
49         DWORD     dwTime;
50     };
51     progressMark progressClock[30];
52     DWORD dwStartTime;
53 
54     CProgressDialog();
55     ~CProgressDialog();
56 
57     // IProgressDialog
58     STDMETHOD(StartProgressDialog)(HWND hwndParent, IUnknown *punkEnableModeless, DWORD dwFlags, LPCVOID reserved) override;
59     STDMETHOD(StopProgressDialog)() override;
60     STDMETHOD(SetTitle)(LPCWSTR pwzTitle) override;
61     STDMETHOD(SetAnimation)(HINSTANCE hInstance, UINT uiResourceId) override;
62     STDMETHOD_(BOOL, HasUserCancelled)() override;
63     STDMETHOD(SetProgress64)(ULONGLONG ullCompleted, ULONGLONG ullTotal) override;
64     STDMETHOD(SetProgress)(DWORD dwCompleted, DWORD dwTotal) override;
65     STDMETHOD(SetLine)(DWORD dwLineNum, LPCWSTR pwzLine, BOOL bPath, LPCVOID reserved) override;
66     STDMETHOD(SetCancelMsg)(LPCWSTR pwzMsg, LPCVOID reserved) override;
67     STDMETHOD(Timer)(DWORD dwTimerAction, LPCVOID reserved) override;
68 
69     // IOleWindow
70     STDMETHOD(GetWindow)(HWND* phwnd) override;
71     STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode) override;
72 
73 DECLARE_REGISTRY_RESOURCEID(IDR_PROGRESSDIALOG)
74 DECLARE_NOT_AGGREGATABLE(CProgressDialog)
75 
76 DECLARE_PROTECT_FINAL_CONSTRUCT()
77 
78 BEGIN_COM_MAP(CProgressDialog)
79     COM_INTERFACE_ENTRY_IID(IID_IProgressDialog, IProgressDialog)
80     COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IOleWindow)
81 END_COM_MAP()
82 };
83 
84 #endif /* _PROGRESSDIALOG_H_ */
85