1 #include "studiox_includes.h"
2 #include "wait_dialog.h"
3 
4 #ifdef _DEBUG
5 #define new DEBUG_NEW
6 #endif
7 
IMPLEMENT_DYNAMIC(wait_dialog,CDialog)8 IMPLEMENT_DYNAMIC(wait_dialog, CDialog)
9 
10 // wait_dialog
11 BEGIN_MESSAGE_MAP(wait_dialog, CDialog)
12     ON_WM_CREATE()
13     ON_WM_PAINT()
14     ON_WM_SHOWWINDOW()
15     ON_MESSAGE(USR_MSG_DIALOG_VISIBLE, OnDialogVisible)
16 END_MESSAGE_MAP()
17 
18 ///////////////////////////////////////////////////////////////////////////////
19 wait_dialog::wait_dialog(int width, int height, const char *msg, CWnd *parent)
20     : CDialog(wait_dialog::IDD, parent)
21 {
22     m_width = width;
23     m_height = height;
24     mMessage = CString(msg);
25     mIconId = 0;
26     m_work_thread = 0;
27 }
28 
29 ///////////////////////////////////////////////////////////////////////////////
~wait_dialog()30 wait_dialog::~wait_dialog()
31 {
32 }
33 
34 ///////////////////////////////////////////////////////////////////////////////
OnCreate(LPCREATESTRUCT lpCreateStruct)35 int wait_dialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
36 {
37     CDialog::OnCreate(lpCreateStruct);
38 
39     CRect client;
40     CRect size;
41     GetWindowRect(&size);
42 
43     if (m_width > 0)
44     {
45         size.right = size.left + m_width;
46         size.bottom = size.top + m_height;
47         MoveWindow(size);
48     }
49     CenterWindow();
50     GetClientRect(&client);
51 
52     SetWindowText(_T("Wait Dialog"));
53 
54     size = client;
55     size.top += 44;
56     size.right -= 4;
57     size.left += 4;
58     size.bottom -= 4;
59     wait_msg.Create(mMessage, WS_CHILD|WS_VISIBLE|SS_CENTER, size, this);
60     return 0;
61 }
62 ///////////////////////////////////////////////////////////////////////////////
PaintTitleBar(CDC * dc)63 void wait_dialog::PaintTitleBar(CDC *dc)
64 {
65     CRect size;
66     CDC dcMemory;
67     CBitmap fillmap;
68     BITMAP bm;
69 
70     // fill the title bar:
71     fillmap.LoadBitmap(IDB_HEADER_BACKGROUND);
72 
73     // go through hoops to get bitmap width:
74     fillmap.GetObject(sizeof(BITMAP), &bm);
75     int width = bm.bmWidth;
76     int height = bm.bmHeight;
77 
78     dcMemory.CreateCompatibleDC(dc);
79     dcMemory.SelectObject(&fillmap);
80 
81     GetClientRect(&size);
82     int xpos = size.left;
83     while(xpos < size.right)
84     {
85         dc->BitBlt(xpos, size.top, width, height, &dcMemory, 0, 0, SRCCOPY);
86         xpos += width;
87     }
88 
89     // draw the icon in top-left corner:
90     fillmap.DeleteObject();
91 
92     if (mIconId)
93     {
94         fillmap.LoadBitmap(mIconId);
95         fillmap.GetObject(sizeof(BITMAP), &bm);
96         dcMemory.SelectObject(fillmap);
97         dc->BitBlt(size.left + 4, size.top + 4, bm.bmWidth, bm.bmHeight, &dcMemory, 0, 0, SRCCOPY);
98     }
99 
100     // draw the caption
101     dc->SetTextColor(RGB(240, 240, 240));
102     dc->SetBkMode(TRANSPARENT);
103     dc->TextOut(size.left + bm.bmWidth + 8, size.top + 4, _T("Please Wait..."));
104 }
105 
106 ///////////////////////////////////////////////////////////////////////////////
OnPaint()107 void wait_dialog::OnPaint()
108 {
109     CDC *dc = GetDC();
110     CDialog::OnPaint();
111     PaintTitleBar(dc);
112     ReleaseDC(dc);
113 }
114 
115 ///////////////////////////////////////////////////////////////////////////////
OnShowWindow(BOOL bShow,UINT nStatus)116 void wait_dialog::OnShowWindow(BOOL bShow, UINT nStatus)
117 {
118     CDialog::OnShowWindow(bShow, nStatus);
119 
120     PostMessage(USR_MSG_DIALOG_VISIBLE, 0, 0);
121 }
122 
OnDialogVisible(WPARAM wParam,LPARAM lParam)123 LRESULT wait_dialog::OnDialogVisible(WPARAM wParam, LPARAM lParam)
124 {
125     if (m_work_thread)
126     {
127         ResumeThread(m_work_thread);
128     }
129     return 0;
130 }
131