GME  13
TestWindow.cpp
Go to the documentation of this file.
00001 // TestWindow.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "TestWindow.h"
00006 
00007 
00008 #ifdef _DEBUG
00009 #define new DEBUG_NEW
00010 #undef THIS_FILE
00011 static char THIS_FILE[] = __FILE__;
00012 #endif
00013 
00014 
00015 // from GME
00016 typedef enum { GME_NAME_FONT = 0, GME_PORTNAME_FONT, GME_CONNLABEL_FONT, GME_FONT_KIND_NUM } GMEFontKind;
00017 static int  fontSizes[GME_FONT_KIND_NUM]        = { 18, 15, 12 };
00018 
00020 // CTestWindow
00021 
00022 CTestWindow::CTestWindow(const CString& titleStr, const CRect& pos, CScrollZoomView* parent):
00023         parentWindowPtr(parent),
00024         title(titleStr),
00025         position(pos),
00026         created(false)
00027 {
00028         backgroundColor = ::GetSysColor(COLOR_APPWORKSPACE);
00029         canvasBgndColor = RGB(0xFF, 0xFF, 0xFF);
00030 //      txtMetricFont.CreateFont(fontSizes[GME_NAME_FONT], 0, 0, 0, true, 0, 0, 0, ANSI_CHARSET,
00031 //                                                       OUT_DEVICE_PRECIS, CLIP_DEFAULT_PRECIS,
00032 //                                                       PROOF_QUALITY, FF_SWISS, "Arial");
00033 }
00034 
00035 CTestWindow::~CTestWindow()
00036 {
00037 //      txtMetricFont.DeleteObject();
00038 }
00039 
00040 
00041 void CTestWindow::CreateWindowSpecial(const CString& wndClassStr)
00042 {
00043         CRect createPos = position;
00044         CPoint scrollPos = parentWindowPtr->GetDeviceScrollPosition();
00045         scrollPos.x *= -1;
00046         scrollPos.y *= -1;
00047         createPos.OffsetRect(scrollPos);
00048         if (!Create(wndClassStr, title, WS_VISIBLE | WS_CHILD, createPos, parentWindowPtr, 0)) {
00049                 DWORD dw = GetLastError();
00050                 // 0x00000008 ERROR_NOT_ENOUGH_MEMORY "Not enough storage is available to process this command."
00051                 // 0x00000486 ERROR_NO_MORE_USER_HANDLES: The current process has used all of its system allowance of handles for Window Manager objects.
00052                 LPVOID lpMsgBuf;
00053                 FormatMessage(
00054                         FORMAT_MESSAGE_ALLOCATE_BUFFER | 
00055                         FORMAT_MESSAGE_FROM_SYSTEM |
00056                         FORMAT_MESSAGE_IGNORE_INSERTS,
00057                         NULL,
00058                         dw,
00059                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
00060                         (LPTSTR) &lpMsgBuf,
00061                         0, NULL);
00062                 OutputDebugString((LPCSTR)lpMsgBuf);
00063                 LocalFree(lpMsgBuf);
00064                 TRACE1("Failed to create %s\n", (const char*)title);
00065 
00066                 return;
00067         }
00068         created = true;
00069 }
00070 
00071 
00072 void CTestWindow::DestroyWindowSpecial(void)
00073 {
00074         DestroyWindow();
00075         created = false;
00076 }
00077 
00078 
00079 void CTestWindow::MoveWindowSpecial(int deltax, int deltay)
00080 {
00081         position.OffsetRect(deltax, deltay);
00082 
00083         if (created) {
00084                 CRect clientRect;
00085                 GetClientRect(&clientRect);
00086 //              TRACE("ClientRect: %ld, %ld, %ld, %ld\n", clientRect.left, clientRect.top, clientRect.right, clientRect.bottom);
00087                 ClientToScreen(&clientRect);
00088 //              TRACE("AfterScreen: %ld, %ld, %ld, %ld\n", clientRect.left, clientRect.top, clientRect.right, clientRect.bottom);
00089 
00090                 CRect parentWindowRect;
00091                 parentWindowPtr->GetWindowRect(&parentWindowRect);
00092                 clientRect.OffsetRect(deltax - parentWindowRect.left, deltay - parentWindowRect.top);
00093 //              TRACE("AfterOffset: %ld, %ld, %ld, %ld\n", clientRect.left, clientRect.top, clientRect.right, clientRect.bottom);
00094                 MoveWindow(clientRect);
00095         }
00096 }
00097 
00098 
00099 bool CTestWindow::IsIntersectRect(const CRect& rect)
00100 {
00101         CRect intersectRect;
00102         intersectRect.IntersectRect(position, rect);
00103         return !intersectRect.IsRectEmpty();
00104 }
00105 
00106 
00107 BEGIN_MESSAGE_MAP(CTestWindow, CWnd)
00108         //{{AFX_MSG_MAP(CTestWindow)
00109         ON_WM_PAINT()
00110         ON_WM_ERASEBKGND()
00111         ON_WM_LBUTTONDOWN()
00112         //}}AFX_MSG_MAP
00113 END_MESSAGE_MAP()
00114 
00115 
00117 // CTestWindow message handlers
00118 
00119 void CTestWindow::OnPaint()
00120 {
00121         CPaintDC dc(this); // device context for painting
00122 
00123         CRect rcBounds;
00124 //      dc.GetBoundsRect(rcBounds, 0);
00125         GetClientRect(&rcBounds);
00126 
00127 //      TRACE("Paint %s: %ld, %ld, %ld, %ld\n", title, rcBounds.left, rcBounds.top, rcBounds.right, rcBounds.bottom);
00128 
00129         CBrush brush(canvasBgndColor);
00130         dc.FillRect(rcBounds, &brush);
00131         dc.DrawEdge(rcBounds, EDGE_BUMP, BF_RECT);
00132 
00133         CSize textSize = dc.GetTextExtent(title);
00134         dc.SetTextAlign(TA_CENTER);
00135         dc.TextOut(rcBounds.Width() / 2, 2, title);
00136 
00137         // Do not call CWnd::OnPaint() for painting messages
00138 }
00139 
00140 BOOL CTestWindow::OnEraseBkgnd(CDC* pDC)
00141 {
00142 /*      RECT r;
00143         GetClientRect(&r);
00144         pDC->FillSolidRect(&r, backgroundColor);
00145         return TRUE;*/
00146 
00147 //      return CWnd::OnEraseBkgnd(pDC);
00148 
00149         return FALSE;   // kill this message--no default processing
00150 }
00151 
00152 void CTestWindow::OnLButtonDown(UINT nFlags, CPoint point) 
00153 {
00154 //      CGMEEventLogger::LogGMEEvent("CTestWindow::OnLButtonDown\r\n");
00155 
00156         CWnd::OnLButtonDown(nFlags, point);
00157 }