//---------------------------------------------------------------------------- // Laser Guard Ltd. // Copyright © 2000-2002. All Rights Reserved. // Version 1.0 01/01/2000 // Last modification: 08/10/2003 // PROJECT: // SUBSYSTEM: // FILE: EventWnd.cpp // AUTHOR: Sergey Chizhevskiy // OVERVIEW // ~~~~~~~~ // Source file of EventWnd.cpp //---------------------------------------------------------------------------- #include "stdafx.h" #include "EventWnd.h" #include "..\LgLib\Version.h" CEventWnd::CEventWnd() { m_hWnd = NULL; m_hMemDC = NULL; m_hMemBitmap = NULL; m_hMemFont = NULL; m_bEnable = TRUE; m_bDebug = FALSE; m_pProfile = NULL; } CEventWnd::~CEventWnd() { Destroy(); } BOOL CEventWnd::Create( BOOL bDebug, HWND hParent, INT x, INT y, INT cx, INT cy, CProfile *pProfile ) { m_pProfile = pProfile; WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc_; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = (HINSTANCE)::GetWindowLong( hParent, GWL_HINSTANCE ); wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = "SINGLE_IPI_EVENT_WINDOW"; wc.hIconSm = NULL; if( !::RegisterClassEx( &wc ) ) return FALSE; m_hWnd = ::CreateWindowEx( /*WS_EX_DLGMODALFRAME|*/WS_EX_CLIENTEDGE, wc.lpszClassName, NULL, WS_CHILD, x, y, cx, cy, hParent, NULL, wc.hInstance, this ); if( !m_hWnd ) return FALSE; ::ShowWindow( m_hWnd, SW_SHOW ); ::UpdateWindow( m_hWnd ); // create icons HDC hDC = ::GetDC( m_hWnd ); m_hIconsDC = ::CreateCompatibleDC( hDC ); m_hIconsBitmap = ::LoadBitmap( wc.hInstance, MAKEINTRESOURCE(IDB_BITMAP_TARGET) ); ::ReleaseDC( m_hWnd, hDC ); // create font LOGFONT lf = {0}; lf.lfHeight = 15; lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = 0; lf.lfItalic = FALSE; lf.lfUnderline = FALSE; lf.lfStrikeOut = FALSE; lf.lfCharSet = ANSI_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = DEFAULT_QUALITY; lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN; _tcscpy(lf.lfFaceName, "Courier"); m_hMemFont = ::CreateFontIndirect( &lf ); m_bDebug = bDebug; return TRUE; } void CEventWnd::Destroy() { if( m_hWnd ) ::DestroyWindow( m_hWnd ); } LRESULT CALLBACK CEventWnd::WindowProc_( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { LPCREATESTRUCT pCreateStruct; switch( uMsg ) { case WM_CREATE: pCreateStruct = (LPCREATESTRUCT) lParam; ::SetWindowLong( hWnd, GWL_USERDATA, (LONG)pCreateStruct->lpCreateParams ); break; } CEventWnd *pThis = (CEventWnd*)::GetWindowLong( hWnd, GWL_USERDATA ); if( pThis ) return pThis->WindowProc( uMsg, wParam, lParam ); return ::DefWindowProc( hWnd, uMsg, wParam, lParam ); } LRESULT CEventWnd::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam ) { switch( uMsg ) { case WM_DESTROY: return OnDestroy( wParam, lParam ); case WM_PAINT: return OnPaint( wParam, lParam ); case WM_SIZE: return OnSize( wParam, lParam ); } return ::DefWindowProc( m_hWnd, uMsg, wParam, lParam ); } LRESULT CEventWnd::OnDestroy( WPARAM wParam, LPARAM lParam ) { if( m_hIconsDC ) { ::DeleteDC( m_hIconsDC ); m_hIconsDC = NULL; } if( m_hIconsBitmap ) { ::DeleteObject( m_hIconsBitmap ); m_hIconsBitmap = NULL; } if( m_hMemDC ) { ::DeleteDC( m_hMemDC ); m_hMemDC = NULL; } if( m_hMemBitmap ) { ::DeleteObject( m_hMemBitmap ); m_hMemBitmap = NULL; } if( m_hMemFont ) { ::DeleteObject( m_hMemFont ); m_hMemFont = NULL; } HWND hWnd = m_hWnd; m_hWnd = NULL; return ::DefWindowProc( hWnd, WM_DESTROY, wParam, lParam ); } LRESULT CEventWnd::OnSize( WPARAM wParam, LPARAM lParam ) { UINT fwSizeType = wParam; INT nWidth = LOWORD(lParam); INT nHeight = HIWORD(lParam); // check old bitmap BOOL bBitmapCreated = FALSE; if( m_hMemBitmap ) { DIBSECTION DibSection; if( ::GetObject( m_hMemBitmap, sizeof(DibSection), &DibSection ) ) { if( DibSection.dsBm.bmWidth == nWidth && DibSection.dsBm.bmHeight == nHeight ) { bBitmapCreated = TRUE; } } } // create new bitmap if( !m_hMemDC || !bBitmapCreated ) { HDC hDC = ::GetDC( m_hWnd ); if( hDC ) { if( !m_hMemDC ) m_hMemDC = ::CreateCompatibleDC( hDC ); if( !bBitmapCreated ) { if( m_hMemBitmap ) ::DeleteObject( m_hMemBitmap ); m_hMemBitmap = ::CreateCompatibleBitmap( hDC, nWidth, nHeight ); } ::ReleaseDC( m_hWnd, hDC ); } } // paint bitmap if( m_hMemDC && m_hMemBitmap ) { HBITMAP hBitmap = (HBITMAP)::SelectObject( m_hMemDC, m_hMemBitmap ); HBRUSH hBrush = ::CreateSolidBrush( RGB(255,255,255) ); if( hBrush ) { RECT rect = { 0, 0, nWidth, nHeight }; ::FillRect( m_hMemDC, &rect, hBrush ); ::DeleteObject( hBrush ); } ::SelectObject( m_hMemDC, hBitmap ); } return 0; } LRESULT CEventWnd::OnPaint( WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT ps; HDC hDC = ::BeginPaint( m_hWnd, &ps ); if( hDC ) OnDraw( hDC ); ::EndPaint( m_hWnd, &ps ); return 0; } void CEventWnd::OnDraw( HDC hDC ) { if( !m_hMemDC || !m_hMemBitmap ) return; DIBSECTION DibSection; if( !::GetObject( m_hMemBitmap, sizeof(DibSection), &DibSection ) ) return; HBITMAP hBitmap = (HBITMAP)::SelectObject( m_hMemDC, m_hMemBitmap ); ::BitBlt( hDC, 0, 0, DibSection.dsBm.bmWidth, DibSection.dsBm.bmHeight, m_hMemDC, 0, 0, SRCCOPY ); ::SelectObject( m_hMemDC, hBitmap ); } void CEventWnd::Reset() { RECT rect; ::GetClientRect( m_hWnd, &rect ); HBITMAP hOldBitmap = (HBITMAP)::SelectObject(m_hMemDC, m_hMemBitmap); ::FillRect(m_hMemDC, &rect, (HBRUSH)::GetStockObject(WHITE_BRUSH)); ::SelectObject(m_hMemDC, hOldBitmap); ::InvalidateRect( m_hWnd, &rect, FALSE ); ::UpdateWindow( m_hWnd ); } void CEventWnd::AddTarget(TARGET_DESCRIPTION& td) { if( !m_bEnable ) return; RECT rect; ::GetClientRect( m_hWnd, &rect ); TCHAR pText[0x500]; HFONT hFont = (HFONT)::SelectObject( m_hMemDC, m_hMemFont ); HBITMAP hOldBitmap = (HBITMAP)::SelectObject(m_hMemDC, m_hMemBitmap); ::ScrollDC(m_hMemDC, 0, 20, &rect, &rect, NULL, NULL); HBRUSH hBrush = ::CreateSolidBrush( RGB(255,255,255) ); if( hBrush ) { RECT fRect = rect; fRect.bottom = rect.top + 20; ::FillRect(m_hMemDC, &fRect, hBrush ); ::DeleteObject( hBrush ); } if( m_bDebug ) { HBITMAP hIconsBitmap = (HBITMAP)::SelectObject( m_hIconsDC, m_hIconsBitmap ); switch(td.master) { case 'a': ::BitBlt( m_hMemDC, 2, 2, 16, 16, m_hIconsDC, 0, 0, SRCCOPY ); break; case 'b': ::BitBlt( m_hMemDC, 2, 2, 16, 16, m_hIconsDC, 0, 16, SRCCOPY ); break; case 'f': ::BitBlt( m_hMemDC, 2, 2, 16, 16, m_hIconsDC, 0, 32, SRCCOPY ); break; case 'w': ::BitBlt( m_hMemDC, 2, 2, 16, 16, m_hIconsDC, 0, 48, SRCCOPY ); break; case 'q': ::BitBlt( m_hMemDC, 2, 2, 16, 16, m_hIconsDC, 0, 64, SRCCOPY ); break; } ::SelectObject( m_hIconsDC, hIconsBitmap ); } // convert angle into user coordinate system double dAngle = m_pProfile->ConvertToUserCoordinate( td.angle ); if( td.master == 'f' ) _stprintf(pText, _T("%02d/%02d/%02d %02d:%02d:%02d DRD "), td.time.wDay, td.time.wMonth, td.time.wYear, td.time.wHour, td.time.wMinute, td.time.wSecond); else if( td.master == 'q' ) { _stprintf( pText, _T("%02d/%02d/%02d %02d:%02d:%02d %3.0f° (dopler)\r\n"), td.time.wDay, td.time.wMonth, td.time.wYear, td.time.wHour, td.time.wMinute, td.time.wSecond, dAngle ); } else #ifdef DRAW_TARGET_WIDTH _stprintf(pText, _T("%02d/%02d/%02d %02d:%02d:%02d %3.0f° %5.1fm. (W %ld)"), td.time.wDay, td.time.wMonth, td.time.wYear, td.time.wHour, td.time.wMinute, td.time.wSecond, dAngle, td.range, td.width ); #else _stprintf(pText, _T("%02d/%02d/%02d %02d:%02d:%02d %3.0f° %5.1fm."), td.time.wDay, td.time.wMonth, td.time.wYear, td.time.wHour, td.time.wMinute, td.time.wSecond, dAngle, td.range ); #endif ::TextOut(m_hMemDC, 20, 0, pText, _tcslen(pText)); ::SelectObject(m_hMemDC, hOldBitmap); ::SelectObject( m_hMemDC, hFont ); ::InvalidateRect( m_hWnd, &rect, FALSE); ::UpdateWindow( m_hWnd ); } void CEventWnd::AddText(LPCTSTR pText) { if( !m_bEnable ) return; RECT rect; ::GetClientRect( m_hWnd, &rect ); HBITMAP hOldBitmap = (HBITMAP)::SelectObject(m_hMemDC, m_hMemBitmap); HFONT hFont = (HFONT)::SelectObject( m_hMemDC, m_hMemFont ); ::ScrollDC(m_hMemDC, 0, 20, &rect, &rect, NULL, NULL); HBRUSH hBrush = ::CreateSolidBrush( RGB(255,255,255) ); if( hBrush ) { RECT fRect = rect; fRect.bottom = rect.top + 20; ::FillRect(m_hMemDC, &fRect, hBrush ); ::DeleteObject( hBrush ); } SYSTEMTIME time; ::GetLocalTime( &time ); TCHAR pBuffer[MAX_PATH]; INT nBuffer = _sntprintf( pBuffer, MAX_PATH, _T("%02d/%02d/%02d %02d:%02d:%02d %s"), time.wDay, time.wMonth, time.wYear, time.wHour, time.wMinute, time.wSecond, pText ); if( nBuffer < 0 ) nBuffer = MAX_PATH; ::TextOut(m_hMemDC, 20, 0, pBuffer, nBuffer ); ::SelectObject( m_hMemDC, hFont ); ::SelectObject(m_hMemDC, hOldBitmap); ::InvalidateRect( m_hWnd, &rect, FALSE); ::UpdateWindow( m_hWnd ); }