GME
13
|
00001 00002 #include "stdafx.h" 00003 #include "MgaProgressDlg.h" 00004 00005 EXTERN_C IMAGE_DOS_HEADER __ImageBase; 00006 #define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase) 00007 00008 // --------------------------- CMgaProgressDlg 00009 00010 CMgaProgressDlg::CMgaProgressDlg() 00011 { 00012 } 00013 00014 CMgaProgressDlg::~CMgaProgressDlg() 00015 { 00016 if( dlg.m_hWnd != NULL ) 00017 dlg.DestroyWindow(); 00018 } 00019 00020 STDMETHODIMP CMgaProgressDlg::SetTitle(BSTR t) 00021 { 00022 COMTRY 00023 { 00024 title = t; 00025 00026 if( dlg.m_hWnd != NULL ) 00027 dlg.SetWindowText(title); 00028 } 00029 COMCATCH(;) 00030 } 00031 00032 int nIDs[2] = {IDC_STATIC1, IDC_STATIC2}; 00033 00034 STDMETHODIMP CMgaProgressDlg::SetLine(int line, BSTR msg) 00035 { 00036 if( line < 0 || line >= 2 ) 00037 COMRETURN(E_INVALIDARG); 00038 00039 COMTRY 00040 { 00041 lines[line] = msg; 00042 00043 if( dlg.m_hWnd != NULL ) 00044 dlg.GetDlgItem(nIDs[line])->SetWindowText(lines[line]); 00045 } 00046 COMCATCH(;) 00047 } 00048 00049 STDMETHODIMP CMgaProgressDlg::StartProgressDialog(HWND hwndParent) 00050 { 00051 AFX_MANAGE_STATE(AfxGetStaticModuleState()) 00052 00053 CWnd *win = hwndParent == NULL ? AfxGetMainWnd() : CWnd::FromHandle(hwndParent); 00054 // n.b. dlg.Create doesn't load comctl32 6.0 00055 dlg.Attach(CreateDialogW(HINST_THISCOMPONENT, MAKEINTRESOURCE(IDD_PROGRESSDLG), hwndParent, NULL)); 00056 //dlg.Create(IDD_PROGRESSDLG, win); 00057 ASSERT( dlg.m_hWnd != NULL ); 00058 00059 dlg.SetWindowText(title); 00060 dlg.GetDlgItem(nIDs[0])->SetWindowText(lines[0]); 00061 dlg.GetDlgItem(nIDs[1])->SetWindowText(lines[1]); 00062 00063 // center the dialog 00064 if (win->GetSafeHwnd() != NULL) 00065 { 00066 CRect rcOwner, rcDlg, rc; 00067 dlg.GetWindowRect(rcDlg); 00068 win->GetWindowRect(rcOwner); 00069 CopyRect(&rc, &rcOwner); 00070 00071 OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); 00072 OffsetRect(&rc, -rc.left, -rc.top); 00073 OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); 00074 00075 SetWindowPos(dlg.GetSafeHwnd(), HWND_TOP, rcOwner.left + (rc.right / 2), rcOwner.top + (rc.bottom / 2), 0, 0, SWP_NOSIZE); 00076 } 00077 00078 dlg.ShowWindow(SW_SHOWNORMAL); 00079 dlg.UpdateWindow(); 00080 00081 if (hwndParent) 00082 dlg.GetParent()->EnableWindow(FALSE); 00083 00084 return S_OK; 00085 } 00086 00087 STDMETHODIMP CMgaProgressDlg::SetProgress(long completed, long total) 00088 { 00089 if( dlg.m_hWnd == NULL ) 00090 COMRETURN(E_INVALID_USAGE); 00091 00092 CProgressCtrl *ctrl = (CProgressCtrl*)dlg.GetDlgItem(IDC_PROGRESS1); 00093 ASSERT( ctrl != NULL ); 00094 00095 if (total == 0) { 00096 if (!(ctrl->GetStyle() & PBS_MARQUEE)) { 00097 ctrl->ModifyStyle(0, PBS_MARQUEE); 00098 ctrl->SetMarquee(TRUE, 30); 00099 } 00100 } else { 00101 if ((ctrl->GetStyle() & PBS_MARQUEE)) { 00102 ctrl->ModifyStyle(0, PBS_MARQUEE, 0, 0); 00103 ctrl->SetMarquee(FALSE, 30); 00104 } 00105 } 00106 if (!(ctrl->GetStyle() & PBS_MARQUEE)) { 00107 ctrl->SetRange32(0, total); 00108 ctrl->SetPos(completed); 00109 } 00110 00111 //dlg.UpdateWindow(); 00112 MSG msg; 00113 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) > 0) 00114 { 00115 if (msg.message == WM_QUIT) { 00116 PostQuitMessage((int)msg.wParam); 00117 return S_OK; 00118 } 00119 TranslateMessage(&msg); 00120 DispatchMessage(&msg); 00121 } 00122 return S_OK; 00123 } 00124 00125 STDMETHODIMP CMgaProgressDlg::HasUserCancelled(VARIANT_BOOL *p) 00126 { 00127 if( dlg.m_hWnd == NULL ) 00128 COMRETURN(E_INVALID_USAGE); 00129 00130 // *p = dlg.cancelPressed ? VARIANT_TRUE : VARIANT_FALSE; 00131 return S_OK; 00132 } 00133 00134 STDMETHODIMP CMgaProgressDlg::StopProgressDialog() 00135 { 00136 if( dlg.m_hWnd == NULL ) 00137 COMRETURN(E_INVALID_USAGE); 00138 00139 HWND hwndParent = ::GetParent(dlg.GetSafeHwnd()); 00140 if (hwndParent) 00141 ::EnableWindow(hwndParent, TRUE); 00142 00143 HWND hwnd = dlg.m_hWnd; 00144 dlg.Detach(); 00145 ASSERT( dlg.m_hWnd == NULL ); 00146 VERIFY(::DestroyWindow(hwnd)); 00147 00148 return S_OK; 00149 }