/******************************************************************************* * * (C) COPYRIGHT MICROSOFT CORPORATION, 1998 * * TITLE: CONTRAST.CPP * * VERSION: 1.0 * * AUTHOR: ShaunIv * * DATE: 1/11/2001 * * DESCRIPTION: Small preview window for illustrating brightness and contrast settings * *******************************************************************************/ #include "precomp.h" #pragma hdrstop #include "contrast.h" LRESULT CBrightnessContrast::OnCreate( WPARAM, LPARAM ) { return 0; } CBrightnessContrast::~CBrightnessContrast() { KillBitmaps(); } CBrightnessContrast::CBrightnessContrast( HWND hWnd ) : m_hWnd(hWnd), m_nIntent(0), m_nBrightness(50), m_nContrast(50), m_hBmpPreviewImage(NULL) { for (int i=0;i= 0 && nBrightness <= 100) { m_nBrightness = static_cast(nBrightness); ApplySettings(); } return 0; } LRESULT CBrightnessContrast::SetContrast(int nContrast) { WIA_PUSH_FUNCTION((TEXT("CBrightnessContrast::SetContrast"))); if (m_nContrast >= 0 && m_nContrast <= 100) { m_nContrast = static_cast(nContrast); ApplySettings(); } return 0; } LRESULT CBrightnessContrast::SetIntent(LONG nIntent) { WIA_PUSH_FUNCTION((TEXT("CBrightnessContrast::SetIntent"))); if (nIntent < NUMPREVIEWIMAGES && nIntent >= 0) { m_nIntent = nIntent; ApplySettings(); } return 0; } LRESULT CBrightnessContrast::KillBitmaps() { WIA_PUSH_FUNCTION((TEXT("CBrightnessContrast::KillBitmaps"))); for (int i=0;i(CopyImage( m_PreviewBitmaps[m_nIntent], IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION )); #else // // If the window is enabled, use the real brightness and contrast settings // if (IsWindowEnabled(m_hWnd)) { if (BCPWM_BW == m_nIntent) { m_GdiPlusHelper.SetThreshold( m_PreviewBitmaps[m_nIntent], m_hBmpPreviewImage, m_nBrightness ); } else { m_GdiPlusHelper.SetBrightnessAndContrast( m_PreviewBitmaps[m_nIntent], m_hBmpPreviewImage, m_nBrightness, m_nContrast ); } } // // Otherwise, use the nominal settings, to prevent feedback // else { if (BCPWM_BW == m_nIntent) { m_GdiPlusHelper.SetThreshold( m_PreviewBitmaps[m_nIntent], m_hBmpPreviewImage, 50 ); } else { m_GdiPlusHelper.SetBrightnessAndContrast( m_PreviewBitmaps[m_nIntent], m_hBmpPreviewImage, 50, 50 ); } } #endif // !DONT_USE_GDIPLUS } InvalidateRect(m_hWnd,NULL,FALSE); UpdateWindow(m_hWnd); return 0; } BOOL CBrightnessContrast::RegisterClass( HINSTANCE hInstance ) { WNDCLASS wc = {0}; wc.style = CS_DBLCLKS; wc.cbWndExtra = sizeof(CBrightnessContrast*); wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1); wc.lpszClassName = BRIGHTNESS_CONTRAST_PREVIEW_WINDOW_CLASS; BOOL res = (::RegisterClass(&wc) != 0); return (res != 0); } LRESULT CBrightnessContrast::OnSetBrightness( WPARAM wParam, LPARAM lParam) { WIA_PUSH_FUNCTION((TEXT("CBrightnessContrast::OnSetBrightness"))); SetBrightness(static_cast(lParam)); return 0; } LRESULT CBrightnessContrast::OnSetContrast( WPARAM wParam, LPARAM lParam) { WIA_PUSH_FUNCTION((TEXT("CBrightnessContrast::OnSetContrast"))); SetContrast(static_cast(lParam)); return 0; } LRESULT CBrightnessContrast::OnSetIntent( WPARAM wParam, LPARAM lParam) { WIA_PUSH_FUNCTION((TEXT("CBrightnessContrast::OnSetIntent"))); SetIntent(static_cast(lParam)); return 0; } LRESULT CBrightnessContrast::OnLoadBitmap( WPARAM wParam, LPARAM lParam ) { WIA_PUSH_FUNCTION((TEXT("CBrightnessContrast::OnLoadBitmap"))); int nId = static_cast(wParam); if (nId < NUMPREVIEWIMAGES && nId >= 0) { if (m_PreviewBitmaps[nId]) { DeleteObject(m_PreviewBitmaps[nId]); m_PreviewBitmaps[nId] = NULL; } m_PreviewBitmaps[nId] = reinterpret_cast(lParam); } return 0; } LRESULT CBrightnessContrast::OnEnable( WPARAM wParam, LPARAM ) { // // Update the control's appearance when we are enabled or disabled // WIA_PUSH_FUNCTION((TEXT("CBrightnessContrast::OnEnable"))); if (wParam) { ApplySettings(); } return 0; } LRESULT CALLBACK CBrightnessContrast::WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { SC_BEGIN_MESSAGE_HANDLERS(CBrightnessContrast) { SC_HANDLE_MESSAGE( WM_CREATE, OnCreate ); SC_HANDLE_MESSAGE( WM_ENABLE, OnEnable ); SC_HANDLE_MESSAGE( WM_PAINT, OnPaint ); SC_HANDLE_MESSAGE( BCPWM_SETBRIGHTNESS, OnSetBrightness ); SC_HANDLE_MESSAGE( BCPWM_SETCONTRAST, OnSetContrast ); SC_HANDLE_MESSAGE( BCPWM_SETINTENT, OnSetIntent); SC_HANDLE_MESSAGE( BCPWM_LOADIMAGE, OnLoadBitmap); } SC_END_MESSAGE_HANDLERS(); }