home *** CD-ROM | disk | FTP | other *** search
- //==========================================================================;
- //
- // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
- // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
- // PURPOSE.
- //
- // Copyright (c) 1992 - 1996 Microsoft Corporation. All Rights Reserved.
- //
- //--------------------------------------------------------------------------;
- //
- //contprop.cpp
- //
- // Contents:
- //
- // CContrastProperties class. This class implements the property page
- // for the contrast filter and exposes the IPropertyPage interface
- // which is defined by OLE2.
- //
-
- #include <streams.h>
- #include <commctrl.h>
- #include <olectl.h>
- #include <memory.h>
-
- #include "resource.h"
- #include "contuids.h"
- #include "icontrst.h"
- #include "contrast.h"
- #include "contprop.h"
-
- // *
- // * CContrastProperties
- // *
-
-
- //
- // CreateInstance
- //
- CUnknown *CContrastProperties::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr) {
-
- CUnknown *punk = new CContrastProperties(lpunk, phr);
- if (punk == NULL) {
- *phr = E_OUTOFMEMORY;
- }
-
- return punk;
- }
-
-
- //
- // CContrastProperties::Constructor
- //
- CContrastProperties::CContrastProperties(LPUNKNOWN pUnk, HRESULT *phr)
- : CBasePropertyPage(NAME("Contrast Property Page"),pUnk,phr,
- IDD_CONTRASTPROP, IDS_TITLE)
- , m_pContrast(NULL)
- {
-
- InitCommonControls();
-
- }
-
- // SetDirty
- //
- // Sets m_bDirty and notifies the property page site of the change
- //
- void CContrastProperties::SetDirty()
- {
- m_bDirty = TRUE;
- if (m_pPageSite)
- {
- m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
- }
- }
-
-
- BOOL CContrastProperties::OnReceiveMessage(HWND hwnd,
- UINT uMsg,
- WPARAM wParam,
- LPARAM lParam)
- {
- switch (uMsg)
- {
- case WM_INITDIALOG:
- {
- m_hwndSlider = CreateSlider(hwnd);
- ASSERT(m_hwndSlider);
- return (LRESULT) 1;
- }
- case WM_VSCROLL:
- {
- ASSERT(m_hwndSlider);
- OnSliderNotification(wParam);
- return (LRESULT) 1;
- }
-
- case WM_COMMAND:
- {
- if (LOWORD(wParam) == IDB_DEFAULT)
- {
- pIContrast()->put_DefaultContrastLevel();
- SendMessage(m_hwndSlider, TBM_SETPOS, TRUE, 0L);
- SetDirty();
- }
- return (LRESULT) 1;
- }
-
- case WM_DESTROY:
- {
- DestroyWindow(m_hwndSlider);
- return (LRESULT) 1;
- }
-
- }
- return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam);
- }
-
-
- HRESULT CContrastProperties::OnConnect(IUnknown *pUnknown)
- {
-
- ASSERT(m_pContrast == NULL);
-
- HRESULT hr = pUnknown->QueryInterface(IID_IContrast, (void **) &m_pContrast);
- if (FAILED(hr))
- {
- return E_NOINTERFACE;
- }
-
- ASSERT(m_pContrast);
-
- // Get the initial contrast value
- m_pContrast->get_ContrastLevel(&m_cContrastLevel);
- m_cContrastOnExit = m_cContrastLevel;
- return NOERROR;
- }
-
- HRESULT CContrastProperties::OnDisconnect()
- {
- // Release of Interface after setting the appropriate contrast value
-
- if (m_pContrast == NULL)
- {
- return E_UNEXPECTED;
- }
-
- m_pContrast->put_ContrastLevel(m_cContrastOnExit, 0);
- m_pContrast->Release();
- m_pContrast = NULL;
- return NOERROR;
- }
-
- // We are being deactivated
-
- HRESULT CContrastProperties::OnDeactivate(void)
- {
- // Remember the present contrast level for the next activate
-
- pIContrast()->get_ContrastLevel(&m_cContrastLevel);
-
- return NOERROR;
- }
-
- //
- // Apply
- //
- // Changes made should be kept. Change the m_cContrastOnExit variable.
- // The contrast level will be changed to its value
- // on CContrastProperties::Deactivate.
- //
-
- HRESULT CContrastProperties::OnApplyChanges()
- {
- pIContrast()->get_ContrastLevel(&m_cContrastOnExit);
- m_bDirty = FALSE; // the page is now clean
- return(NOERROR);
-
- }
-
-
- //
- // CreateSlider
- //
- // Create the slider (common control) to allow the user to
- // adjust the contrast
- HWND CContrastProperties::CreateSlider(HWND hwndParent) {
-
- HWND hwndSlider = CreateWindow( TRACKBAR_CLASS
- , TEXT("")
- , WS_CHILD | WS_VISIBLE | WS_TABSTOP | TBS_VERT | TBS_BOTH | WS_GROUP
- , 120, 0
- , 50, 100
- , hwndParent
- , NULL
- , g_hInst
- , NULL
- );
- if (hwndSlider == NULL) {
- DWORD dwErr = GetLastError();
- DbgLog((LOG_ERROR, 1, TEXT("Could not create window: 0x%x"), dwErr));
- return NULL;
- }
-
- // Set the Range
- SendMessage(hwndSlider, TBM_SETRANGE, TRUE, MAKELONG(MinContrastLevel, MaxContrastLevel) );
-
- // Set a tick at zero
- SendMessage(hwndSlider, TBM_SETTIC, 0, 0L);
-
- //
- // Set the slider position according to the value we obtained during
- // initialisation or the last IPropertyPage::Deactivate call
- //
- SendMessage(hwndSlider, TBM_SETPOS, TRUE, m_cContrastLevel);
-
- return hwndSlider;
- }
-
-
- //
- // OnSliderNotification
- //
- // Handle the notification meesages from the slider control
- void CContrastProperties::OnSliderNotification(WPARAM wParam) {
-
- switch (wParam) {
- case TB_BOTTOM:
- SetDirty();
- SendMessage(m_hwndSlider, TBM_SETPOS, TRUE, (LPARAM) MinContrastLevel);
- break;
-
- case TB_TOP:
- SetDirty();
- SendMessage(m_hwndSlider, TBM_SETPOS, TRUE, (LPARAM) MaxContrastLevel);
- break;
-
- case TB_PAGEDOWN:
- case TB_PAGEUP:
- break;
-
- case TB_THUMBPOSITION:
- case TB_ENDTRACK: {
- SetDirty();
- signed char Level = (signed char) SendMessage(m_hwndSlider, TBM_GETPOS, 0, 0L);
- pIContrast()->put_ContrastLevel(Level, 0);
- }
- break;
-
- case TB_THUMBTRACK: // default handling of these messages is ok.
- case TB_LINEDOWN:
- case TB_LINEUP:
- break;
- }
- }
-