00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "precomp.h"
00028 #include "CCPrintDlg.h"
00029
00030 #include "globals.h"
00031 #include "debug.h"
00032
00033
00041 INT_PTR APIENTRY CCPrintDlg::StaticDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
00042 {
00043
00044 CCPrintDlg* pThis = (CCPrintDlg*) ::GetWindowLong(hDlg, DWLP_USER);
00045
00046 if ((uMsg == WM_INITDIALOG) && (pThis == NULL))
00047 {
00048
00049 pThis = (CCPrintDlg*)lParam;
00050 pThis->m_hDlg = hDlg;
00051 pThis->SetWindowLong(DWLP_USER, (LPARAM)pThis);
00052 }
00053
00054 if (pThis == NULL)
00055 {
00056
00057 switch (uMsg)
00058 {
00059 case WM_SETFONT:
00060 case WM_NOTIFYFORMAT:
00061 case WM_QUERYUISTATE:
00062 return FALSE;
00063 default:
00064
00065 ASSERT(FALSE);
00066 return FALSE;
00067 }
00068 }
00069 else
00070 {
00071
00072 ASSERT(pThis->m_hDlg == hDlg);
00073 }
00074
00075
00076 BOOL bRet = pThis->PageProc(uMsg, wParam, lParam);
00077
00078
00079 if (uMsg == WM_NCDESTROY)
00080 {
00081
00082 pThis->m_hDlg = NULL;
00083
00084 pThis->PostDestroy();
00085 }
00086
00087
00088 return bRet;
00089 }
00090
00095 BOOL CCPrintDlg::GetDlgItemCheck(UINT uID)
00096 {
00097
00098 HWND hWnd = GetDlgItem(uID);
00099 if (hWnd == NULL)
00100 {
00101
00102 ASSERTMSG(FALSE, "GetDlgItemCheck Error: check box not found");
00103 return FALSE;
00104 }
00105
00106 return (SendMessage(hWnd, BM_GETCHECK, 0, 0) == BST_CHECKED);
00107 }
00108
00113 void CCPrintDlg::SetDlgItemCheck(UINT uID, BOOL bCheck)
00114 {
00115
00116 HWND hWnd = GetDlgItem(uID);
00117 if (hWnd == NULL)
00118 {
00119
00120 ASSERTMSG(FALSE, "SetDlgItemCheck Error: check box not found");
00121 return;
00122 }
00123
00124 SendMessage(hWnd, BM_SETCHECK, bCheck ? BST_CHECKED : BST_UNCHECKED , 0);
00125 }
00126
00131 int CCPrintDlg::GetDlgComboCount(UINT uID)
00132 {
00133
00134 HWND hWnd = GetDlgItem(uID);
00135 if (hWnd == NULL)
00136 {
00137
00138 ASSERTMSG(FALSE, "GetDlgComboCount Error: combo box not found");
00139 return FALSE;
00140 }
00141
00142 return (int)SendMessage(hWnd, CB_GETCOUNT, 0, 0);
00143 }
00144
00149 int CCPrintDlg::GetDlgComboSel(UINT uID)
00150 {
00151
00152 HWND hWnd = GetDlgItem(uID);
00153 if (hWnd == NULL)
00154 {
00155
00156 ASSERTMSG(FALSE, "GetDlgComboSel Error: combo box not found");
00157 return FALSE;
00158 }
00159
00160 return (int)SendMessage(hWnd, CB_GETCURSEL, 0, 0);
00161 }
00162
00167 LONG_PTR CCPrintDlg::GetDlgComboSelData(UINT uID)
00168 {
00169
00170 HWND hWnd = GetDlgItem(uID);
00171 if (hWnd == NULL)
00172 {
00173
00174 ASSERTMSG(FALSE, "GetDlgComboSelData Error: combo box not found");
00175 return FALSE;
00176 }
00177
00178 int nSel = (int)SendMessage(hWnd, CB_GETCURSEL, 0, 0);
00179 if (nSel == CB_ERR)
00180
00181 return 0;
00182
00183
00184 return SendMessage(hWnd, CB_GETITEMDATA, nSel, 0);
00185 }
00186
00191 std::tstring CCPrintDlg::GetDlgComboText(UINT uID)
00192 {
00193 std::tstring sRet;
00194
00195
00196 HWND hWnd = GetDlgItem(uID);
00197 if (hWnd == NULL)
00198 {
00199
00200 ASSERTMSG(FALSE, "GetDlgComboSelData Error: combo box not found");
00201 return sRet;
00202 }
00203
00204 int nSel = (int)SendMessage(hWnd, CB_GETCURSEL, 0, 0);
00205 if (nSel == CB_ERR)
00206
00207 return sRet;
00208
00209
00210 int nLen = (int)SendMessage(hWnd, CB_GETLBTEXTLEN, nSel, 0);
00211 if (nLen < 1)
00212
00213 return sRet;
00214
00215
00216 TCHAR* pStr = new TCHAR[nLen + 1];
00217 if (SendMessage(hWnd, CB_GETLBTEXT, nSel, (LPARAM)pStr) != nLen)
00218 {
00219
00220 delete [] pStr;
00221 return sRet;
00222 }
00223
00224
00225 sRet.assign(pStr, nLen);
00226 delete [] pStr;
00227 return sRet;
00228 }
00229
00234 void CCPrintDlg::SetDlgComboItem(UINT uID, int nItem)
00235 {
00236
00237 HWND hWnd = GetDlgItem(uID);
00238 if (hWnd == NULL)
00239 {
00240
00241 ASSERTMSG(FALSE, "SetDlgComboItem Error: combo box not found");
00242 return;
00243 }
00244
00245 SendMessage(hWnd, CB_SETCURSEL, nItem, 0);
00246 }
00247
00252 void CCPrintDlg::SetDlgComboSel(UINT uID, DWORD dwData)
00253 {
00254
00255 HWND hWnd = GetDlgItem(uID);
00256 if (hWnd == NULL)
00257 {
00258
00259 ASSERTMSG(FALSE, "SetDlgComboSel Error: combo box not found");
00260 return;
00261 }
00262
00263 int nCount = (int)SendMessage(hWnd, CB_GETCOUNT, 0, 0);
00264 if (nCount == CB_ERR)
00265
00266 return;
00267
00268
00269 for (int i = 0; i < nCount; i++)
00270 {
00271
00272 if (dwData == (DWORD)SendMessage(hWnd, CB_GETITEMDATA, i, 0))
00273 {
00274
00275 SendMessage(hWnd, CB_SETCURSEL, i, 0);
00276 return;
00277 }
00278 }
00279 }
00280
00285 void CCPrintDlg::SetDlgComboSel(UINT uID, LPCTSTR lpString)
00286 {
00287
00288 HWND hWnd = GetDlgItem(uID);
00289 if (hWnd == NULL)
00290 {
00291
00292 ASSERTMSG(FALSE, "SetDlgComboSel Error: combo box not found");
00293 return;
00294 }
00295
00296 int nCount = (int) SendMessage(hWnd, CB_GETCOUNT, 0, 0);
00297 if (nCount == CB_ERR)
00298
00299 return;
00300 int nLen = 64, nCurrentLen;
00301 TCHAR* pStr = new TCHAR[nLen];
00302
00303 int i;
00304 for (i = 0; i < nCount; i++)
00305 {
00306
00307 nCurrentLen = (int)SendMessage(hWnd, CB_GETLBTEXTLEN, i, 0) + 1;
00308 if (nCurrentLen < 2)
00309
00310 continue;
00311
00312 if (nCurrentLen > nLen)
00313 {
00314
00315 while (nLen < nCurrentLen)
00316 nLen *= 2;
00317
00318 delete [] pStr;
00319 pStr = new TCHAR[nLen];
00320 }
00321
00322 if (SendMessage(hWnd, CB_GETLBTEXT, i, (LPARAM)pStr) != nCurrentLen - 1)
00323
00324 continue;
00325
00326
00327 pStr[nCurrentLen - 1] = '\0';
00328 if (_tcscmp(pStr, lpString) == 0)
00329
00330 break;
00331 }
00332 delete [] pStr;
00333 if (i == nCount)
00334
00335 return;
00336
00337 SendMessage(hWnd, CB_SETCURSEL, i, 0);
00338 }
00339
00345 void CCPrintDlg::AddDlgComboString(UINT uID, UINT uStringID, DWORD dwData)
00346 {
00347
00348 std::tstring sStr = LoadResourceString(uStringID);
00349 if (sStr.empty())
00350
00351 return;
00352
00353
00354 AddDlgComboString(uID, sStr.c_str(), dwData);
00355 }
00356
00362 void CCPrintDlg::AddDlgComboString(UINT uID, LPCTSTR lpString, DWORD dwData)
00363 {
00364
00365 HWND hWnd = GetDlgItem(uID);
00366 if (hWnd == NULL)
00367 {
00368
00369 ASSERTMSG(FALSE, "AddDlgComboString Error: combo box not found");
00370 return;
00371 }
00372
00373 int nItem = (int) SendMessage(hWnd, CB_ADDSTRING, 0, (LPARAM)lpString);
00374 if (nItem == CB_ERR)
00375 {
00376
00377 ASSERTMSG(FALSE, "AddDlgComboString Error: could not add string");
00378 return;
00379 }
00380
00381 if (dwData != 0)
00382 SendMessage(hWnd, CB_SETITEMDATA, nItem, dwData);
00383 }
00384
00388 void CCPrintDlg::CleanDlgCombo(UINT uID)
00389 {
00390
00391 HWND hWnd = GetDlgItem(uID);
00392 if (hWnd == NULL)
00393 {
00394
00395 ASSERTMSG(FALSE, "AddDlgComboString Error: combo box not found");
00396 return;
00397 }
00398
00399 SendMessage(hWnd, CB_RESETCONTENT, 0, 0);
00400 }
00401
00407 int CCPrintDlg::GetCheckedRadioBtn(UINT uIDStart, UINT uIDEnd)
00408 {
00409
00410 ASSERT(uIDStart <= uIDEnd);
00411
00412 for (UINT uID = uIDStart; uID <= uIDEnd; uID++)
00413 {
00414
00415 if (IsDlgButtonChecked(m_hDlg, uID))
00416
00417 return uID - uIDStart;
00418 }
00419
00420
00421 return -1;
00422 }
00423
00428 int CCPrintDlg::DoModal(HWND hParent)
00429 {
00430 return (int) DialogBoxParam(ghInstance, MAKEINTRESOURCE(m_uResourceID), hParent, StaticDlgProc, (LPARAM)this);
00431 }
00432
00439 BOOL CCPrintDlg::PageProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
00440 {
00441 switch (uMsg)
00442 {
00443 case WM_COMMAND:
00444
00445 switch(HIWORD(wParam))
00446 {
00447 case BN_CLICKED:
00448
00449 switch(LOWORD(wParam))
00450 {
00451 case IDCANCEL:
00452 case IDOK:
00453
00454 EndDialog(m_hDlg, LOWORD(wParam));
00455 return TRUE;
00456 }
00457 break;
00458 }
00459 break;
00460 }
00461
00462
00463 return FALSE;
00464 }