2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 #include <afs/param.h>
15 #include <WINNT/al_wizard.h>
19 * DEFINITIONS ________________________________________________________________
23 #define REFRESH_LEFT_PANE 0x00000001
24 #define REFRESH_RIGHT_PANE 0x00000002
26 #define cxRECT(_r) ((_r).right - (_r).left)
27 #define cyRECT(_r) ((_r).bottom - (_r).top)
29 #define clrWASH_SOLID RGB(0,0,128)
30 #define clrWASH_BRIGHTEST RGB(0,0,252)
31 #define clrWASH_DARKEST RGB(0,0,4)
32 #define clrWASH_INCREMENT RGB(0,0,4)
33 #define clrWASH_TEXT_BG RGB(0,0,0)
34 #define clrWASH_TEXT_FG RGB(255,255,255)
36 #define ToPALETTERGB(_rgb) PALETTERGB(GetRValue(_rgb),GetGValue(_rgb),GetBValue(_rgb))
38 #define cxLEFT_BACKGROUND 20
39 #define cxRIGHT_BACKGROUND 20
40 #define cyTOP_BACKGROUND 20
41 #define cyBOTTOM_BACKGROUND 20
48 #define cptWASH_TEXT_SIZE 20
52 * PROTOTYPES _________________________________________________________________
56 static void MoveRect (RECT *_pr, LONG _dx, LONG _dy);
57 static void GetRectInParent (HWND hWnd, RECT *pr);
61 * ROUTINES ___________________________________________________________________
74 m_bmpGraphic16 = NULL;
76 m_bmpGraphic256 = NULL;
87 m_fnBackground = NULL;
88 m_szBackground[0] = TEXT('\0');
89 m_bmpBackground = NULL;
92 SetRectEmpty (&m_rBuffer);
94 HDC hdc = GetDC (NULL);
96 memset (&lf, 0x00, sizeof(lf));
97 GetObject (GetStockObject (DEFAULT_GUI_FONT), sizeof(lf), &lf);
98 lf.lfHeight = -MulDiv (cptWASH_TEXT_SIZE, GetDeviceCaps (hdc, LOGPIXELSY), 72);
100 m_hfBackground = CreateFontIndirect (&lf);
101 ReleaseDC (NULL, hdc);
107 WIZARD::~WIZARD (void)
109 if (m_hWnd && IsWindow (m_hWnd))
110 DestroyWindow (m_hWnd);
111 if (m_bmpGraphic16 != NULL)
112 DeleteObject (m_bmpGraphic16);
113 if (m_bmpGraphic256 != NULL)
114 DeleteObject (m_bmpGraphic256);
115 if (m_bmpBuffer != NULL)
116 DeleteObject (m_bmpBuffer);
117 if (m_palGraphic != NULL)
118 DeleteObject (m_palGraphic);
119 if (m_bmpBackground != NULL)
120 DeleteObject (m_bmpBackground);
121 if (m_hfBackground != NULL)
122 DeleteObject (m_hfBackground);
126 HWND WIZARD::GetWindow (void)
128 if (m_hWnd && IsWindow (m_hWnd))
134 LPWIZARD WIZARD::GetWizard (HWND hWnd)
136 LPWIZARD pWiz = NULL;
139 if ((pWiz = (LPWIZARD)GetWindowLongPtr (hWnd, DWLP_USER)) != NULL)
141 if ( (pWiz->m_hWnd != hWnd) && (pWiz->m_hBkg != hWnd) )
152 void WIZARD::SetDialogTemplate (int iddTemplate, int idcLeftPane, int idcRightPane, int idcBack, int idcNext)
154 m_iddTemplate = iddTemplate;
155 m_idcLeftPane = idcLeftPane;
156 m_idcRightPane = idcRightPane;
168 void WIZARD::SetGraphic (int idbGraphic16, int idbGraphic256)
170 LPRGBQUAD pargb = NULL;
173 m_idbGraphic16 = idbGraphic16;
174 m_idbGraphic256 = idbGraphic256;
176 if (m_bmpGraphic16 != NULL)
178 DeleteObject (m_bmpGraphic16);
179 m_bmpGraphic16 = NULL;
182 if (m_bmpGraphic256 != NULL)
184 DeleteObject (m_bmpGraphic256);
185 m_bmpGraphic256 = NULL;
188 if (m_palGraphic != NULL)
190 DeleteObject (m_palGraphic);
194 m_bmpGraphic16 = (HBITMAP)TaLocale_LoadImage (idbGraphic16, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
196 if ((m_bmpGraphic256 = (HBITMAP)TaLocale_LoadImage (idbGraphic256, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)) != NULL)
199 GetObject (m_bmpGraphic256, sizeof(BITMAP), &bm);
201 if ((bm.bmBitsPixel * bm.bmPlanes) == 8)
203 HDC hdc = CreateCompatibleDC (NULL);
204 HBITMAP bmpOld = (HBITMAP)SelectObject (hdc, m_bmpGraphic256);
206 GetDIBColorTable (hdc, 0, 256, argb);
209 SelectObject (hdc, bmpOld);
214 GeneratePalette (pargb);
218 Refresh (REFRESH_LEFT_PANE);
223 void WIZARD::SetGraphicCallback (void (CALLBACK *pfnCallback)(LPWIZARD pWiz, HDC hdcTarget, LPRECT prTarget, HPALETTE hPal))
225 m_pfnCallback = pfnCallback;
229 Refresh (REFRESH_LEFT_PANE);
234 void WIZARD::SetStates (LPWIZARD_STATE aStates, size_t cStates)
241 Refresh (REFRESH_RIGHT_PANE);
246 int WIZARD::GetState (void)
252 void WIZARD::SetState (int stNew, BOOL fForce)
254 SendStateCommand (m_stCurrent, wcSTATE_LEAVE);
256 int stOriginal = m_stCurrent;
259 if (!fForce && SendStateCommand (stNew, wcIS_STATE_DISABLED))
261 if (stOriginal <= stNew)
264 for (st = stNew+1; st < (int)m_cStates; ++st)
266 LPWIZARD_STATE pState;
267 if ((pState = FindState (st)) != NULL)
270 if (!SendStateCommand (st, wcIS_STATE_DISABLED))
272 m_stCurrent = stOriginal;
273 SendStateCommand (st, wcSTATE_ENTER);
274 SendStateCommand (st, wcSTATE_LEAVE);
277 stNew = (st < (int)m_cStates) ? st : m_stCurrent;
279 else // (moving backwards?)
282 for (st = stNew-1; st >= 0; --st)
284 LPWIZARD_STATE pState;
285 if ((pState = FindState (st)) != NULL)
288 if (!SendStateCommand (st, wcIS_STATE_DISABLED))
290 m_stCurrent = stOriginal;
291 SendStateCommand (st, wcSTATE_ENTER);
292 SendStateCommand (st, wcSTATE_LEAVE);
295 stNew = (st >= 0) ? st : m_stCurrent;
301 SendStateCommand (m_stCurrent, wcSTATE_ENTER);
305 Refresh (REFRESH_RIGHT_PANE);
310 BOOL WIZARD::Show (BOOL fShowReq)
312 if (m_fShowing && !fShowReq)
315 if (m_hWnd && IsWindow (m_hWnd))
316 DestroyWindow (m_hWnd);
319 else if (!m_fShowing && fShowReq)
321 if (m_iddTemplate == -1)
323 if (m_idcLeftPane == -1)
325 if (m_idcRightPane == -1)
332 if ((m_hWnd = ModelessDialogParam (m_iddTemplate, m_hBkg, (DLGPROC)WIZARD::Template_DlgProc, (LPARAM)this)) == NULL)
337 while (GetMessage (&msg, 0, 0, NULL))
339 if (!IsDialogMessage (m_hWnd, &msg))
341 TranslateMessage (&msg);
342 DispatchMessage (&msg);
345 if (!m_fShowing || !m_hWnd || !IsWindow (m_hWnd))
354 void WIZARD::EnableButton (int idcButton, BOOL fEnable)
356 EnableWindow (GetDlgItem (m_hWnd, idcButton), fEnable);
360 void WIZARD::EnableButtons (DWORD dwButtonFlags)
362 EnableWindow (GetDlgItem (m_hWnd, m_idcBack), (dwButtonFlags & BACK_BUTTON) ? TRUE : FALSE);
363 EnableWindow (GetDlgItem (m_hWnd, m_idcNext), (dwButtonFlags & NEXT_BUTTON) ? TRUE : FALSE);
367 void WIZARD::SetButtonText (int idcButton, int idsText)
370 if ((hButton = GetDlgItem (m_hWnd, idcButton)) != NULL)
372 TCHAR szText[ cchRESOURCE ];
373 GetString (szText, idsText);
374 SetWindowText (hButton, szText);
379 void WIZARD::SetDefaultControl (int idc)
382 if ((hControl = GetDlgItem (m_hWnd, idc)) == NULL)
385 if ((hRHS = GetRightHandWindow()) != NULL)
386 hControl = GetDlgItem (hRHS, idc);
391 PostMessage (m_hWnd, WM_NEXTDLGCTL, (WPARAM)hControl, TRUE);
396 void WIZARD::SetBackground (int iddBackground, BOOL fBlue, DLGPROC dlgproc)
398 m_iddBackground = iddBackground;
400 m_fnBackground = dlgproc;
402 if (m_hBkg && IsWindow (m_hBkg))
404 ShowBackground (FALSE);
405 ShowBackground (TRUE);
410 void WIZARD::SetBackgroundText (int idsText, HFONT hf)
412 GetString (m_szBackground, idsText);
414 if ((hf != NULL) && (hf != m_hfBackground))
416 if (m_hfBackground != NULL)
417 DeleteObject (m_hfBackground);
421 if (m_hBkg && IsWindow (m_hBkg))
428 void WIZARD::SetBackgroundText (LPTSTR pszText, HFONT hf)
431 m_szBackground[0] = TEXT('\0');
433 lstrcpy (m_szBackground, pszText);
435 if ((hf != NULL) && (hf != m_hfBackground))
437 if (m_hfBackground != NULL)
438 DeleteObject (m_hfBackground);
442 if (m_hBkg && IsWindow (m_hBkg))
449 BOOL WIZARD::ShowBackground (BOOL fShow)
451 if (!fShow && m_hBkg && IsWindow (m_hBkg))
453 DestroyWindow (m_hBkg);
456 else if (fShow && !(m_hBkg && IsWindow (m_hBkg)))
458 if ((m_hBkg = ModelessDialogParam (m_iddBackground, NULL, (DLGPROC)WIZARD::Background_DlgProc, (LPARAM)this)) == NULL)
462 SystemParametersInfo (SPI_GETWORKAREA, 0, &rDesktop, 0);
465 wpl.length = sizeof(wpl);
467 wpl.showCmd = (GetWindowLong (m_hBkg, GWL_STYLE) & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOW;
468 wpl.ptMinPosition.x = 0;
469 wpl.ptMinPosition.y = 0;
470 wpl.ptMaxPosition.x = 0;
471 wpl.ptMaxPosition.y = 0;
472 wpl.rcNormalPosition.left = rDesktop.left + cxLEFT_BACKGROUND;
473 wpl.rcNormalPosition.right = rDesktop.right - cxRIGHT_BACKGROUND;
474 wpl.rcNormalPosition.top = rDesktop.top + cyTOP_BACKGROUND;
475 wpl.rcNormalPosition.bottom = rDesktop.bottom - cyBOTTOM_BACKGROUND;
476 SetWindowPlacement (m_hBkg, &wpl);
483 HWND WIZARD::GetBackgroundWindow (void)
489 void WIZARD::Refresh (DWORD dwRefFlags)
491 if (dwRefFlags & REFRESH_LEFT_PANE)
494 if ((hLHS = GetDlgItem (m_hWnd, m_idcLeftPane)) != NULL)
497 GetClientRect (hLHS, &rr);
498 InvalidateRect (hLHS, &rr, TRUE);
503 if (dwRefFlags & REFRESH_RIGHT_PANE)
506 if ((hRHS = GetDlgItem (m_hWnd, m_idcRightPane)) != NULL)
508 HWND hOld = GetRightHandWindow();
510 LPWIZARD_STATE pState;
511 if ((pState = FindState (m_stCurrent)) != NULL)
513 int stCurrent = m_stCurrent;
516 if ((hNew = ModelessDialogParam (pState->idd, m_hWnd, pState->dlgproc, pState->lp)) != NULL)
518 if (stCurrent != m_stCurrent)
519 DestroyWindow (hNew);
523 GetRectInParent (hRHS, &rRHS);
524 SetWindowPos (hNew, NULL, rRHS.left, rRHS.top, cxRECT(rRHS), cyRECT(rRHS), SWP_NOZORDER | SWP_NOACTIVATE);
525 SetWindowLong (hNew, GWL_ID, pState->idd);
527 ShowWindow (hNew, SW_SHOW);
528 ShowWindow (hRHS, SW_HIDE);
534 DestroyWindow (hOld);
540 HWND WIZARD::GetRightHandWindow (void)
542 if (!m_fShowing || !m_hWnd || !IsWindow (m_hWnd))
547 for (HWND hFound = ::GetWindow (m_hWnd, GW_CHILD);
549 hFound = ::GetWindow (hFound, GW_HWNDNEXT))
551 TCHAR szClassName[ cchRESOURCE ];
552 if (GetClassName (hFound, szClassName, cchRESOURCE))
554 if (!lstrcmp (szClassName, TEXT("#32770"))) // WC_DIALOG
556 if (!hRHS || IsWindowVisible(hRHS))
566 void WIZARD::GeneratePalette (LPRGBQUAD argb)
568 HDC hdc = GetDC (NULL);
569 WORD wDepthDisplay = (WORD)GetDeviceCaps (hdc, BITSPIXEL);
570 ReleaseDC (NULL, hdc);
572 if (wDepthDisplay == 8)
574 BYTE aPalBuffer[ sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY) ];
575 LPLOGPALETTE pPal = (LPLOGPALETTE)aPalBuffer;
576 pPal->palVersion = 0x300;
577 pPal->palNumEntries = 256;
580 for (ii = 0; ii < 256; ++ii)
582 pPal->palPalEntry[ ii ].peRed = (argb) ? argb[ ii ].rgbRed : 0;
583 pPal->palPalEntry[ ii ].peGreen = (argb) ? argb[ ii ].rgbGreen : 0;
584 pPal->palPalEntry[ ii ].peBlue = (argb) ? argb[ ii ].rgbBlue : 0;
585 pPal->palPalEntry[ ii ].peFlags = 0;
588 for (COLORREF clr = clrWASH_DARKEST; clr <= clrWASH_BRIGHTEST; clr += clrWASH_INCREMENT)
590 for (ii = 0; ii < 256; ++ii)
592 if ( (pPal->palPalEntry[ ii ].peRed == GetRValue (clr)) &&
593 (pPal->palPalEntry[ ii ].peGreen == GetGValue (clr)) &&
594 (pPal->palPalEntry[ ii ].peBlue == GetBValue (clr)) )
599 for (ii = 10; ii < 246; ++ii)
601 if ( (pPal->palPalEntry[ ii ].peRed == 0) &&
602 (pPal->palPalEntry[ ii ].peGreen == 0) &&
603 (pPal->palPalEntry[ ii ].peBlue == 0) )
605 if ( (pPal->palPalEntry[ ii ].peRed == 255) &&
606 (pPal->palPalEntry[ ii ].peGreen == 255) &&
607 (pPal->palPalEntry[ ii ].peBlue == 255) )
613 pPal->palPalEntry[ ii ].peRed = GetRValue (clr);
614 pPal->palPalEntry[ ii ].peGreen = GetGValue (clr);
615 pPal->palPalEntry[ ii ].peBlue = GetBValue (clr);
619 m_palGraphic = CreatePalette (pPal);
624 LPWIZARD_STATE WIZARD::FindState (int stFind)
626 for (size_t ii = 0; ii < m_cStates; ++ii)
628 if (m_aStates[ ii ].st == stFind)
629 return &m_aStates[ ii ];
635 BOOL WIZARD::SendStateCommand (int st, WIZARD_COMMAND wc)
639 LPWIZARD_STATE pState;
640 if ((pState = FindState (st)) != NULL)
642 rc = CallWindowProc ((WNDPROC)(pState->dlgproc), NULL, WM_COMMAND, MAKEWPARAM(IDC_WIZARD,(WORD)wc), (LPARAM)this);
649 BOOL CALLBACK WIZARD::Template_DlgProc (HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
651 if (msg == WM_INITDIALOG)
652 SetWindowLongPtr (hWnd, DWLP_USER, lp);
654 LPWIZARD pWiz = (LPWIZARD)GetWindowLongPtr (hWnd, DWLP_USER);
660 pWiz->Template_OnInitDialog (hWnd);
664 if (pWiz && (pWiz->m_hWnd == hWnd))
669 return pWiz->Template_ForwardMessage (hWnd, msg, wp, lp);
676 BOOL CALLBACK WIZARD::Template_LeftPaneHook (HWND hLHS, UINT msg, WPARAM wp, LPARAM lp)
678 PVOID oldProc = Subclass_FindNextHook (hLHS, WIZARD::Template_LeftPaneHook);
684 if ((pWiz = WIZARD::GetWizard (GetParent (hLHS))) != NULL)
686 if (pWiz->Template_OnPaintLHS (hLHS))
692 Subclass_RemoveHook (hLHS, WIZARD::Template_LeftPaneHook);
697 return CallWindowProc ((WNDPROC)oldProc, hLHS, msg, wp, lp);
699 return DefWindowProc (hLHS, msg, wp, lp);
703 BOOL WIZARD::Template_ForwardMessage (HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
706 if ((hRHS = GetRightHandWindow()) != NULL)
707 return SendMessage (hRHS, msg, wp, lp);
709 LPWIZARD_STATE pState;
710 if ((pState = FindState (m_stCurrent)) != NULL)
711 return CallWindowProc ((WNDPROC)(pState->dlgproc), hWnd, msg, wp, lp);
717 void WIZARD::Template_OnInitDialog (HWND hWnd)
723 if ((hLHS = GetDlgItem (m_hWnd, m_idcLeftPane)) != NULL)
725 Subclass_AddHook (hLHS, WIZARD::Template_LeftPaneHook);
729 if ((hRHS = GetDlgItem (m_hWnd, m_idcRightPane)) != NULL)
731 ShowWindow (hRHS, SW_HIDE);
734 Refresh (REFRESH_RIGHT_PANE);
736 ShowWindow (m_hWnd, SW_SHOW);
740 BOOL WIZARD::Template_OnPaintLHS (HWND hLHS)
742 BOOL fShow16 = FALSE;
743 BOOL fShow256 = FALSE;
745 HDC hdc = GetDC (NULL);
746 WORD wDepthDisplay = (WORD)GetDeviceCaps (hdc, BITSPIXEL);
747 ReleaseDC (NULL, hdc);
749 if ( (m_bmpGraphic256 != NULL) && (wDepthDisplay >= 8) )
751 else if (m_bmpGraphic16 != NULL)
758 if ((hdcTarget = BeginPaint (hLHS, &ps)) != NULL)
760 HBITMAP bmpSource = (fShow256) ? m_bmpGraphic256 : m_bmpGraphic16;
763 GetObject (bmpSource, sizeof(BITMAP), &bm);
766 GetClientRect (hLHS, &rWindow);
768 RECT rSource = { 0, 0, bm.bmWidth, bm.bmHeight };
769 RECT rTarget = rWindow;
771 if (cxRECT(rSource) > cxRECT(rTarget))
773 MoveRect (&rSource, (cxRECT(rSource) - cxRECT(rTarget)) / 2, 0);
774 rSource.right = rSource.left + cxRECT(rTarget);
776 else if (cxRECT(rSource) < cxRECT(rTarget))
778 MoveRect (&rTarget, (cxRECT(rTarget) - cxRECT(rSource)) / 2, 0);
781 if (cyRECT(rSource) > cyRECT(rTarget))
783 MoveRect (&rSource, 0, (cyRECT(rSource) - cyRECT(rTarget)) / 2);
784 rSource.bottom = rSource.top + cyRECT(rTarget);
786 else if (cyRECT(rSource) < cyRECT(rTarget))
788 MoveRect (&rTarget, 0, (cyRECT(rTarget) - cyRECT(rSource)) / 2);
790 rTarget.right = rTarget.left + cxRECT(rSource);
791 rTarget.bottom = rTarget.top + cyRECT(rSource);
793 // If the user has supplied a custom draw-proc, then we should
794 // do our rendering to an off-screen bitmap.
796 HDC hdcFinalTarget = NULL;
797 HBITMAP bmpTempTarget = NULL;
800 // First make sure our offscreen buffer is large enough
802 if (!m_bmpBuffer || (cxRECT(m_rBuffer) < cxRECT(rWindow)) || (cyRECT(m_rBuffer) < cyRECT(rWindow)))
804 if (m_bmpBuffer != NULL)
805 DeleteObject (m_bmpBuffer);
806 if ((m_bmpBuffer = CreateCompatibleBitmap (hdcTarget, cxRECT(rWindow), cyRECT(rWindow))) != NULL)
808 m_rBuffer.right = cxRECT(rWindow); // m_rBuffer.left=already 0
809 m_rBuffer.bottom = cyRECT(rWindow); // m_rBuffer.top=already 0
813 // Then set up to double-buffer, if possible
817 hdcFinalTarget = hdcTarget;
818 hdcTarget = CreateCompatibleDC (hdcFinalTarget);
819 bmpTempTarget = (HBITMAP)SelectObject (hdcTarget, m_bmpBuffer);
823 HDC hdcSource = CreateCompatibleDC (hdcTarget);
824 HBITMAP bmpOld = (HBITMAP)SelectObject (hdcSource, bmpSource);
825 HPALETTE palOld = NULL;
826 if ((wDepthDisplay == 8) && (m_palGraphic != NULL) && (fShow256))
828 palOld = SelectPalette (hdcTarget, m_palGraphic, FALSE);
829 RealizePalette (hdcTarget);
832 if ( (bm.bmWidth < cxRECT(rWindow)) || (bm.bmHeight < cyRECT(rWindow)) )
834 COLORREF clrFill = GetPixel (hdcSource, 0, rSource.bottom -1);
835 clrFill = ToPALETTERGB(clrFill);
836 HBRUSH hbrFill = CreateSolidBrush (clrFill);
838 if (bm.bmWidth < cxRECT(rWindow))
842 rr.right = rTarget.left;
843 FillRect (hdcTarget, &rr, hbrFill);
846 rr.left = rTarget.right;
847 FillRect (hdcTarget, &rr, hbrFill);
850 if (bm.bmHeight < cyRECT(rWindow))
854 rr.bottom = rTarget.top;
855 FillRect (hdcTarget, &rr, hbrFill);
858 rr.top = rTarget.bottom;
859 FillRect (hdcTarget, &rr, hbrFill);
862 DeleteObject (hbrFill);
865 BitBlt (hdcTarget, rTarget.left, rTarget.top, cxRECT(rTarget), cyRECT(rTarget), hdcSource, rSource.left, rSource.top, SRCCOPY);
867 // Call the user-supplied callback function (if there is one)
871 (*m_pfnCallback)(this, hdcTarget, &rWindow, (palOld) ? m_palGraphic : NULL);
875 SelectPalette (hdcTarget, palOld, FALSE);
877 // If we've been drawing to an off-screen bitmap, blit the result to
882 BitBlt (hdcFinalTarget, rWindow.left, rWindow.top, cxRECT(rWindow), cyRECT(rWindow), hdcTarget, 0, 0, SRCCOPY);
883 SelectObject (hdcTarget, bmpTempTarget);
884 DeleteDC (hdcTarget);
885 hdcTarget = hdcFinalTarget;
888 SelectObject (hdcSource, bmpOld);
889 DeleteDC (hdcSource);
891 EndPaint (hLHS, &ps);
898 void MoveRect (RECT *_pr, LONG _dx, LONG _dy)
907 void GetRectInParent (HWND hWnd, RECT *pr)
911 GetWindowRect (hWnd, pr);
913 pr->right -= pr->left;
914 pr->bottom -= pr->top; // right/bottom == width/height for now
919 ScreenToClient (GetParent (hWnd), &pt);
923 pr->right += pr->left;
924 pr->bottom += pr->top;
928 BOOL CALLBACK WIZARD::Background_DlgProc (HWND hBkg, UINT msg, WPARAM wp, LPARAM lp)
930 if (msg == WM_INITDIALOG)
931 SetWindowLongPtr (hBkg, DWLP_USER, lp);
933 LPWIZARD pWiz = (LPWIZARD)GetWindowLongPtr (hBkg, DWLP_USER);
939 pWiz->Background_OnInitDialog (hBkg);
944 pWiz->Background_OnSize();
949 pWiz->Background_OnDestroy();
957 pWiz->Background_OnClose();
959 DestroyWindow (hBkg);
965 if (pWiz && pWiz->m_fnBackground)
967 if (CallWindowProc ((WNDPROC)(pWiz->m_fnBackground), hBkg, msg, wp, lp))
975 BOOL CALLBACK WIZARD::Background_PaintHook (HWND hBkg, UINT msg, WPARAM wp, LPARAM lp)
977 PVOID oldProc = Subclass_FindNextHook (hBkg, WIZARD::Background_PaintHook);
983 if ((pWiz = WIZARD::GetWizard (hBkg)) != NULL)
985 if (pWiz->Background_OnPaint())
991 Subclass_RemoveHook (hBkg, WIZARD::Background_PaintHook);
996 return CallWindowProc ((WNDPROC)oldProc, hBkg, msg, wp, lp);
998 return DefWindowProc (hBkg, msg, wp, lp);
1003 void WIZARD::Background_OnInitDialog (HWND hBkg)
1006 Background_OnSize();
1007 Subclass_AddHook (m_hBkg, (DLGPROC)WIZARD::Background_PaintHook);
1011 void WIZARD::Background_OnSize (void)
1013 if (m_bmpBackground)
1015 DeleteObject (m_bmpBackground);
1016 m_bmpBackground = NULL;
1020 GetClientRect (m_hBkg, &rr);
1024 HDC hdc = GetDC (NULL);
1025 WORD wDepthDisplay = (WORD)GetDeviceCaps (hdc, BITSPIXEL);
1026 ReleaseDC (NULL, hdc);
1028 hdc = GetDC (m_hBkg);
1029 HDC hdcTarget = CreateCompatibleDC (hdc);
1031 if ((m_bmpBackground = CreateCompatibleBitmap (hdc, cxRECT(rr), cyRECT(rr))) != NULL)
1033 HBITMAP bmpOld = (HBITMAP)SelectObject (hdcTarget, m_bmpBackground);
1035 HPALETTE palOld = NULL;
1038 palOld = SelectPalette (hdcTarget, m_palGraphic, FALSE);
1039 RealizePalette (hdcTarget);
1043 size_t cy = cyRECT(rr) / ((clrWASH_BRIGHTEST - clrWASH_DARKEST) / clrWASH_INCREMENT);
1044 for (COLORREF clr = clrWASH_BRIGHTEST; clr >= clrWASH_DARKEST; clr -= clrWASH_INCREMENT)
1048 rSection.bottom = yy +cy;
1049 HBRUSH hbr = CreateSolidBrush (ToPALETTERGB(clr));
1050 FillRect (hdcTarget, &rSection, hbr);
1055 if (m_szBackground[0] != TEXT('\0'))
1057 HFONT hfOld = (HFONT)SelectObject (hdcTarget, m_hfBackground);
1058 COLORREF clrOld = SetTextColor (hdcTarget, clrWASH_TEXT_BG);
1059 SetBkMode (hdcTarget, TRANSPARENT);
1062 rText.left += xTEXT + cxSHADOW;
1063 rText.top += yTEXT + cySHADOW;
1064 DrawTextEx (hdcTarget, m_szBackground, lstrlen(m_szBackground), &rText, DT_NOPREFIX | DT_LEFT, NULL);
1066 rText.left -= cxSHADOW;
1067 rText.top -= cySHADOW;
1068 SetTextColor (hdcTarget, clrWASH_TEXT_FG);
1069 DrawTextEx (hdcTarget, m_szBackground, lstrlen(m_szBackground), &rText, DT_NOPREFIX | DT_LEFT, NULL);
1071 SetTextColor (hdcTarget, clrOld);
1072 SelectObject (hdcTarget, hfOld);
1076 SelectPalette (hdcTarget, palOld, FALSE);
1078 SelectObject (hdcTarget, bmpOld);
1081 DeleteDC (hdcTarget);
1082 ReleaseDC (m_hBkg, hdc);
1085 InvalidateRect (m_hBkg, &rr, TRUE);
1086 UpdateWindow (m_hBkg);
1090 void WIZARD::Background_OnDestroy (void)
1092 if (m_bmpBackground)
1094 DeleteObject (m_bmpBackground);
1095 m_bmpBackground = NULL;
1100 void WIZARD::Background_OnClose (void)
1102 LPWIZARD_STATE pState;
1104 if (m_hWnd && IsWindow (m_hWnd))
1106 PostMessage (m_hWnd, WM_COMMAND, MAKEWPARAM(IDCANCEL,BN_CLICKED), (LPARAM)GetDlgItem(m_hWnd,IDCANCEL));
1108 else if ((pState = FindState (m_stCurrent)) != NULL)
1110 CallWindowProc ((WNDPROC)(pState->dlgproc), m_hBkg, WM_COMMAND, MAKEWPARAM(IDCANCEL,BN_CLICKED), 0);
1114 ShowBackground (FALSE);
1119 BOOL WIZARD::Background_OnPaint (void)
1121 if (!m_bmpBackground)
1126 if ((hdcTarget = BeginPaint (m_hBkg, &ps)) != NULL)
1129 GetObject (m_bmpBackground, sizeof(BITMAP), &bm);
1131 HDC hdcSource = CreateCompatibleDC (hdcTarget);
1132 HBITMAP bmpOld = (HBITMAP)SelectObject (hdcSource, m_bmpBackground);
1133 HPALETTE palOld = NULL;
1136 palOld = SelectPalette (hdcSource, m_palGraphic, FALSE);
1137 RealizePalette (hdcTarget);
1140 BitBlt (hdcTarget, 0, 0, bm.bmWidth, bm.bmHeight, hdcSource, 0, 0, SRCCOPY);
1143 SelectPalette (hdcTarget, palOld, FALSE);
1144 SelectObject (hdcSource, bmpOld);
1145 DeleteDC (hdcSource);
1147 EndPaint (m_hBkg, &ps);