6 #include <WINNT/al_wizard.h>
10 * DEFINITIONS ________________________________________________________________
14 #define REFRESH_LEFT_PANE 0x00000001
15 #define REFRESH_RIGHT_PANE 0x00000002
17 #define cxRECT(_r) ((_r).right - (_r).left)
18 #define cyRECT(_r) ((_r).bottom - (_r).top)
20 #define clrWASH_SOLID RGB(0,0,128)
21 #define clrWASH_BRIGHTEST RGB(0,0,252)
22 #define clrWASH_DARKEST RGB(0,0,4)
23 #define clrWASH_INCREMENT RGB(0,0,4)
24 #define clrWASH_TEXT_BG RGB(0,0,0)
25 #define clrWASH_TEXT_FG RGB(255,255,255)
27 #define ToPALETTERGB(_rgb) PALETTERGB(GetRValue(_rgb),GetGValue(_rgb),GetBValue(_rgb))
29 #define cxLEFT_BACKGROUND 20
30 #define cxRIGHT_BACKGROUND 20
31 #define cyTOP_BACKGROUND 20
32 #define cyBOTTOM_BACKGROUND 20
39 #define cptWASH_TEXT_SIZE 20
43 * PROTOTYPES _________________________________________________________________
47 static void MoveRect (RECT *_pr, LONG _dx, LONG _dy);
48 static void GetRectInParent (HWND hWnd, RECT *pr);
52 * ROUTINES ___________________________________________________________________
65 m_bmpGraphic16 = NULL;
67 m_bmpGraphic256 = NULL;
78 m_fnBackground = NULL;
79 m_szBackground[0] = TEXT('\0');
80 m_bmpBackground = NULL;
83 SetRectEmpty (&m_rBuffer);
85 HDC hdc = GetDC (NULL);
87 memset (&lf, 0x00, sizeof(lf));
88 GetObject (GetStockObject (DEFAULT_GUI_FONT), sizeof(lf), &lf);
89 lf.lfHeight = -MulDiv (cptWASH_TEXT_SIZE, GetDeviceCaps (hdc, LOGPIXELSY), 72);
91 m_hfBackground = CreateFontIndirect (&lf);
92 ReleaseDC (NULL, hdc);
98 WIZARD::~WIZARD (void)
100 if (m_hWnd && IsWindow (m_hWnd))
101 DestroyWindow (m_hWnd);
102 if (m_bmpGraphic16 != NULL)
103 DeleteObject (m_bmpGraphic16);
104 if (m_bmpGraphic256 != NULL)
105 DeleteObject (m_bmpGraphic256);
106 if (m_bmpBuffer != NULL)
107 DeleteObject (m_bmpBuffer);
108 if (m_palGraphic != NULL)
109 DeleteObject (m_palGraphic);
110 if (m_bmpBackground != NULL)
111 DeleteObject (m_bmpBackground);
112 if (m_hfBackground != NULL)
113 DeleteObject (m_hfBackground);
117 HWND WIZARD::GetWindow (void)
119 if (m_hWnd && IsWindow (m_hWnd))
125 LPWIZARD WIZARD::GetWizard (HWND hWnd)
127 LPWIZARD pWiz = NULL;
130 if ((pWiz = (LPWIZARD)GetWindowLong (hWnd, DWL_USER)) != NULL)
132 if ( (pWiz->m_hWnd != hWnd) && (pWiz->m_hBkg != hWnd) )
143 void WIZARD::SetDialogTemplate (int iddTemplate, int idcLeftPane, int idcRightPane, int idcBack, int idcNext)
145 m_iddTemplate = iddTemplate;
146 m_idcLeftPane = idcLeftPane;
147 m_idcRightPane = idcRightPane;
159 void WIZARD::SetGraphic (int idbGraphic16, int idbGraphic256)
161 LPRGBQUAD pargb = NULL;
163 m_idbGraphic16 = idbGraphic16;
164 m_idbGraphic256 = idbGraphic256;
166 if (m_bmpGraphic16 != NULL)
168 DeleteObject (m_bmpGraphic16);
169 m_bmpGraphic16 = NULL;
172 if (m_bmpGraphic256 != NULL)
174 DeleteObject (m_bmpGraphic256);
175 m_bmpGraphic256 = NULL;
178 if (m_palGraphic != NULL)
180 DeleteObject (m_palGraphic);
184 m_bmpGraphic16 = (HBITMAP)TaLocale_LoadImage (idbGraphic16, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
186 if ((m_bmpGraphic256 = (HBITMAP)TaLocale_LoadImage (idbGraphic256, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)) != NULL)
189 GetObject (m_bmpGraphic256, sizeof(BITMAP), &bm);
191 if ((bm.bmBitsPixel * bm.bmPlanes) == 8)
193 HDC hdc = CreateCompatibleDC (NULL);
194 HBITMAP bmpOld = (HBITMAP)SelectObject (hdc, m_bmpGraphic256);
197 GetDIBColorTable (hdc, 0, 256, argb);
200 SelectObject (hdc, bmpOld);
205 GeneratePalette (pargb);
209 Refresh (REFRESH_LEFT_PANE);
214 void WIZARD::SetGraphicCallback (void (CALLBACK *pfnCallback)(LPWIZARD pWiz, HDC hdcTarget, LPRECT prTarget, HPALETTE hPal))
216 m_pfnCallback = pfnCallback;
220 Refresh (REFRESH_LEFT_PANE);
225 void WIZARD::SetStates (LPWIZARD_STATE aStates, size_t cStates)
232 Refresh (REFRESH_RIGHT_PANE);
237 int WIZARD::GetState (void)
243 void WIZARD::SetState (int stNew, BOOL fForce)
245 SendStateCommand (m_stCurrent, wcSTATE_LEAVE);
247 int stOriginal = m_stCurrent;
250 if (!fForce && SendStateCommand (stNew, wcIS_STATE_DISABLED))
252 if (stOriginal <= stNew)
254 for (int st = stNew+1; st < (int)m_cStates; ++st)
256 LPWIZARD_STATE pState;
257 if ((pState = FindState (st)) != NULL)
260 if (!SendStateCommand (st, wcIS_STATE_DISABLED))
262 m_stCurrent = stOriginal;
263 SendStateCommand (st, wcSTATE_ENTER);
264 SendStateCommand (st, wcSTATE_LEAVE);
267 stNew = (st < (int)m_cStates) ? st : m_stCurrent;
269 else // (moving backwards?)
271 for (int st = stNew-1; st >= 0; --st)
273 LPWIZARD_STATE pState;
274 if ((pState = FindState (st)) != NULL)
277 if (!SendStateCommand (st, wcIS_STATE_DISABLED))
279 m_stCurrent = stOriginal;
280 SendStateCommand (st, wcSTATE_ENTER);
281 SendStateCommand (st, wcSTATE_LEAVE);
284 stNew = (st >= 0) ? st : m_stCurrent;
290 SendStateCommand (m_stCurrent, wcSTATE_ENTER);
294 Refresh (REFRESH_RIGHT_PANE);
299 BOOL WIZARD::Show (BOOL fShowReq)
301 if (m_fShowing && !fShowReq)
304 if (m_hWnd && IsWindow (m_hWnd))
305 DestroyWindow (m_hWnd);
308 else if (!m_fShowing && fShowReq)
310 if (m_iddTemplate == -1)
312 if (m_idcLeftPane == -1)
314 if (m_idcRightPane == -1)
321 if ((m_hWnd = ModelessDialogParam (m_iddTemplate, m_hBkg, (DLGPROC)WIZARD::Template_DlgProc, (LPARAM)this)) == NULL)
326 while (GetMessage (&msg, 0, 0, NULL))
328 if (!IsDialogMessage (m_hWnd, &msg))
330 TranslateMessage (&msg);
331 DispatchMessage (&msg);
334 if (!m_fShowing || !m_hWnd || !IsWindow (m_hWnd))
343 void WIZARD::EnableButton (int idcButton, BOOL fEnable)
345 EnableWindow (GetDlgItem (m_hWnd, idcButton), fEnable);
349 void WIZARD::EnableButtons (DWORD dwButtonFlags)
351 EnableWindow (GetDlgItem (m_hWnd, m_idcBack), (dwButtonFlags & BACK_BUTTON) ? TRUE : FALSE);
352 EnableWindow (GetDlgItem (m_hWnd, m_idcNext), (dwButtonFlags & NEXT_BUTTON) ? TRUE : FALSE);
356 void WIZARD::SetButtonText (int idcButton, int idsText)
359 if ((hButton = GetDlgItem (m_hWnd, idcButton)) != NULL)
361 TCHAR szText[ cchRESOURCE ];
362 GetString (szText, idsText);
363 SetWindowText (hButton, szText);
368 void WIZARD::SetDefaultControl (int idc)
371 if ((hControl = GetDlgItem (m_hWnd, idc)) == NULL)
374 if ((hRHS = GetRightHandWindow()) != NULL)
375 hControl = GetDlgItem (hRHS, idc);
380 PostMessage (m_hWnd, WM_NEXTDLGCTL, (WPARAM)hControl, TRUE);
385 void WIZARD::SetBackground (int iddBackground, BOOL fBlue, DLGPROC dlgproc)
387 m_iddBackground = iddBackground;
389 m_fnBackground = dlgproc;
391 if (m_hBkg && IsWindow (m_hBkg))
393 ShowBackground (FALSE);
394 ShowBackground (TRUE);
399 void WIZARD::SetBackgroundText (int idsText, HFONT hf)
401 GetString (m_szBackground, idsText);
403 if ((hf != NULL) && (hf != m_hfBackground))
405 if (m_hfBackground != NULL)
406 DeleteObject (m_hfBackground);
410 if (m_hBkg && IsWindow (m_hBkg))
417 void WIZARD::SetBackgroundText (LPTSTR pszText, HFONT hf)
420 m_szBackground[0] = TEXT('\0');
422 lstrcpy (m_szBackground, pszText);
424 if ((hf != NULL) && (hf != m_hfBackground))
426 if (m_hfBackground != NULL)
427 DeleteObject (m_hfBackground);
431 if (m_hBkg && IsWindow (m_hBkg))
438 BOOL WIZARD::ShowBackground (BOOL fShow)
440 if (!fShow && m_hBkg && IsWindow (m_hBkg))
442 DestroyWindow (m_hBkg);
445 else if (fShow && !(m_hBkg && IsWindow (m_hBkg)))
447 if ((m_hBkg = ModelessDialogParam (m_iddBackground, NULL, (DLGPROC)WIZARD::Background_DlgProc, (LPARAM)this)) == NULL)
451 SystemParametersInfo (SPI_GETWORKAREA, 0, &rDesktop, 0);
454 wpl.length = sizeof(wpl);
456 wpl.showCmd = (GetWindowLong (m_hBkg, GWL_STYLE) & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOW;
457 wpl.ptMinPosition.x = 0;
458 wpl.ptMinPosition.y = 0;
459 wpl.ptMaxPosition.x = 0;
460 wpl.ptMaxPosition.y = 0;
461 wpl.rcNormalPosition.left = rDesktop.left + cxLEFT_BACKGROUND;
462 wpl.rcNormalPosition.right = rDesktop.right - cxRIGHT_BACKGROUND;
463 wpl.rcNormalPosition.top = rDesktop.top + cyTOP_BACKGROUND;
464 wpl.rcNormalPosition.bottom = rDesktop.bottom - cyBOTTOM_BACKGROUND;
465 SetWindowPlacement (m_hBkg, &wpl);
472 HWND WIZARD::GetBackgroundWindow (void)
478 void WIZARD::Refresh (DWORD dwRefFlags)
480 if (dwRefFlags & REFRESH_LEFT_PANE)
483 if ((hLHS = GetDlgItem (m_hWnd, m_idcLeftPane)) != NULL)
486 GetClientRect (hLHS, &rr);
487 InvalidateRect (hLHS, &rr, TRUE);
492 if (dwRefFlags & REFRESH_RIGHT_PANE)
495 if ((hRHS = GetDlgItem (m_hWnd, m_idcRightPane)) != NULL)
497 HWND hOld = GetRightHandWindow();
499 LPWIZARD_STATE pState;
500 if ((pState = FindState (m_stCurrent)) != NULL)
502 int stCurrent = m_stCurrent;
505 if ((hNew = ModelessDialogParam (pState->idd, m_hWnd, pState->dlgproc, pState->lp)) != NULL)
507 if (stCurrent != m_stCurrent)
508 DestroyWindow (hNew);
512 GetRectInParent (hRHS, &rRHS);
513 SetWindowPos (hNew, NULL, rRHS.left, rRHS.top, cxRECT(rRHS), cyRECT(rRHS), SWP_NOZORDER | SWP_NOACTIVATE);
514 SetWindowLong (hNew, GWL_ID, pState->idd);
516 ShowWindow (hNew, SW_SHOW);
517 ShowWindow (hRHS, SW_HIDE);
523 DestroyWindow (hOld);
529 HWND WIZARD::GetRightHandWindow (void)
531 if (!m_fShowing || !m_hWnd || !IsWindow (m_hWnd))
536 for (HWND hFound = ::GetWindow (m_hWnd, GW_CHILD);
538 hFound = ::GetWindow (hFound, GW_HWNDNEXT))
540 TCHAR szClassName[ cchRESOURCE ];
541 if (GetClassName (hFound, szClassName, cchRESOURCE))
543 if (!lstrcmp (szClassName, TEXT("#32770"))) // WC_DIALOG
545 if (!hRHS || IsWindowVisible(hRHS))
555 void WIZARD::GeneratePalette (LPRGBQUAD argb)
557 HDC hdc = GetDC (NULL);
558 WORD wDepthDisplay = (WORD)GetDeviceCaps (hdc, BITSPIXEL);
559 ReleaseDC (NULL, hdc);
561 if (wDepthDisplay == 8)
563 BYTE aPalBuffer[ sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY) ];
564 LPLOGPALETTE pPal = (LPLOGPALETTE)aPalBuffer;
565 pPal->palVersion = 0x300;
566 pPal->palNumEntries = 256;
568 for (size_t ii = 0; ii < 256; ++ii)
570 pPal->palPalEntry[ ii ].peRed = (argb) ? argb[ ii ].rgbRed : 0;
571 pPal->palPalEntry[ ii ].peGreen = (argb) ? argb[ ii ].rgbGreen : 0;
572 pPal->palPalEntry[ ii ].peBlue = (argb) ? argb[ ii ].rgbBlue : 0;
573 pPal->palPalEntry[ ii ].peFlags = 0;
576 for (COLORREF clr = clrWASH_DARKEST; clr <= clrWASH_BRIGHTEST; clr += clrWASH_INCREMENT)
578 for (size_t ii = 0; ii < 256; ++ii)
580 if ( (pPal->palPalEntry[ ii ].peRed == GetRValue (clr)) &&
581 (pPal->palPalEntry[ ii ].peGreen == GetGValue (clr)) &&
582 (pPal->palPalEntry[ ii ].peBlue == GetBValue (clr)) )
587 for (size_t ii = 10; ii < 246; ++ii)
589 if ( (pPal->palPalEntry[ ii ].peRed == 0) &&
590 (pPal->palPalEntry[ ii ].peGreen == 0) &&
591 (pPal->palPalEntry[ ii ].peBlue == 0) )
593 if ( (pPal->palPalEntry[ ii ].peRed == 255) &&
594 (pPal->palPalEntry[ ii ].peGreen == 255) &&
595 (pPal->palPalEntry[ ii ].peBlue == 255) )
601 pPal->palPalEntry[ ii ].peRed = GetRValue (clr);
602 pPal->palPalEntry[ ii ].peGreen = GetGValue (clr);
603 pPal->palPalEntry[ ii ].peBlue = GetBValue (clr);
607 m_palGraphic = CreatePalette (pPal);
612 LPWIZARD_STATE WIZARD::FindState (int stFind)
614 for (size_t ii = 0; ii < m_cStates; ++ii)
616 if (m_aStates[ ii ].st == stFind)
617 return &m_aStates[ ii ];
623 BOOL WIZARD::SendStateCommand (int st, WIZARD_COMMAND wc)
627 LPWIZARD_STATE pState;
628 if ((pState = FindState (st)) != NULL)
630 rc = CallWindowProc ((WNDPROC)(pState->dlgproc), NULL, WM_COMMAND, MAKEWPARAM(IDC_WIZARD,(WORD)wc), (LPARAM)this);
637 BOOL CALLBACK WIZARD::Template_DlgProc (HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
639 if (msg == WM_INITDIALOG)
640 SetWindowLong (hWnd, DWL_USER, lp);
642 LPWIZARD pWiz = (LPWIZARD)GetWindowLong (hWnd, DWL_USER);
648 pWiz->Template_OnInitDialog (hWnd);
652 if (pWiz && (pWiz->m_hWnd == hWnd))
657 return pWiz->Template_ForwardMessage (hWnd, msg, wp, lp);
664 BOOL CALLBACK WIZARD::Template_LeftPaneHook (HWND hLHS, UINT msg, WPARAM wp, LPARAM lp)
666 PVOID oldProc = Subclass_FindNextHook (hLHS, WIZARD::Template_LeftPaneHook);
672 if ((pWiz = WIZARD::GetWizard (GetParent (hLHS))) != NULL)
674 if (pWiz->Template_OnPaintLHS (hLHS))
680 Subclass_RemoveHook (hLHS, WIZARD::Template_LeftPaneHook);
685 return CallWindowProc ((WNDPROC)oldProc, hLHS, msg, wp, lp);
687 return DefWindowProc (hLHS, msg, wp, lp);
691 BOOL WIZARD::Template_ForwardMessage (HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
694 if ((hRHS = GetRightHandWindow()) != NULL)
695 return SendMessage (hRHS, msg, wp, lp);
697 LPWIZARD_STATE pState;
698 if ((pState = FindState (m_stCurrent)) != NULL)
699 return CallWindowProc ((WNDPROC)(pState->dlgproc), hWnd, msg, wp, lp);
705 void WIZARD::Template_OnInitDialog (HWND hWnd)
711 if ((hLHS = GetDlgItem (m_hWnd, m_idcLeftPane)) != NULL)
713 Subclass_AddHook (hLHS, WIZARD::Template_LeftPaneHook);
717 if ((hRHS = GetDlgItem (m_hWnd, m_idcRightPane)) != NULL)
719 ShowWindow (hRHS, SW_HIDE);
722 Refresh (REFRESH_RIGHT_PANE);
724 ShowWindow (m_hWnd, SW_SHOW);
728 BOOL WIZARD::Template_OnPaintLHS (HWND hLHS)
730 BOOL fShow16 = FALSE;
731 BOOL fShow256 = FALSE;
733 HDC hdc = GetDC (NULL);
734 WORD wDepthDisplay = (WORD)GetDeviceCaps (hdc, BITSPIXEL);
735 ReleaseDC (NULL, hdc);
737 if ( (m_bmpGraphic256 != NULL) && (wDepthDisplay >= 8) )
739 else if (m_bmpGraphic16 != NULL)
746 if ((hdcTarget = BeginPaint (hLHS, &ps)) != NULL)
748 HBITMAP bmpSource = (fShow256) ? m_bmpGraphic256 : m_bmpGraphic16;
751 GetObject (bmpSource, sizeof(BITMAP), &bm);
754 GetClientRect (hLHS, &rWindow);
756 RECT rSource = { 0, 0, bm.bmWidth, bm.bmHeight };
757 RECT rTarget = rWindow;
759 if (cxRECT(rSource) > cxRECT(rTarget))
761 MoveRect (&rSource, (cxRECT(rSource) - cxRECT(rTarget)) / 2, 0);
762 rSource.right = rSource.left + cxRECT(rTarget);
764 else if (cxRECT(rSource) < cxRECT(rTarget))
766 MoveRect (&rTarget, (cxRECT(rTarget) - cxRECT(rSource)) / 2, 0);
769 if (cyRECT(rSource) > cyRECT(rTarget))
771 MoveRect (&rSource, 0, (cyRECT(rSource) - cyRECT(rTarget)) / 2);
772 rSource.bottom = rSource.top + cyRECT(rTarget);
774 else if (cyRECT(rSource) < cyRECT(rTarget))
776 MoveRect (&rTarget, 0, (cyRECT(rTarget) - cyRECT(rSource)) / 2);
778 rTarget.right = rTarget.left + cxRECT(rSource);
779 rTarget.bottom = rTarget.top + cyRECT(rSource);
781 // If the user has supplied a custom draw-proc, then we should
782 // do our rendering to an off-screen bitmap.
784 HDC hdcFinalTarget = NULL;
785 HBITMAP bmpTempTarget = NULL;
788 // First make sure our offscreen buffer is large enough
790 if (!m_bmpBuffer || (cxRECT(m_rBuffer) < cxRECT(rWindow)) || (cyRECT(m_rBuffer) < cyRECT(rWindow)))
792 if (m_bmpBuffer != NULL)
793 DeleteObject (m_bmpBuffer);
794 if ((m_bmpBuffer = CreateCompatibleBitmap (hdcTarget, cxRECT(rWindow), cyRECT(rWindow))) != NULL)
796 m_rBuffer.right = cxRECT(rWindow); // m_rBuffer.left=already 0
797 m_rBuffer.bottom = cyRECT(rWindow); // m_rBuffer.top=already 0
801 // Then set up to double-buffer, if possible
805 hdcFinalTarget = hdcTarget;
806 hdcTarget = CreateCompatibleDC (hdcFinalTarget);
807 bmpTempTarget = (HBITMAP)SelectObject (hdcTarget, m_bmpBuffer);
811 HDC hdcSource = CreateCompatibleDC (hdcTarget);
812 HBITMAP bmpOld = (HBITMAP)SelectObject (hdcSource, bmpSource);
813 HPALETTE palOld = NULL;
814 if ((wDepthDisplay == 8) && (m_palGraphic != NULL) && (fShow256))
816 palOld = SelectPalette (hdcTarget, m_palGraphic, FALSE);
817 RealizePalette (hdcTarget);
820 if ( (bm.bmWidth < cxRECT(rWindow)) || (bm.bmHeight < cyRECT(rWindow)) )
822 COLORREF clrFill = GetPixel (hdcSource, 0, rSource.bottom -1);
823 clrFill = ToPALETTERGB(clrFill);
824 HBRUSH hbrFill = CreateSolidBrush (clrFill);
826 if (bm.bmWidth < cxRECT(rWindow))
830 rr.right = rTarget.left;
831 FillRect (hdcTarget, &rr, hbrFill);
834 rr.left = rTarget.right;
835 FillRect (hdcTarget, &rr, hbrFill);
838 if (bm.bmHeight < cyRECT(rWindow))
842 rr.bottom = rTarget.top;
843 FillRect (hdcTarget, &rr, hbrFill);
846 rr.top = rTarget.bottom;
847 FillRect (hdcTarget, &rr, hbrFill);
850 DeleteObject (hbrFill);
853 BitBlt (hdcTarget, rTarget.left, rTarget.top, cxRECT(rTarget), cyRECT(rTarget), hdcSource, rSource.left, rSource.top, SRCCOPY);
855 // Call the user-supplied callback function (if there is one)
859 (*m_pfnCallback)(this, hdcTarget, &rWindow, (palOld) ? m_palGraphic : NULL);
863 SelectPalette (hdcTarget, palOld, FALSE);
865 // If we've been drawing to an off-screen bitmap, blit the result to
870 BitBlt (hdcFinalTarget, rWindow.left, rWindow.top, cxRECT(rWindow), cyRECT(rWindow), hdcTarget, 0, 0, SRCCOPY);
871 SelectObject (hdcTarget, bmpTempTarget);
872 DeleteDC (hdcTarget);
873 hdcTarget = hdcFinalTarget;
876 SelectObject (hdcSource, bmpOld);
877 DeleteDC (hdcSource);
879 EndPaint (hLHS, &ps);
886 void MoveRect (RECT *_pr, LONG _dx, LONG _dy)
895 void GetRectInParent (HWND hWnd, RECT *pr)
899 GetWindowRect (hWnd, pr);
901 pr->right -= pr->left;
902 pr->bottom -= pr->top; // right/bottom == width/height for now
907 ScreenToClient (GetParent (hWnd), &pt);
911 pr->right += pr->left;
912 pr->bottom += pr->top;
916 BOOL CALLBACK WIZARD::Background_DlgProc (HWND hBkg, UINT msg, WPARAM wp, LPARAM lp)
918 if (msg == WM_INITDIALOG)
919 SetWindowLong (hBkg, DWL_USER, lp);
921 LPWIZARD pWiz = (LPWIZARD)GetWindowLong (hBkg, DWL_USER);
927 pWiz->Background_OnInitDialog (hBkg);
932 pWiz->Background_OnSize();
937 pWiz->Background_OnDestroy();
945 pWiz->Background_OnClose();
947 DestroyWindow (hBkg);
953 if (pWiz && pWiz->m_fnBackground)
955 if (CallWindowProc ((WNDPROC)(pWiz->m_fnBackground), hBkg, msg, wp, lp))
963 BOOL CALLBACK WIZARD::Background_PaintHook (HWND hBkg, UINT msg, WPARAM wp, LPARAM lp)
965 PVOID oldProc = Subclass_FindNextHook (hBkg, WIZARD::Background_PaintHook);
971 if ((pWiz = WIZARD::GetWizard (hBkg)) != NULL)
973 if (pWiz->Background_OnPaint())
979 Subclass_RemoveHook (hBkg, WIZARD::Background_PaintHook);
984 return CallWindowProc ((WNDPROC)oldProc, hBkg, msg, wp, lp);
986 return DefWindowProc (hBkg, msg, wp, lp);
991 void WIZARD::Background_OnInitDialog (HWND hBkg)
995 Subclass_AddHook (m_hBkg, (DLGPROC)WIZARD::Background_PaintHook);
999 void WIZARD::Background_OnSize (void)
1001 if (m_bmpBackground)
1003 DeleteObject (m_bmpBackground);
1004 m_bmpBackground = NULL;
1008 GetClientRect (m_hBkg, &rr);
1012 HDC hdc = GetDC (NULL);
1013 WORD wDepthDisplay = (WORD)GetDeviceCaps (hdc, BITSPIXEL);
1014 ReleaseDC (NULL, hdc);
1016 hdc = GetDC (m_hBkg);
1017 HDC hdcTarget = CreateCompatibleDC (hdc);
1019 if ((m_bmpBackground = CreateCompatibleBitmap (hdc, cxRECT(rr), cyRECT(rr))) != NULL)
1021 HBITMAP bmpOld = (HBITMAP)SelectObject (hdcTarget, m_bmpBackground);
1023 HPALETTE palOld = NULL;
1026 palOld = SelectPalette (hdcTarget, m_palGraphic, FALSE);
1027 RealizePalette (hdcTarget);
1031 size_t cy = cyRECT(rr) / ((clrWASH_BRIGHTEST - clrWASH_DARKEST) / clrWASH_INCREMENT);
1032 for (COLORREF clr = clrWASH_BRIGHTEST; clr >= clrWASH_DARKEST; clr -= clrWASH_INCREMENT)
1036 rSection.bottom = yy +cy;
1037 HBRUSH hbr = CreateSolidBrush (ToPALETTERGB(clr));
1038 FillRect (hdcTarget, &rSection, hbr);
1043 if (m_szBackground[0] != TEXT('\0'))
1045 HFONT hfOld = (HFONT)SelectObject (hdcTarget, m_hfBackground);
1046 COLORREF clrOld = SetTextColor (hdcTarget, clrWASH_TEXT_BG);
1047 SetBkMode (hdcTarget, TRANSPARENT);
1050 rText.left += xTEXT + cxSHADOW;
1051 rText.top += yTEXT + cySHADOW;
1052 DrawTextEx (hdcTarget, m_szBackground, lstrlen(m_szBackground), &rText, DT_NOPREFIX | DT_LEFT, NULL);
1054 rText.left -= cxSHADOW;
1055 rText.top -= cySHADOW;
1056 SetTextColor (hdcTarget, clrWASH_TEXT_FG);
1057 DrawTextEx (hdcTarget, m_szBackground, lstrlen(m_szBackground), &rText, DT_NOPREFIX | DT_LEFT, NULL);
1059 SetTextColor (hdcTarget, clrOld);
1060 SelectObject (hdcTarget, hfOld);
1064 SelectPalette (hdcTarget, palOld, FALSE);
1066 SelectObject (hdcTarget, bmpOld);
1069 DeleteDC (hdcTarget);
1070 ReleaseDC (m_hBkg, hdc);
1073 InvalidateRect (m_hBkg, &rr, TRUE);
1074 UpdateWindow (m_hBkg);
1078 void WIZARD::Background_OnDestroy (void)
1080 if (m_bmpBackground)
1082 DeleteObject (m_bmpBackground);
1083 m_bmpBackground = NULL;
1088 void WIZARD::Background_OnClose (void)
1090 LPWIZARD_STATE pState;
1092 if (m_hWnd && IsWindow (m_hWnd))
1094 PostMessage (m_hWnd, WM_COMMAND, MAKEWPARAM(IDCANCEL,BN_CLICKED), (LPARAM)GetDlgItem(m_hWnd,IDCANCEL));
1096 else if ((pState = FindState (m_stCurrent)) != NULL)
1098 CallWindowProc ((WNDPROC)(pState->dlgproc), m_hBkg, WM_COMMAND, MAKEWPARAM(IDCANCEL,BN_CLICKED), 0);
1102 ShowBackground (FALSE);
1107 BOOL WIZARD::Background_OnPaint (void)
1109 if (!m_bmpBackground)
1114 if ((hdcTarget = BeginPaint (m_hBkg, &ps)) != NULL)
1117 GetObject (m_bmpBackground, sizeof(BITMAP), &bm);
1119 HDC hdcSource = CreateCompatibleDC (hdcTarget);
1120 HBITMAP bmpOld = (HBITMAP)SelectObject (hdcSource, m_bmpBackground);
1121 HPALETTE palOld = NULL;
1124 palOld = SelectPalette (hdcSource, m_palGraphic, FALSE);
1125 RealizePalette (hdcTarget);
1128 BitBlt (hdcTarget, 0, 0, bm.bmWidth, bm.bmHeight, hdcSource, 0, 0, SRCCOPY);
1131 SelectPalette (hdcTarget, palOld, FALSE);
1132 SelectObject (hdcSource, bmpOld);
1133 DeleteDC (hdcSource);
1135 EndPaint (m_hBkg, &ps);