GME  13
PanningViewCtrl.cpp
Go to the documentation of this file.
00001 // PanningViewCtrl.cpp : Implementation of the CPanningViewCtrl ActiveX Control class.
00002 
00003 #include "stdafx.h"
00004 #include "PanningView.h"
00005 #include "PanningViewCtrl.h"
00006 #include "PanningViewPropPage.h"
00007 
00008 
00009 #ifdef _DEBUG
00010 #define new DEBUG_NEW
00011 #endif
00012 
00013 
00014 IMPLEMENT_DYNCREATE(CPanningViewCtrl, COleControl)
00015 
00016 
00017 
00018 // Message map
00019 
00020 BEGIN_MESSAGE_MAP(CPanningViewCtrl, COleControl)
00021         //{{AFX_MSG_MAP(CPanningViewCtrl)
00022         ON_WM_CREATE()
00023         //}}AFX_MSG_MAP
00024         ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
00025 END_MESSAGE_MAP()
00026 
00027 
00028 
00029 // Dispatch map
00030 
00031 BEGIN_DISPATCH_MAP(CPanningViewCtrl, COleControl)
00032         //{{AFX_DISPATCH_MAP(CPanningViewCtrl)
00033         DISP_FUNCTION_ID(CPanningViewCtrl, "SetBitmapDC", dispidSetBitmapDC, SetBitmapDC, VT_EMPTY, VTS_UI8 VTS_UI8 VTS_UI8 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_COLOR)
00034         DISP_FUNCTION_ID(CPanningViewCtrl, "SetViewRect", dispidSetViewRect, SetViewRect, VT_EMPTY, VTS_I4 VTS_I4 VTS_I4 VTS_I4)
00035         //}}AFX_DISPATCH_MAP
00036         DISP_FUNCTION_ID(CPanningViewCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
00037 END_DISPATCH_MAP()
00038 
00039 
00040 
00041 // Event map
00042 
00043 BEGIN_EVENT_MAP(CPanningViewCtrl, COleControl)
00044 END_EVENT_MAP()
00045 
00046 
00047 
00048 // Property pages
00049 
00050 // TODO: Add more property pages as needed.  Remember to increase the count!
00051 BEGIN_PROPPAGEIDS(CPanningViewCtrl, 1)
00052         PROPPAGEID(CPanningViewPropPage::guid)
00053 END_PROPPAGEIDS(CPanningViewCtrl)
00054 
00055 
00056 
00057 // Initialize class factory and guid
00058 
00059 IMPLEMENT_OLECREATE_EX(CPanningViewCtrl, "PANNINGVIEW.PanningViewCtrl.1",
00060         0xb0c28baa, 0x7e44, 0x404c, 0xbe, 0xad, 0x83, 0x73, 0x53, 0x56, 0xf1, 0xd2)
00061 
00062 
00063 
00064 // Type library ID and version
00065 
00066 IMPLEMENT_OLETYPELIB(CPanningViewCtrl, _tlid, _wVerMajor, _wVerMinor)
00067 
00068 
00069 
00070 // Interface IDs
00071 
00072 const IID BASED_CODE IID_DPanningView =
00073                 { 0x3055658C, 0xDEFE, 0x4B68, { 0x9B, 0xC3, 0x21, 0xB1, 0x36, 0xBD, 0xBB, 0xDB } };
00074 const IID BASED_CODE IID_DPanningViewEvents =
00075                 { 0xBD4F784C, 0xA79F, 0x48F6, { 0x81, 0x8D, 0xB, 0x82, 0x9A, 0x6, 0x1C, 0xC0 } };
00076 
00077 
00078 
00079 // Control type information
00080 
00081 static const DWORD BASED_CODE _dwPanningViewOleMisc =
00082         OLEMISC_ACTIVATEWHENVISIBLE |
00083         OLEMISC_SETCLIENTSITEFIRST |
00084         OLEMISC_INSIDEOUT |
00085         OLEMISC_CANTLINKINSIDE |
00086         OLEMISC_RECOMPOSEONRESIZE;
00087 
00088 IMPLEMENT_OLECTLTYPE(CPanningViewCtrl, IDS_PANNINGVIEW, _dwPanningViewOleMisc)
00089 
00090 
00091 
00092 // CPanningViewCtrl::CPanningViewCtrlFactory::UpdateRegistry -
00093 // Adds or removes system registry entries for CPanningViewCtrl
00094 
00095 BOOL CPanningViewCtrl::CPanningViewCtrlFactory::UpdateRegistry(BOOL bRegister)
00096 {
00097         // TODO: Verify that your control follows apartment-model threading rules.
00098         // Refer to MFC TechNote 64 for more information.
00099         // If your control does not conform to the apartment-model rules, then
00100         // you must modify the code below, changing the 6th parameter from
00101         // afxRegApartmentThreading to 0.
00102 
00103         if (bRegister)
00104                 return AfxOleRegisterControlClass(
00105                         AfxGetInstanceHandle(),
00106                         m_clsid,
00107                         m_lpszProgID,
00108                         IDS_PANNINGVIEW,
00109                         IDB_PANNINGVIEW,
00110                         afxRegApartmentThreading,
00111                         _dwPanningViewOleMisc,
00112                         _tlid,
00113                         _wVerMajor,
00114                         _wVerMinor);
00115         else
00116                 return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
00117 }
00118 
00119 
00120 
00121 // CPanningViewCtrl::CPanningViewCtrl - Constructor
00122 
00123 CPanningViewCtrl::CPanningViewCtrl()
00124 {
00125         InitializeIIDs(&IID_DPanningView, &IID_DPanningViewEvents);
00126         // TODO: Initialize your control's instance data here.
00127 }
00128 
00129 
00130 
00131 // CPanningViewCtrl::~CPanningViewCtrl - Destructor
00132 
00133 CPanningViewCtrl::~CPanningViewCtrl()
00134 {
00135         // TODO: Cleanup your control's instance data here.
00136 }
00137 
00138 
00139 
00140 // CPanningViewCtrl::OnDraw - Drawing function
00141 
00142 void CPanningViewCtrl::OnDraw(
00143                         CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
00144 {
00145         if (!pdc)
00146                 return;
00147 
00148         if (m_panningViewDlg.GetSafeHwnd()) {
00149                 m_panningViewDlg.MoveWindow(rcBounds, TRUE);
00150         } else {
00151                 AFX_MANAGE_STATE(AfxGetStaticModuleState());
00152                 CBrush brush(RGB(255, 255, 255));
00153                 pdc->FillRect(rcBounds, &brush);
00154 
00155                 CRect edge(rcBounds);
00156                 pdc->DrawEdge(&edge, EDGE_BUMP, BF_RECT);
00157 
00158                 CString label("PanningView OCX");
00159 
00160                 BITMAP bm;
00161                 CBitmap bitmap;
00162                 bitmap.LoadBitmap(IDB_PANNINGVIEW);
00163                 bitmap.GetBitmap(&bm);
00164                 CSize size(bm.bmWidth, bm.bmHeight);
00165                 pdc->DPtoLP(&size);
00166                 CPoint org(0,0);
00167                 pdc->DPtoLP(&org);
00168                 CPoint pos(rcBounds.Width() / 2, rcBounds.Height() / 2 - (pdc->GetTextExtent(label).cy));
00169                 CDC dcMem;
00170                 dcMem.CreateCompatibleDC(pdc);
00171                 CBitmap* oldbitmap = dcMem.SelectObject(&bitmap);
00172                 dcMem.SetMapMode(pdc->GetMapMode());
00173                 pdc->BitBlt(pos.x, pos.y, size.cx, size.cy, &dcMem, org.x, org.y, SRCCOPY);
00174                 dcMem.SelectObject(oldbitmap);
00175 
00176                 pdc->SetTextAlign(TA_CENTER);
00177                 pdc->TextOut(rcBounds.Width() / 2, rcBounds.Height() / 2, CString("PanningView ActiveX Control"));
00178         }
00179 }
00180 
00181 
00182 
00183 // CPanningViewCtrl::DoPropExchange - Persistence support
00184 
00185 void CPanningViewCtrl::DoPropExchange(CPropExchange* pPX)
00186 {
00187         ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
00188         COleControl::DoPropExchange(pPX);
00189 
00190         // TODO: Call PX_ functions for each persistent custom property.
00191 }
00192 
00193 
00194 
00195 // CPanningViewCtrl::OnResetState - Reset control to default state
00196 
00197 void CPanningViewCtrl::OnResetState()
00198 {
00199         COleControl::OnResetState();  // Resets defaults found in DoPropExchange
00200 
00201         // TODO: Reset any other control state here.
00202 }
00203 
00204 
00205 
00206 // CPanningViewCtrl::AboutBox - Display an "About" box to the user
00207 
00208 void CPanningViewCtrl::AboutBox()
00209 {
00210         CDialog dlgAbout(IDD_ABOUTBOX_PANNINGVIEW);
00211         dlgAbout.DoModal();
00212 }
00213 
00214 
00215 
00216 // CPanningViewCtrl message handlers
00217 
00218 int CPanningViewCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
00219 {
00220         if (COleControl::OnCreate(lpCreateStruct) == -1)
00221                 return -1;
00222         
00223         if (m_panningViewDlg.Create(IDD_PANNINGVIEWDLG, this) == FALSE)
00224                 return -1;
00225 
00226         return 0;
00227 }
00228 
00229 BOOL CPanningViewCtrl::PreCreateWindow(CREATESTRUCT& cs) 
00230 {
00231         cs.dwExStyle |= WS_EX_CONTROLPARENT;
00232         return COleControl::PreCreateWindow(cs);
00233 }
00234 
00235 void CPanningViewCtrl::SetBitmapDC(ULONGLONG ownerWnd, ULONGLONG bDC, ULONGLONG oldBmp,
00236                                                                    LONG orix, LONG oriy, LONG oriw, LONG orih,
00237                                                                    LONG rx, LONG ry, LONG rw, LONG rh,
00238                                                                    OLE_COLOR bkgrnd)
00239 {
00240         AFX_MANAGE_STATE(AfxGetStaticModuleState());
00241 
00242         HWND owner = (HWND) ownerWnd;
00243         HDC bdc = (HDC) bDC;
00244         HBITMAP oBmp = (HBITMAP)oldBmp;
00245         CRect ori(orix, oriy, orix + oriw, oriy + orih);
00246         CRect rect(rx, ry, rx + rw, ry + rh);
00247         COLORREF bgColor = TranslateColor(bkgrnd);
00248 
00249         m_panningViewDlg.SetBitmapDC(owner, bdc, oBmp, ori, rect, bgColor);
00250 }
00251 
00252 void CPanningViewCtrl::SetViewRect(LONG vrx, LONG vry, LONG vrw, LONG vrh)
00253 {
00254         AFX_MANAGE_STATE(AfxGetStaticModuleState());
00255 
00256         CRect vrect(vrx, vry, vrx + vrw, vry + vrh);
00257 
00258         m_panningViewDlg.SetViewRect(vrect);
00259 }