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)GetWindowLong (hWnd, DWL_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;
172 m_idbGraphic16 = idbGraphic16;
173 m_idbGraphic256 = idbGraphic256;
175 if (m_bmpGraphic16 != NULL)
177 DeleteObject (m_bmpGraphic16);
178 m_bmpGraphic16 = NULL;
181 if (m_bmpGraphic256 != NULL)
183 DeleteObject (m_bmpGraphic256);
184 m_bmpGraphic256 = NULL;
187 if (m_palGraphic != NULL)
189 DeleteObject (m_palGraphic);
193 m_bmpGraphic16 = (HBITMAP)TaLocale_LoadImage (idbGraphic16, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
195 if ((m_bmpGraphic256 = (HBITMAP)TaLocale_LoadImage (idbGraphic256, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)) != NULL)
198 GetObject (m_bmpGraphic256, sizeof(BITMAP), &bm);
200 if ((bm.bmBitsPixel * bm.bmPlanes) == 8)
202 HDC hdc = CreateCompatibleDC (NULL);
203 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)
263 for (int st = stNew+1; st < (int)m_cStates; ++st)
265 LPWIZARD_STATE pState;
266 if ((pState = FindState (st)) != NULL)
269 if (!SendStateCommand (st, wcIS_STATE_DISABLED))
271 m_stCurrent = stOriginal;
272 SendStateCommand (st, wcSTATE_ENTER);
273 SendStateCommand (st, wcSTATE_LEAVE);
276 stNew = (st < (int)m_cStates) ? st : m_stCurrent;
278 else // (moving backwards?)
280 for (int st = stNew-1; st >= 0; --st)
282 LPWIZARD_STATE pState;
283 if ((pState = FindState (st)) != NULL)
286 if (!SendStateCommand (st, wcIS_STATE_DISABLED))
288 m_stCurrent = stOriginal;
289 SendStateCommand (st, wcSTATE_ENTER);
290 SendStateCommand (st, wcSTATE_LEAVE);
293 stNew = (st >= 0) ? st : m_stCurrent;
299 SendStateCommand (m_stCurrent, wcSTATE_ENTER);
303 Refresh (REFRESH_RIGHT_PANE);
308 BOOL WIZARD::Show (BOOL fShowReq)
310 if (m_fShowing && !fShowReq)
313 if (m_hWnd && IsWindow (m_hWnd))
314 DestroyWindow (m_hWnd);
317 else if (!m_fShowing && fShowReq)
319 if (m_iddTemplate == -1)
321 if (m_idcLeftPane == -1)
323 if (m_idcRightPane == -1)
330 if ((m_hWnd = ModelessDialogParam (m_iddTemplate, m_hBkg, (DLGPROC)WIZARD::Template_DlgProc, (LPARAM)this)) == NULL)
335 while (GetMessage (&msg, 0, 0, NULL))
337 if (!IsDialogMessage (m_hWnd, &msg))
339 TranslateMessage (&msg);
340 DispatchMessage (&msg);
343 if (!m_fShowing || !m_hWnd || !IsWindow (m_hWnd))
352 void WIZARD::EnableButton (int idcButton, BOOL fEnable)
354 EnableWindow (GetDlgItem (m_hWnd, idcButton), fEnable);
358 void WIZARD::EnableButtons (DWORD dwButtonFlags)
360 EnableWindow (GetDlgItem (m_hWnd, m_idcBack), (dwButtonFlags & BACK_BUTTON) ? TRUE : FALSE);
361 EnableWindow (GetDlgItem (m_hWnd, m_idcNext), (dwButtonFlags & NEXT_BUTTON) ? TRUE : FALSE);
365 void WIZARD::SetButtonText (int idcButton, int idsText)
368 if ((hButton = GetDlgItem (m_hWnd, idcButton)) != NULL)
370 TCHAR szText[ cchRESOURCE ];
371 GetString (szText, idsText);
372 SetWindowText (hButton, szText);
377 void WIZARD::SetDefaultControl (int idc)
380 if ((hControl = GetDlgItem (m_hWnd, idc)) == NULL)
383 if ((hRHS = GetRightHandWindow()) != NULL)
384 hControl = GetDlgItem (hRHS, idc);
389 PostMessage (m_hWnd, WM_NEXTDLGCTL, (WPARAM)hControl, TRUE);
394 void WIZARD::SetBackground (int iddBackground, BOOL fBlue, DLGPROC dlgproc)
396 m_iddBackground = iddBackground;
398 m_fnBackground = dlgproc;
400 if (m_hBkg && IsWindow (m_hBkg))
402 ShowBackground (FALSE);
403 ShowBackground (TRUE);
408 void WIZARD::SetBackgroundText (int idsText, HFONT hf)
410 GetString (m_szBackground, idsText);
412 if ((hf != NULL) && (hf != m_hfBackground))
414 if (m_hfBackground != NULL)
415 DeleteObject (m_hfBackground);
419 if (m_hBkg && IsWindow (m_hBkg))
426 void WIZARD::SetBackgroundText (LPTSTR pszText, HFONT hf)
429 m_szBackground[0] = TEXT('\0');
431 lstrcpy (m_szBackground, pszText);
433 if ((hf != NULL) && (hf != m_hfBackground))
435 if (m_hfBackground != NULL)
436 DeleteObject (m_hfBackground);
440 if (m_hBkg && IsWindow (m_hBkg))
447 BOOL WIZARD::ShowBackground (BOOL fShow)
449 if (!fShow && m_hBkg && IsWindow (m_hBkg))
451 DestroyWindow (m_hBkg);
454 else if (fShow && !(m_hBkg && IsWindow (m_hBkg)))
456 if ((m_hBkg = ModelessDialogParam (m_iddBackground, NULL, (DLGPROC)WIZARD::Background_DlgProc, (LPARAM)this)) == NULL)
460 SystemParametersInfo (SPI_GETWORKAREA, 0, &rDesktop, 0);
463 wpl.length = sizeof(wpl);
465 wpl.showCmd = (GetWindowLong (m_hBkg, GWL_STYLE) & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOW;
466 wpl.ptMinPosition.x = 0;
467 wpl.ptMinPosition.y = 0;
468 wpl.ptMaxPosition.x = 0;
469 wpl.ptMaxPosition.y = 0;
470 wpl.rcNormalPosition.left = rDesktop.left + cxLEFT_BACKGROUND;
471 wpl.rcNormalPosition.right = rDesktop.right - cxRIGHT_BACKGROUND;
472 wpl.rcNormalPosition.top = rDesktop.top + cyTOP_BACKGROUND;
473 wpl.rcNormalPosition.bottom = rDesktop.bottom - cyBOTTOM_BACKGROUND;
474 SetWindowPlacement (m_hBkg, &wpl);
481 HWND WIZARD::GetBackgroundWindow (void)
487 void WIZARD::Refresh (DWORD dwRefFlags)
489 if (dwRefFlags & REFRESH_LEFT_PANE)
492 if ((hLHS = GetDlgItem (m_hWnd, m_idcLeftPane)) != NULL)
495 GetClientRect (hLHS, &rr);
496 InvalidateRect (hLHS, &rr, TRUE);
501 if (dwRefFlags & REFRESH_RIGHT_PANE)
504 if ((hRHS = GetDlgItem (m_hWnd, m_idcRightPane)) != NULL)
506 HWND hOld = GetRightHandWindow();
508 LPWIZARD_STATE pState;
509 if ((pState = FindState (m_stCurrent)) != NULL)
511 int stCurrent = m_stCurrent;
514 if ((hNew = ModelessDialogParam (pState->idd, m_hWnd, pState->dlgproc, pState->lp)) != NULL)
516 if (stCurrent != m_stCurrent)
517 DestroyWindow (hNew);
521 GetRectInParent (hRHS, &rRHS);
522 SetWindowPos (hNew, NULL, rRHS.left, rRHS.top, cxRECT(rRHS), cyRECT(rRHS), SWP_NOZORDER | SWP_NOACTIVATE);
523 SetWindowLong (hNew, GWL_ID, pState->idd);
525 ShowWindow (hNew, SW_SHOW);
526 ShowWindow (hRHS, SW_HIDE);
532 DestroyWindow (hOld);
538 HWND WIZARD::GetRightHandWindow (void)
540 if (!m_fShowing || !m_hWnd || !IsWindow (m_hWnd))
545 for (HWND hFound = ::GetWindow (m_hWnd, GW_CHILD);
547 hFound = ::GetWindow (hFound, GW_HWNDNEXT))
549 TCHAR szClassName[ cchRESOURCE ];
550 if (GetClassName (hFound, szClassName, cchRESOURCE))
552 if (!lstrcmp (szClassName, TEXT("#32770"))) // WC_DIALOG
554 if (!hRHS || IsWindowVisible(hRHS))
564 void WIZARD::GeneratePalette (LPRGBQUAD argb)
566 HDC hdc = GetDC (NULL);
567 WORD wDepthDisplay = (WORD)GetDeviceCaps (hdc, BITSPIXEL);
568 ReleaseDC (NULL, hdc);
570 if (wDepthDisplay == 8)
572 BYTE aPalBuffer[ sizeof(LOGPALETTE) + 256 * sizeof(PALETTEENTRY) ];
573 LPLOGPALETTE pPal = (LPLOGPALETTE)aPalBuffer;
574 pPal->palVersion = 0x300;
575 pPal->palNumEntries = 256;
577 for (size_t ii = 0; ii < 256; ++ii)
579 pPal->palPalEntry[ ii ].peRed = (argb) ? argb[ ii ].rgbRed : 0;
580 pPal->palPalEntry[ ii ].peGreen = (argb) ? argb[ ii ].rgbGreen : 0;
581 pPal->palPalEntry[ ii ].peBlue = (argb) ? argb[ ii ].rgbBlue : 0;
582 pPal->palPalEntry[ ii ].peFlags = 0;
585 for (COLORREF clr = clrWASH_DARKEST; clr <= clrWASH_BRIGHTEST; clr += clrWASH_INCREMENT)
587 for (size_t ii = 0; ii < 256; ++ii)
589 if ( (pPal->palPalEntry[ ii ].peRed == GetRValue (clr)) &&
590 (pPal->palPalEntry[ ii ].peGreen == GetGValue (clr)) &&
591 (pPal->palPalEntry[ ii ].peBlue == GetBValue (clr)) )
596 for (size_t ii = 10; ii < 246; ++ii)
598 if ( (pPal->palPalEntry[ ii ].peRed == 0) &&
599 (pPal->palPalEntry[ ii ].peGreen == 0) &&
600 (pPal->palPalEntry[ ii ].peBlue == 0) )
602 if ( (pPal->palPalEntry[ ii ].peRed == 255) &&
603 (pPal->palPalEntry[ ii ].peGreen == 255) &&
604 (pPal->palPalEntry[ ii ].peBlue == 255) )
610 pPal->palPalEntry[ ii ].peRed = GetRValue (clr);
611 pPal->palPalEntry[ ii ].peGreen = GetGValue (clr);
612 pPal->palPalEntry[ ii ].peBlue = GetBValue (clr);
616 m_palGraphic = CreatePalette (pPal);
621 LPWIZARD_STATE WIZARD::FindState (int stFind)
623 for (size_t ii = 0; ii < m_cStates; ++ii)
625 if (m_aStates[ ii ].st == stFind)
626 return &m_aStates[ ii ];
632 BOOL WIZARD::SendStateCommand (int st, WIZARD_COMMAND wc)
636 LPWIZARD_STATE pState;
637 if ((pState = FindState (st)) != NULL)
639 rc = CallWindowProc ((WNDPROC)(pState->dlgproc), NULL, WM_COMMAND, MAKEWPARAM(IDC_WIZARD,(WORD)wc), (LPARAM)this);
646 BOOL CALLBACK WIZARD::Template_DlgProc (HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
648 if (msg == WM_INITDIALOG)
649 SetWindowLong (hWnd, DWL_USER, lp);
651 LPWIZARD pWiz = (LPWIZARD)GetWindowLong (hWnd, DWL_USER);
657 pWiz->Template_OnInitDialog (hWnd);
661 if (pWiz && (pWiz->m_hWnd == hWnd))
666 return pWiz->Template_ForwardMessage (hWnd, msg, wp, lp);
673 BOOL CALLBACK WIZARD::Template_LeftPaneHook (HWND hLHS, UINT msg, WPARAM wp, LPARAM lp)
675 PVOID oldProc = Subclass_FindNextHook (hLHS, WIZARD::Template_LeftPaneHook);
681 if ((pWiz = WIZARD::GetWizard (GetParent (hLHS))) != NULL)
683 if (pWiz->Template_OnPaintLHS (hLHS))
689 Subclass_RemoveHook (hLHS, WIZARD::Template_LeftPaneHook);
694 return CallWindowProc ((WNDPROC)oldProc, hLHS, msg, wp, lp);
696 return DefWindowProc (hLHS, msg, wp, lp);
700 BOOL WIZARD::Template_ForwardMessage (HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
703 if ((hRHS = GetRightHandWindow()) != NULL)
704 return SendMessage (hRHS, msg, wp, lp);
706 LPWIZARD_STATE pState;
707 if ((pState = FindState (m_stCurrent)) != NULL)
708 return CallWindowProc ((WNDPROC)(pState->dlgproc), hWnd, msg, wp, lp);
714 void WIZARD::Template_OnInitDialog (HWND hWnd)
720 if ((hLHS = GetDlgItem (m_hWnd, m_idcLeftPane)) != NULL)
722 Subclass_AddHook (hLHS, WIZARD::Template_LeftPaneHook);
726 if ((hRHS = GetDlgItem (m_hWnd, m_idcRightPane)) != NULL)
728 ShowWindow (hRHS, SW_HIDE);
731 Refresh (REFRESH_RIGHT_PANE);
733 ShowWindow (m_hWnd, SW_SHOW);
737 BOOL WIZARD::Template_OnPaintLHS (HWND hLHS)
739 BOOL fShow16 = FALSE;
740 BOOL fShow256 = FALSE;
742 HDC hdc = GetDC (NULL);
743 WORD wDepthDisplay = (WORD)GetDeviceCaps (hdc, BITSPIXEL);
744 ReleaseDC (NULL, hdc);
746 if ( (m_bmpGraphic256 != NULL) && (wDepthDisplay >= 8) )
748 else if (m_bmpGraphic16 != NULL)
755 if ((hdcTarget = BeginPaint (hLHS, &ps)) != NULL)
757 HBITMAP bmpSource = (fShow256) ? m_bmpGraphic256 : m_bmpGraphic16;
760 GetObject (bmpSource, sizeof(BITMAP), &bm);
763 GetClientRect (hLHS, &rWindow);
765 RECT rSource = { 0, 0, bm.bmWidth, bm.bmHeight };
766 RECT rTarget = rWindow;
768 if (cxRECT(rSource) > cxRECT(rTarget))
770 MoveRect (&rSource, (cxRECT(rSource) - cxRECT(rTarget)) / 2, 0);
771 rSource.right = rSource.left + cxRECT(rTarget);
773 else if (cxRECT(rSource) < cxRECT(rTarget))
775 MoveRect (&rTarget, (cxRECT(rTarget) - cxRECT(rSource)) / 2, 0);
778 if (cyRECT(rSource) > cyRECT(rTarget))
780 MoveRect (&rSource, 0, (cyRECT(rSource) - cyRECT(rTarget)) / 2);
781 rSource.bottom = rSource.top + cyRECT(rTarget);
783 else if (cyRECT(rSource) < cyRECT(rTarget))
785 MoveRect (&rTarget, 0, (cyRECT(rTarget) - cyRECT(rSource)) / 2);
787 rTarget.right = rTarget.left + cxRECT(rSource);
788 rTarget.bottom = rTarget.top + cyRECT(rSource);
790 // If the user has supplied a custom draw-proc, then we should
791 // do our rendering to an off-screen bitmap.
793 HDC hdcFinalTarget = NULL;
794 HBITMAP bmpTempTarget = NULL;
797 // First make sure our offscreen buffer is large enough
799 if (!m_bmpBuffer || (cxRECT(m_rBuffer) < cxRECT(rWindow)) || (cyRECT(m_rBuffer) < cyRECT(rWindow)))
801 if (m_bmpBuffer != NULL)
802 DeleteObject (m_bmpBuffer);
803 if ((m_bmpBuffer = CreateCompatibleBitmap (hdcTarget, cxRECT(rWindow), cyRECT(rWindow))) != NULL)
805 m_rBuffer.right = cxRECT(rWindow); // m_rBuffer.left=already 0
806 m_rBuffer.bottom = cyRECT(rWindow); // m_rBuffer.top=already 0
810 // Then set up to double-buffer, if possible
814 hdcFinalTarget = hdcTarget;
815 hdcTarget = CreateCompatibleDC (hdcFinalTarget);
816 bmpTempTarget = (HBITMAP)SelectObject (hdcTarget, m_bmpBuffer);
820 HDC hdcSource = CreateCompatibleDC (hdcTarget);
821 HBITMAP bmpOld = (HBITMAP)SelectObject (hdcSource, bmpSource);
822 HPALETTE palOld = NULL;
823 if ((wDepthDisplay == 8) && (m_palGraphic != NULL) && (fShow256))
825 palOld = SelectPalette (hdcTarget, m_palGraphic, FALSE);
826 RealizePalette (hdcTarget);
829 if ( (bm.bmWidth < cxRECT(rWindow)) || (bm.bmHeight < cyRECT(rWindow)) )
831 COLORREF clrFill = GetPixel (hdcSource, 0, rSource.bottom -1);
832 clrFill = ToPALETTERGB(clrFill);
833 HBRUSH hbrFill = CreateSolidBrush (clrFill);
835 if (bm.bmWidth < cxRECT(rWindow))
839 rr.right = rTarget.left;
840 FillRect (hdcTarget, &rr, hbrFill);
843 rr.left = rTarget.right;
844 FillRect (hdcTarget, &rr, hbrFill);
847 if (bm.bmHeight < cyRECT(rWindow))
851 rr.bottom = rTarget.top;
852 FillRect (hdcTarget, &rr, hbrFill);
855 rr.top = rTarget.bottom;
856 FillRect (hdcTarget, &rr, hbrFill);
859 DeleteObject (hbrFill);
862 BitBlt (hdcTarget, rTarget.left, rTarget.top, cxRECT(rTarget), cyRECT(rTarget), hdcSource, rSource.left, rSource.top, SRCCOPY);
864 // Call the user-supplied callback function (if there is one)
868 (*m_pfnCallback)(this, hdcTarget, &rWindow, (palOld) ? m_palGraphic : NULL);
872 SelectPalette (hdcTarget, palOld, FALSE);
874 // If we've been drawing to an off-screen bitmap, blit the result to
879 BitBlt (hdcFinalTarget, rWindow.left, rWindow.top, cxRECT(rWindow), cyRECT(rWindow), hdcTarget, 0, 0, SRCCOPY);
880 SelectObject (hdcTarget, bmpTempTarget);
881 DeleteDC (hdcTarget);
882 hdcTarget = hdcFinalTarget;
885 SelectObject (hdcSource, bmpOld);
886 DeleteDC (hdcSource);
888 EndPaint (hLHS, &ps);
895 void MoveRect (RECT *_pr, LONG _dx, LONG _dy)
904 void GetRectInParent (HWND hWnd, RECT *pr)
908 GetWindowRect (hWnd, pr);
910 pr->right -= pr->left;
911 pr->bottom -= pr->top; // right/bottom == width/height for now
916 ScreenToClient (GetParent (hWnd), &pt);
920 pr->right += pr->left;
921 pr->bottom += pr->top;
925 BOOL CALLBACK WIZARD::Background_DlgProc (HWND hBkg, UINT msg, WPARAM wp, LPARAM lp)
927 if (msg == WM_INITDIALOG)
928 SetWindowLong (hBkg, DWL_USER, lp);
930 LPWIZARD pWiz = (LPWIZARD)GetWindowLong (hBkg, DWL_USER);
936 pWiz->Background_OnInitDialog (hBkg);
941 pWiz->Background_OnSize();
946 pWiz->Background_OnDestroy();
954 pWiz->Background_OnClose();
956 DestroyWindow (hBkg);
962 if (pWiz && pWiz->m_fnBackground)
964 if (CallWindowProc ((WNDPROC)(pWiz->m_fnBackground), hBkg, msg, wp, lp))
972 BOOL CALLBACK WIZARD::Background_PaintHook (HWND hBkg, UINT msg, WPARAM wp, LPARAM lp)
974 PVOID oldProc = Subclass_FindNextHook (hBkg, WIZARD::Background_PaintHook);
980 if ((pWiz = WIZARD::GetWizard (hBkg)) != NULL)
982 if (pWiz->Background_OnPaint())
988 Subclass_RemoveHook (hBkg, WIZARD::Background_PaintHook);
993 return CallWindowProc ((WNDPROC)oldProc, hBkg, msg, wp, lp);
995 return DefWindowProc (hBkg, msg, wp, lp);
1000 void WIZARD::Background_OnInitDialog (HWND hBkg)
1003 Background_OnSize();
1004 Subclass_AddHook (m_hBkg, (DLGPROC)WIZARD::Background_PaintHook);
1008 void WIZARD::Background_OnSize (void)
1010 if (m_bmpBackground)
1012 DeleteObject (m_bmpBackground);
1013 m_bmpBackground = NULL;
1017 GetClientRect (m_hBkg, &rr);
1021 HDC hdc = GetDC (NULL);
1022 WORD wDepthDisplay = (WORD)GetDeviceCaps (hdc, BITSPIXEL);
1023 ReleaseDC (NULL, hdc);
1025 hdc = GetDC (m_hBkg);
1026 HDC hdcTarget = CreateCompatibleDC (hdc);
1028 if ((m_bmpBackground = CreateCompatibleBitmap (hdc, cxRECT(rr), cyRECT(rr))) != NULL)
1030 HBITMAP bmpOld = (HBITMAP)SelectObject (hdcTarget, m_bmpBackground);
1032 HPALETTE palOld = NULL;
1035 palOld = SelectPalette (hdcTarget, m_palGraphic, FALSE);
1036 RealizePalette (hdcTarget);
1040 size_t cy = cyRECT(rr) / ((clrWASH_BRIGHTEST - clrWASH_DARKEST) / clrWASH_INCREMENT);
1041 for (COLORREF clr = clrWASH_BRIGHTEST; clr >= clrWASH_DARKEST; clr -= clrWASH_INCREMENT)
1045 rSection.bottom = yy +cy;
1046 HBRUSH hbr = CreateSolidBrush (ToPALETTERGB(clr));
1047 FillRect (hdcTarget, &rSection, hbr);
1052 if (m_szBackground[0] != TEXT('\0'))
1054 HFONT hfOld = (HFONT)SelectObject (hdcTarget, m_hfBackground);
1055 COLORREF clrOld = SetTextColor (hdcTarget, clrWASH_TEXT_BG);
1056 SetBkMode (hdcTarget, TRANSPARENT);
1059 rText.left += xTEXT + cxSHADOW;
1060 rText.top += yTEXT + cySHADOW;
1061 DrawTextEx (hdcTarget, m_szBackground, lstrlen(m_szBackground), &rText, DT_NOPREFIX | DT_LEFT, NULL);
1063 rText.left -= cxSHADOW;
1064 rText.top -= cySHADOW;
1065 SetTextColor (hdcTarget, clrWASH_TEXT_FG);
1066 DrawTextEx (hdcTarget, m_szBackground, lstrlen(m_szBackground), &rText, DT_NOPREFIX | DT_LEFT, NULL);
1068 SetTextColor (hdcTarget, clrOld);
1069 SelectObject (hdcTarget, hfOld);
1073 SelectPalette (hdcTarget, palOld, FALSE);
1075 SelectObject (hdcTarget, bmpOld);
1078 DeleteDC (hdcTarget);
1079 ReleaseDC (m_hBkg, hdc);
1082 InvalidateRect (m_hBkg, &rr, TRUE);
1083 UpdateWindow (m_hBkg);
1087 void WIZARD::Background_OnDestroy (void)
1089 if (m_bmpBackground)
1091 DeleteObject (m_bmpBackground);
1092 m_bmpBackground = NULL;
1097 void WIZARD::Background_OnClose (void)
1099 LPWIZARD_STATE pState;
1101 if (m_hWnd && IsWindow (m_hWnd))
1103 PostMessage (m_hWnd, WM_COMMAND, MAKEWPARAM(IDCANCEL,BN_CLICKED), (LPARAM)GetDlgItem(m_hWnd,IDCANCEL));
1105 else if ((pState = FindState (m_stCurrent)) != NULL)
1107 CallWindowProc ((WNDPROC)(pState->dlgproc), m_hBkg, WM_COMMAND, MAKEWPARAM(IDCANCEL,BN_CLICKED), 0);
1111 ShowBackground (FALSE);
1116 BOOL WIZARD::Background_OnPaint (void)
1118 if (!m_bmpBackground)
1123 if ((hdcTarget = BeginPaint (m_hBkg, &ps)) != NULL)
1126 GetObject (m_bmpBackground, sizeof(BITMAP), &bm);
1128 HDC hdcSource = CreateCompatibleDC (hdcTarget);
1129 HBITMAP bmpOld = (HBITMAP)SelectObject (hdcSource, m_bmpBackground);
1130 HPALETTE palOld = NULL;
1133 palOld = SelectPalette (hdcSource, m_palGraphic, FALSE);
1134 RealizePalette (hdcTarget);
1137 BitBlt (hdcTarget, 0, 0, bm.bmWidth, bm.bmHeight, hdcSource, 0, 0, SRCCOPY);
1140 SelectPalette (hdcTarget, palOld, FALSE);
1141 SelectObject (hdcSource, bmpOld);
1142 DeleteDC (hdcSource);
1144 EndPaint (m_hBkg, &ps);