#include "SRFramework\SRApp.h" #include "SRSubWindow.h" #include "SRModuleWidget.h" #include "resource.h" using namespace SRFramework; BOOL SRSubWindow::s_fRegistered = false; SRSubWindow::SRSubWindow(SRWnd *pwndSub) :m_wndSub(pwndSub) { m_wcsClassName = "SRSubWindow"; m_wcsWindowName = ""; m_hInstance = SRFramework::SRApp::GetInstanceHandle(); } SRSubWindow::~SRSubWindow() { } BOOL SRSubWindow::Create(SRWnd *pParentWnd, RECT bounds) { RECT rectSub = bounds; rectSub.top += 21; rectSub.left += 2; rectSub.right -= 2; rectSub.bottom -= 2; if(!Register()) return FALSE; if(!SRWnd::Create(m_wcsClassName,m_wcsWindowName,WS_CHILD | WS_VISIBLE, bounds, pParentWnd, NULL, m_hInstance)) return FALSE; if(!m_wndSub || !m_wndSub->Create(this, rectSub)) return FALSE; m_wndSub->Show(); return TRUE; } BOOL SRSubWindow::Register() { // Register window class... WNDCLASS wc; if(s_fRegistered) return TRUE; wc.style = CS_HREDRAW | CS_VREDRAW | CS_PARENTDC; wc.lpfnWndProc = (WNDPROC) MessageRoute; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = m_hInstance; wc.hIcon = NULL; wc.hCursor = 0; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = m_wcsClassName.w_str(); if(RegisterClass(&wc) == 0) return FALSE; s_fRegistered = TRUE; return TRUE; } BOOL SRSubWindow::OnPaint() { RECT clientRect; PAINTSTRUCT ps; HDC hdc = BeginPaint(m_hWnd, &ps); INT nSavedDC = SaveDC(hdc); GetClientRect(m_hWnd, &clientRect); FillRect(hdc, &ps.rcPaint,(HBRUSH)GetStockObject(WHITE_BRUSH)); Rectangle(hdc, clientRect.left, clientRect.top, clientRect.right, 20); Rectangle(hdc, clientRect.left, 20, clientRect.right, clientRect.bottom); HICON icoCl = LoadIcon(m_hInstance, MAKEINTRESOURCE(IDI_CLOSE)); DrawIcon(hdc, clientRect.right - 18, 2, icoCl); RestoreDC(hdc, nSavedDC); EndPaint(m_hWnd, &ps); return TRUE; } void SRSubWindow::MoveWindow(LPCRECT lpRect,BOOL bRepaint) { RECT rectSub; rectSub.top = 20; rectSub.left = 2; rectSub.bottom = lpRect->bottom - lpRect->top - 2; if(rectSub.bottom < 0) rectSub.bottom = 0; rectSub.right = lpRect->right - lpRect->left - 4; if(rectSub.right < 0) rectSub.right = 0; SRWnd::MoveWindow(lpRect,bRepaint); m_wndSub->MoveWindow(&rectSub,bRepaint); } BOOL SRSubWindow::OnLButtonUp(WORD fwKeys, INT xPos, INT yPos) { RECT clientRect; GetClientRect(m_hWnd, &clientRect); if(xPos > clientRect.right - 20 && yPos < clientRect.bottom){ SRModuleWidget *parent = dynamic_cast(m_pParentWnd); if(parent) parent->HideSubWindow(this); return TRUE; } return FALSE; }