| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167 |
- // WndEx.cpp : implementation file
- //
- #include "stdafx.h"
- #include "CP_Main.h"
- #include "WndEx.h"
- #include ".\wndex.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CWndEx
- #define CLOSE_WIDTH 12
- #define CLOSE_HEIGHT 11
- #define CLOSE_BORDER 2
- #define TIMER_AUTO_MAX 1
- #define TIMER_AUTO_MIN 2
- CWndEx::CWndEx()
- {
- m_bResizable = true;
- m_bMouseDownOnClose = false;
- m_bMouseOverClose = false;
- m_bMouseDownOnCaption = false;
- m_bMouseOverMinimize = false;
- m_bMouseDownOnMinimize = false;
- m_bMinimized = false;
- m_bMaxSetTimer = false;
- m_lTopBorder = BORDER;
- m_lRightBorder = BORDER;
- m_lBottomBorder = BORDER;
- m_lLeftBorder = BORDER;
-
- SetCaptionColorActive(false, theApp.GetConnectCV());
- }
- CWndEx::~CWndEx()
- {
- }
- void CWndEx::InvalidateNc()
- {
- ::RedrawWindow( m_hWnd, NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_NOCHILDREN );
- }
- void CWndEx::GetWindowRectEx(LPRECT lpRect)
- {
- if(m_bMinimized)
- {
- *lpRect = m_crFullSizeWindow;
- return;
- }
-
- CWnd::GetWindowRect(lpRect);
- }
- bool CWndEx::SetCaptionColors( COLORREF left, COLORREF right )
- {
- if( left == m_CaptionColorLeft || right == m_CaptionColorRight )
- return false;
-
- m_CaptionColorLeft = left;
- m_CaptionColorRight = right;
-
- return true;
- }
- bool CWndEx::SetCaptionColorActive(bool bActive, bool ConnectedToClipboard)
- {
- bool bResult;
- if(ConnectedToClipboard == false)
- {
- bResult = SetCaptionColors(RGB(255, 0, 0), RGB(255, 0, 0));
- }
- else
- {
- if(bActive)
- bResult = SetCaptionColors( ::GetSysColor(COLOR_ACTIVECAPTION), ::GetSysColor(COLOR_GRADIENTACTIVECAPTION) );
- else
- bResult = SetCaptionColors( ::GetSysColor(COLOR_INACTIVECAPTION), ::GetSysColor(COLOR_GRADIENTINACTIVECAPTION) );
- }
-
- return bResult;
- }
- BEGIN_MESSAGE_MAP(CWndEx, CWnd)
- //{{AFX_MSG_MAP(CWndEx)
- ON_WM_CREATE()
- ON_WM_NCPAINT()
- ON_WM_NCCALCSIZE()
- ON_WM_NCHITTEST()
- ON_WM_NCLBUTTONDOWN()
- ON_WM_NCMOUSEMOVE()
- ON_WM_NCLBUTTONUP()
- ON_WM_ERASEBKGND()
- ON_WM_TIMER()
- ON_WM_WINDOWPOSCHANGING()
- ON_WM_INITMENUPOPUP()
- //}}AFX_MSG_MAP
- ON_WM_SIZE()
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CWndEx message handlers
- BOOL CWndEx::Create(const CRect& crStart, CWnd* pParentWnd)
- {
- WNDCLASS wc;
- wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = AfxWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = AfxGetInstanceHandle();
- wc.hIcon = NULL;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "QPasteClass";
-
- // Create the QPaste window class
- if (!AfxRegisterClass(&wc))
- return FALSE;
-
- return CWndEx::CreateEx(0, "QPasteClass", "Quick Paste", WS_POPUP,
- crStart, pParentWnd, 0);
- }
- int CWndEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- m_TitleFont.CreateFont(14,0,-900,0,400,FALSE,FALSE,0,ANSI_CHARSET,
- OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
- DEFAULT_PITCH|FF_SWISS,"Arial");
-
- m_HorFont.CreateFont(14,0,0,0,400,FALSE,FALSE,0,ANSI_CHARSET,
- OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
- DEFAULT_PITCH|FF_SWISS,"Arial");
-
- SetCaptionOn(CGetSetOptions::GetCaptionPos(), true);
- SetAutoHide(CGetSetOptions::GetAutoHide());
-
- return 0;
- }
- void CWndEx::SetAutoHide(BOOL bAutoHide)
- {
- if(bAutoHide)
- {
- SetTimer(TIMER_AUTO_MIN, 500, NULL);
- }
- else
- {
- KillTimer(TIMER_AUTO_MIN);
- }
- }
- void CWndEx::SetCaptionOn(int nPos, bool bOnstartup)
- {
- m_lTopBorder = BORDER;
- m_lRightBorder = BORDER;
- m_lBottomBorder = BORDER;
- m_lLeftBorder = BORDER;
-
- if(nPos == CAPTION_RIGHT)
- m_lRightBorder = CAPTION_BORDER;
- if(nPos == CAPTION_BOTTOM)
- m_lBottomBorder = CAPTION_BORDER;
- if(nPos == CAPTION_LEFT)
- m_lLeftBorder = CAPTION_BORDER;
- if(nPos == CAPTION_TOP)
- m_lTopBorder = CAPTION_BORDER;
-
- SetRegion();
-
- if(!bOnstartup)
- {
- SetWindowPos (NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
- }
-
- RedrawWindow();
- }
- void CWndEx::OnNcPaint()
- {
- CWindowDC dc(this);
-
- CRect rcFrame;
- GetWindowRect(rcFrame);
-
- ScreenToClient(rcFrame);
-
- CRect rc;
- GetClientRect(rc);
-
- ClientToScreen(rc);
-
- long lWidth = rcFrame.Width();
-
- // Draw the window border
- CRect rcBorder(0, 0, lWidth, rcFrame.Height());
-
- COLORREF left = m_CaptionColorLeft;
- COLORREF right = m_CaptionColorRight;
-
- dc.Draw3dRect(rcBorder, left, left);
- rcBorder.DeflateRect(1, 1, 1, 1);
- dc.Draw3dRect(rcBorder, left, left);
-
- rcBorder.InflateRect(1, 1, 1, 1);
-
- BOOL bVertical;
- if(m_lRightBorder == CAPTION_BORDER)
- {
- m_crCloseBT.SetRect(rcBorder.right - m_lRightBorder + 2,
- 7,
- rcBorder.right - m_lRightBorder + 14,
- 18);
-
- m_crMinimizeBT.SetRect(rcBorder.right - m_lRightBorder + 2,
- rcBorder.bottom - 18,
- rcBorder.right - m_lRightBorder + 14,
- rcBorder.bottom - 7);
-
- rcBorder.left = rcBorder.right - m_lRightBorder;
- bVertical = TRUE;
- }
- else if(m_lLeftBorder == CAPTION_BORDER)
- {
- m_crCloseBT.SetRect(2,
- 7,
- 2 + 12,
- 7 + 11);
-
- m_crMinimizeBT.SetRect(2,
- rcBorder.bottom - 18,
- 2 + 12,
- rcBorder.bottom - 7);
-
- rcBorder.right = rcBorder.left + m_lLeftBorder;
- bVertical = TRUE;
- }
- else if(m_lTopBorder == CAPTION_BORDER)
- {
- m_crCloseBT.SetRect(rcBorder.right - 18,
- 3,
- rcBorder.right - 6,
- 3 + 11);
-
- m_crMinimizeBT.SetRect(4,
- 2,
- 15,
- 2 + 12);
-
- rcBorder.bottom = rcBorder.top + m_lTopBorder;
- bVertical = FALSE;
- }
- else if(m_lBottomBorder == CAPTION_BORDER)
- {
- m_crCloseBT.SetRect(rcBorder.right - 18,
- rcBorder.bottom - 13,
- rcBorder.right - 6,
- rcBorder.bottom - 2);
-
- m_crMinimizeBT.SetRect(4,
- rcBorder.bottom - 14,
- 15,
- rcBorder.bottom - 2);
-
- rcBorder.top = rcBorder.bottom - m_lBottomBorder;
- bVertical = FALSE;
- }
- float gR = 0;
- float gG = 0;
- float gB = 0;
-
- float sR = GetRValue(left);
- float sG = GetGValue(left);
- float sB = GetBValue(left);
-
- float eR = GetRValue(right);
- float eG = GetGValue(right);
- float eB = GetBValue(right);
-
- bool bGradient = true;
- if(left == right)
- {
- gR = eR;
- gG = eG;
- gB = eB;
- bGradient = false;
- }
- // calculate the slope for color gradient
- else if(bVertical)
- {
- gR = (eR - sR) / rcBorder.Height();
- gG = (eG - sG) / rcBorder.Height();
- gB = (eB - sB) / rcBorder.Height();
- }
- else
- {
- gR = (eR - sR) / rcBorder.Width();
- gG = (eG - sG) / rcBorder.Width();
- gB = (eB - sB) / rcBorder.Width();
- }
-
- HBRUSH color;
-
- long lHeight = rcBorder.Height();
- CRect cr = rcBorder;
-
- long lCount = rcBorder.Width();
- if(bVertical)
- lCount = lHeight;
- for(int i = 0; i < lCount; i++)
- {
- if(bVertical)
- {
- cr.top = i;
- cr.bottom = i + 1;
- }
- else
- {
- cr.left = i;
- cr.right = i + 1;
- }
- if(bGradient || i == 0)
- {
- color = CreateSolidBrush(RGB(int(gR * (float) i + gR),
- int(gG * (float) i + sG),
- int(gB * (float) i + sB)));
- }
-
- ::FillRect(dc, &cr, color);
- if(bGradient)
- DeleteObject(color);
- }
-
- if(bGradient == false)
- DeleteObject(color);
- /*
- HBRUSH color;
- color = CreateSolidBrush(left);
- ::FillRect(dc, &rcBorder, color);
- DeleteObject(color);
- */
-
-
- int nOldBKMode = dc.SetBkMode(TRANSPARENT);
- COLORREF oldColor = dc.SetTextColor(RGB(255, 255, 255));
- CFont *pOldFont = NULL;
- if(bVertical)
- pOldFont=dc.SelectObject(&m_TitleFont);
- else
- pOldFont=dc.SelectObject(&m_HorFont);
-
- CString csText;
- GetWindowText(csText);
-
- if(m_lRightBorder == CAPTION_BORDER)
- {
- CRect cr;
- cr.SetRect(rcBorder.right-1, 20, rcBorder.right - 13, rcBorder.bottom - 20);
- dc.DrawText(csText, cr, DT_SINGLELINE);
- }
- else if(m_lBottomBorder == CAPTION_BORDER)
- {
- CRect cr;
- cr.SetRect(20, rcBorder.bottom - 15, rcBorder.right - 20, rcBorder.bottom - 1);
- dc.DrawText(csText, cr, DT_SINGLELINE);
- }
- else if(m_lLeftBorder == CAPTION_BORDER)
- {
- CRect cr;
- cr.SetRect(15, 20, 2, rcBorder.bottom - 20);
- dc.DrawText(csText, cr, DT_SINGLELINE);
- }
- else if(m_lTopBorder == CAPTION_BORDER)
- {
- CRect cr;
- cr.SetRect(20, 1, rcBorder.right - 20, 15);
- dc.DrawText(csText, cr, DT_SINGLELINE);
- }
-
- DrawCloseBtn(dc, left);
- DrawMinimizeBtn(dc, left);
-
- dc.SelectObject(pOldFont);
- dc.SetTextColor(oldColor);
- dc.SetBkMode(nOldBKMode);
- }
- void CWndEx::DrawCloseBtn(CWindowDC &dc, COLORREF left)
- {
- if(left == 0)
- left = GetSysColor(COLOR_ACTIVECAPTION);
-
- //rows first then columns
- int Points[5][6] =
- {
- 1,1,0,0,1,1,
- 0,1,1,1,1,0,
- 0,0,1,1,0,0,
- 0,1,1,1,1,0,
- 1,1,0,0,1,1
- };
-
- CPoint ptShift = m_crCloseBT.TopLeft();
- ptShift.Offset(3, 3);
-
- COLORREF shaddow = RGB(GetRValue(left) * 1.16,
- GetGValue(left) * 1.12,
- GetBValue(left) * 1.12);
-
- if(m_bMouseDownOnClose)
- dc.Draw3dRect(m_crCloseBT, shaddow, RGB(255, 255, 255));
- else if(m_bMouseOverClose)
- dc.Draw3dRect(m_crCloseBT, RGB(255, 255, 255), shaddow);
-
- for (int iRow = 0; iRow < 5; iRow++)
- {
- for (int iCol = 0; iCol < 6; iCol++)
- {
- if (Points[iRow][iCol] == 1)
- dc.SetPixel(ptShift+CPoint(iCol, iRow), RGB(255, 255, 255));
- }
- }
- }
- void CWndEx::DrawMinimizeBtn(CWindowDC &dc, COLORREF left)
- {
- if(left == 0)
- left = GetSysColor(COLOR_ACTIVECAPTION);
-
- bool bTopOrBottom = false;
-
- int Points[5][8];
- int Points2[8][5];
- if(((m_lRightBorder == CAPTION_BORDER) && (m_bMinimized == false)) ||
- ((m_lLeftBorder == CAPTION_BORDER) && (m_bMinimized)))
- {
- int nTemp[5][8] =
- {
- 1,1,0,0,1,1,0,0,
- 0,1,1,0,0,1,1,0,
- 0,0,1,1,0,0,1,1,
- 0,1,1,0,0,1,1,0,
- 1,1,0,0,1,1,0,0
- };
- memcpy(&Points, &nTemp, sizeof(nTemp));
- }
- else if(((m_lRightBorder == CAPTION_BORDER) && (m_bMinimized)) ||
- ((m_lLeftBorder == CAPTION_BORDER) && (m_bMinimized == false)))
- {
- int nTemp[5][8] =
- {
- 0,0,1,1,0,0,1,1,
- 0,1,1,0,0,1,1,0,
- 1,1,0,0,1,1,0,0,
- 0,1,1,0,0,1,1,0,
- 0,0,1,1,0,0,1,1
- };
-
- memcpy(&Points, &nTemp, sizeof(nTemp));
- }
- else if(((m_lTopBorder == CAPTION_BORDER) && (m_bMinimized == false)) ||
- ((m_lBottomBorder == CAPTION_BORDER) && (m_bMinimized)))
- {
- bTopOrBottom = true;
-
- int nTemp[8][5] =
- {
- 0,0,1,0,0,
- 0,1,1,1,0,
- 1,1,0,1,1,
- 1,0,0,0,1,
- 0,0,1,0,0,
- 0,1,1,1,0,
- 1,1,0,1,1,
- 1,0,0,0,1
- };
- memcpy(&Points2, &nTemp, sizeof(nTemp));
- }
- else if(((m_lTopBorder == CAPTION_BORDER) && (m_bMinimized)) ||
- ((m_lBottomBorder == CAPTION_BORDER) && (m_bMinimized == false)))
- {
- bTopOrBottom = true;
-
- int nTemp[8][5] =
- {
- 1,0,0,0,1,
- 1,1,0,1,1,
- 0,1,1,1,0,
- 0,0,1,0,0,
- 1,0,0,0,1,
- 1,1,0,1,1,
- 0,1,1,1,0,
- 0,0,1,0,0
- };
- memcpy(&Points2, &nTemp, sizeof(nTemp));
- }
-
- COLORREF shaddow = RGB(GetRValue(left) * 1.16,
- GetGValue(left) * 1.12,
- GetBValue(left) * 1.12);
-
- if(m_bMouseDownOnMinimize)
- dc.Draw3dRect(m_crMinimizeBT, shaddow, RGB(255, 255, 255));
- else if(m_bMouseOverMinimize)
- dc.Draw3dRect(m_crMinimizeBT, RGB(255, 255, 255), shaddow);
-
- if(bTopOrBottom == false)
- {
- CPoint ptShift = m_crMinimizeBT.TopLeft();
- ptShift.Offset(2, 3);
-
- for (int iRow = 0; iRow < 5; iRow++)
- {
- for (int iCol = 0; iCol < 8; iCol++)
- {
- if (Points[iRow][iCol] == 1)
- dc.SetPixel(ptShift+CPoint(iCol, iRow), RGB(255, 255, 255));
- }
- }
- }
- else
- {
- CPoint ptShift = m_crMinimizeBT.TopLeft();
- ptShift.Offset(3, 2);
-
- for (int iRow = 0; iRow < 8; iRow++)
- {
- for (int iCol = 0; iCol < 5; iCol++)
- {
- if (Points2[iRow][iCol] == 1)
- dc.SetPixel(ptShift+CPoint(iCol, iRow), RGB(255, 255, 255));
- }
- }
- }
- }
- void CWndEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
- {
- CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
-
- //Decrease the client area
- lpncsp->rgrc[0].left+= m_lLeftBorder;
- lpncsp->rgrc[0].top+= m_lTopBorder;
- lpncsp->rgrc[0].right-= m_lRightBorder;
- lpncsp->rgrc[0].bottom-= m_lBottomBorder;
- }
- UINT CWndEx::OnNcHitTest(CPoint point)
- {
- if(!m_bResizable)
- return CWnd::OnNcHitTest(point);
-
- //Hit the close button
- // CPoint clPoint(point);
- // ScreenToClient(&clPoint);
- // if(m_crCloseBT.PtInRect(clPoint))
- // return HTCLOSE;
-
-
- CRect crWindow;
- GetWindowRect(crWindow);
-
- if(crWindow.PtInRect(point) == false)
- {
- return CWnd::OnNcHitTest(point);
- }
-
- if(m_bMinimized == false)
- {
- if ((point.y < crWindow.top + BORDER * 2) &&
- (point.x < crWindow.left + BORDER * 2))
- return HTTOPLEFT;
- else if ((point.y < crWindow.top + BORDER * 2) &&
- (point.x > crWindow.right - BORDER * 2))
- return HTTOPRIGHT;
- else if ((point.y > crWindow.bottom - BORDER * 2) &&
- (point.x > crWindow.right - BORDER * 2))
- return HTBOTTOMRIGHT;
- else if ((point.y > crWindow.bottom - BORDER * 2) &&
- (point.x < crWindow.left + BORDER * 2))
- return HTBOTTOMLEFT;
- }
-
- if((((m_lTopBorder == CAPTION_BORDER) || (m_lBottomBorder == CAPTION_BORDER)) &&
- (m_bMinimized)) == false)
- {
- if (point.y < crWindow.top + BORDER * 2)
- return HTTOP;
- if (point.y > crWindow.bottom - BORDER * 2)
- return HTBOTTOM;
- }
-
- if((((m_lLeftBorder == CAPTION_BORDER) || (m_lRightBorder == CAPTION_BORDER)) &&
- (m_bMinimized)) == false)
- {
- if (point.x > crWindow.right - BORDER * 2)
- return HTRIGHT;
- if (point.x < crWindow.left + BORDER * 2)
- return HTLEFT;
- }
-
- if(m_lRightBorder == CAPTION_BORDER)
- {
- if (point.x > crWindow.right - m_lRightBorder)
- return HTCAPTION;
- }
- else if(m_lBottomBorder == CAPTION_BORDER)
- {
- if(point.y > crWindow.bottom - m_lBottomBorder)
- return HTCAPTION;
- }
- else if(m_lLeftBorder == CAPTION_BORDER)
- {
- if (point.x < crWindow.left + m_lLeftBorder)
- return HTCAPTION;
- }
- else if(m_lTopBorder == CAPTION_BORDER)
- {
- if (point.y < crWindow.top + m_lTopBorder)
- return HTCAPTION;
- }
-
- return CWnd::OnNcHitTest(point); // The default handler
- }
- void CWndEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
- {
- CPoint clPoint(point);
- ScreenToClient(&clPoint);
-
- clPoint.x += m_lLeftBorder;
- clPoint.y += m_lTopBorder;
-
- if(m_crCloseBT.PtInRect(clPoint))
- {
- SetCapture();
-
- m_bMouseDownOnClose = true;
-
- CWindowDC dc(this);
- DrawCloseBtn(dc);
- }
- else if(m_crMinimizeBT.PtInRect(clPoint))
- {
- SetCapture();
- m_bMouseDownOnMinimize = true;
- CWindowDC dc(this);
- DrawMinimizeBtn(dc);
- }
-
- CWnd::OnNcLButtonDown(nHitTest, point);
- }
- void CWndEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
- {
- if(m_bMouseDownOnClose)
- {
- ReleaseCapture();
- m_bMouseDownOnClose = false;
- m_bMouseOverClose = false;
-
- OnNcPaint();
-
- CPoint clPoint(point);
- clPoint.x += m_lLeftBorder;
- clPoint.y += m_lTopBorder;
- if(m_crCloseBT.PtInRect(clPoint))
- SendMessage(WM_CLOSE, 0, 0);
- }
- else if(m_bMouseDownOnMinimize)
- {
- ReleaseCapture();
- m_bMouseDownOnMinimize = false;
- m_bMouseOverMinimize = false;
-
- OnNcPaint();
-
- CPoint clPoint(point);
- clPoint.x += m_lLeftBorder;
- clPoint.y += m_lTopBorder;
- if(m_crMinimizeBT.PtInRect(clPoint))
- {
- MinMaxWindow();
- }
- }
-
- CWnd::OnNcLButtonUp(nHitTest, point);
- }
- void CWndEx::MinMaxWindow(long lOption)
- {
- if((m_bMinimized) && (lOption == FORCE_MIN))
- return;
-
- if((m_bMinimized == false) && (lOption == FORCE_MAX))
- return;
-
- if(m_lRightBorder == CAPTION_BORDER)
- {
- if(m_bMinimized == false)
- {
- GetWindowRect(m_crFullSizeWindow);
- MoveWindow(m_crFullSizeWindow.right - CAPTION_BORDER,
- m_crFullSizeWindow.top, CAPTION_BORDER,
- m_crFullSizeWindow.Height());
- m_bMinimized = true;
- OnNcPaint();
- }
- else
- {
- CRect cr;
- GetWindowRect(cr);
- MoveWindow(cr.right - m_crFullSizeWindow.Width(),
- cr.top, m_crFullSizeWindow.Width(), cr.Height());
-
- m_crFullSizeWindow.SetRectEmpty();
- m_bMinimized = false;
- OnNcPaint();
- }
- }
- if(m_lLeftBorder == CAPTION_BORDER)
- {
- if(m_bMinimized == false)
- {
- GetWindowRect(m_crFullSizeWindow);
- MoveWindow(m_crFullSizeWindow.left,
- m_crFullSizeWindow.top, CAPTION_BORDER,
- m_crFullSizeWindow.Height());
- m_bMinimized = true;
- OnNcPaint();
- }
- else
- {
- CRect cr;
- GetWindowRect(cr);
- MoveWindow(cr.left, cr.top,
- m_crFullSizeWindow.Width(), cr.Height());
-
- m_crFullSizeWindow.SetRectEmpty();
- m_bMinimized = false;
- OnNcPaint();
- }
- }
- else if(m_lTopBorder == CAPTION_BORDER)
- {
- if(m_bMinimized == false)
- {
- GetWindowRect(m_crFullSizeWindow);
- MoveWindow(m_crFullSizeWindow.left,
- m_crFullSizeWindow.top,
- m_crFullSizeWindow.Width(),
- CAPTION_BORDER);
- m_bMinimized = true;
- OnNcPaint();
- }
- else
- {
- CRect cr;
- GetWindowRect(cr);
- MoveWindow(cr.left, cr.top,
- cr.Width(), m_crFullSizeWindow.Height());
-
- m_crFullSizeWindow.SetRectEmpty();
- m_bMinimized = false;
- OnNcPaint();
- }
- }
- else if(m_lBottomBorder == CAPTION_BORDER)
- {
- if(m_bMinimized == false)
- {
- GetWindowRect(m_crFullSizeWindow);
- MoveWindow(m_crFullSizeWindow.left,
- m_crFullSizeWindow.bottom - CAPTION_BORDER,
- m_crFullSizeWindow.Width(),
- CAPTION_BORDER);
- m_bMinimized = true;
- OnNcPaint();
- }
- else
- {
- CRect cr;
- GetWindowRect(cr);
- MoveWindow(cr.left,
- cr.bottom - m_crFullSizeWindow.Height(),
- cr.Width(), m_crFullSizeWindow.Height());
-
- m_crFullSizeWindow.SetRectEmpty();
- m_bMinimized = false;
- OnNcPaint();
- }
- }
- }
- void CWndEx::OnNcMouseMove(UINT nHitTest, CPoint point)
- {
- CPoint clPoint(point);
- ScreenToClient(&clPoint);
-
- clPoint.x += m_lLeftBorder;
- clPoint.y += m_lTopBorder;
-
- if(m_crCloseBT.PtInRect(clPoint))
- {
- m_bMouseOverClose = true;
- CWindowDC dc(this);
- DrawCloseBtn(dc);
- }
- else if(m_bMouseOverClose)
- {
- m_bMouseOverClose = false;
- OnNcPaint();
- }
-
- if(m_crMinimizeBT.PtInRect(clPoint))
- {
- m_bMouseOverMinimize = true;
- CWindowDC dc(this);
- DrawMinimizeBtn(dc);
- }
- else if(m_bMouseOverMinimize)
- {
- m_bMouseOverMinimize = false;
- OnNcPaint();
- }
-
- if((m_bMaxSetTimer == false) && m_bMinimized)
- {
- SetTimer(TIMER_AUTO_MAX, 1000, NULL);
- m_bMaxSetTimer = true;
- }
-
- CWnd::OnNcMouseMove(nHitTest, point);
- }
- BOOL CWndEx::PreTranslateMessage(MSG* pMsg)
- {
- if (pMsg->message == WM_NCLBUTTONDOWN)
- {
- m_bMouseDownOnCaption = true;
- }
-
- if ((pMsg->message == WM_LBUTTONUP) && (m_bMouseDownOnCaption))
- {
- m_bMouseDownOnCaption = false;
- pMsg->message = WM_NCLBUTTONUP;
- }
-
- return CWnd::PreTranslateMessage(pMsg);
- }
- /*
- CBitmap m_bitmap;
- CDC dcMem;
-
- void MakeBitmap();
-
-
- CDC dcMem;
- dcMem.CreateCompatibleDC(&dc);
-
- CBitmap *pOldBmp = (CBitmap *)(dcMem.SelectObject(&m_bitmap));
-
- dc.BitBlt(rcBorder.left, 0, rcBorder.Width(), rcBorder.Height(), &dcMem, 0, 0, SRCCOPY);
-
- dcMem.SelectObject(pOldBmp);
-
- dcMem.DeleteDC();
-
-
- void CWndEx::MakeBitmap()
- {
- CWindowDC dc(this);
- CRect rect;
- GetWindowRect(&rect);
-
- CRect rcBorder(0, 0, rect.Width(), rect.Height());
- rcBorder.left = rcBorder.right - RIGHT_CAPTION - BORDER + 1;
-
- rect = rcBorder;
-
- int r1=245,g1=190,b1=240;
- int r2=130,g2=0,b2=0;
-
- int x1=0,y1=0;
- int x2=0,y2=0;
-
- CDC dc2;
- dc2.CreateCompatibleDC(&dc);
-
- if(m_bitmap.m_hObject)
- m_bitmap.DeleteObject();
- m_bitmap.CreateCompatibleBitmap(&dc,rect.Width(),
- rect.Height());
-
- CBitmap *oldbmap=dc2.SelectObject(&m_bitmap);
-
- while(x1 < rect.Width() && y1 < rect.Height())
- {
- if(y1 < rect.Height()-1)
- y1++;
- else
- x1++;
-
- if(x2 < rect.Width()-1)
- x2++;
- else
- y2++;
-
- int r,g,b;
- int i = x1+y1;
- r = r1 + (i * (r2-r1) / (rect.Width()+rect.Height()));
- g = g1 + (i * (g2-g1) / (rect.Width()+rect.Height()));
- b = b1 + (i * (b2-b1) / (rect.Width()+rect.Height()));
-
- CPen p(PS_SOLID,1,RGB(r,g,b));
- CPen *oldpen = dc2.SelectObject(&p);
-
- dc2.MoveTo(x1,y1);
- dc2.LineTo(x2,y2);
-
- dc2.SelectObject(oldpen);
- }
-
- dc2.SelectObject(oldbmap);
- }
- */
- BOOL CWndEx::OnEraseBkgnd(CDC* pDC)
- {
- return CWnd::OnEraseBkgnd(pDC);
- }
- void CWndEx::OnTimer(UINT nIDEvent)
- {
- if(nIDEvent == TIMER_AUTO_MAX)
- {
- if(m_bMinimized)
- {
- CPoint cp;
- GetCursorPos(&cp);
-
- UINT nHitTest = OnNcHitTest(cp);
-
- ScreenToClient(&cp);
-
- if(nHitTest == HTCAPTION)
- {
- if(m_crCloseBT.PtInRect(cp) == false)
- {
- if(m_crMinimizeBT.PtInRect(cp) == false)
- {
- MinMaxWindow(FORCE_MAX);
- }
- }
- }
- }
- KillTimer(TIMER_AUTO_MAX);
- m_bMaxSetTimer = false;
- }
- else if(nIDEvent == TIMER_AUTO_MIN)
- {
- if((m_bMinimized == false) && (g_Opt.m_bShowPersistent))
- {
- CPoint cp;
- CRect cr;
-
- GetCursorPos(&cp);
- GetWindowRect(&cr);
-
- if(cr.PtInRect(cp) == false)
- {
- if(GetFocus() == NULL)
- {
- MinMaxWindow(FORCE_MIN);
- }
- }
- }
- }
-
- CWnd::OnTimer(nIDEvent);
- }
- void CWndEx::OnWindowPosChanging(WINDOWPOS* lpwndpos)
- {
- CWnd::OnWindowPosChanging(lpwndpos);
-
- if(m_bMaxSetTimer)
- {
- KillTimer(TIMER_AUTO_MAX);
- m_bMaxSetTimer = false;
- }
- }
- void CWndEx::SetRegion()
- {
- if((m_lRightBorder == CAPTION_BORDER) ||
- (m_lTopBorder == CAPTION_BORDER))
- {
- //Create the region for drawing the rounded top edge
- CRect rect;
- GetWindowRect(rect);
- CRgn rgnRect, rgnRect2, rgnRound, rgnFinalA, rgnFinalB;
-
- rgnRect.CreateRectRgn(0, 0, rect.Width() - 7, rect.Height());
- rgnRound.CreateRoundRectRgn(0, 0, rect.Width()+1, rect.Height(), 15, 15);
-
- rgnFinalB.CreateRectRgn(0, 0, 0, 0);
- rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
-
- rgnRect2.CreateRectRgn(0, 7, rect.Width(), rect.Height());
- rgnFinalA.CreateRectRgn(0, 0, 0, 0);
- rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
-
- //Set the region
- SetWindowRgn(rgnFinalA, TRUE);
- }
- else if(m_lLeftBorder == CAPTION_BORDER)
- {
- CRect rect;
- GetWindowRect(rect);
- CRgn rgnRect, rgnRect2, rgnRound, rgnFinalA, rgnFinalB;
-
- rgnRect.CreateRectRgn(0, 7, rect.Width(), rect.Height());
- rgnRound.CreateRoundRectRgn(0, 0, rect.Width(), rect.Height(), 15, 15);
-
- rgnFinalB.CreateRectRgn(0, 0, 0, 0);
- rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
-
- rgnRect2.CreateRectRgn(7, 0, rect.Width(), rect.Height());
- rgnFinalA.CreateRectRgn(0, 0, 0, 0);
- rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
-
- //Set the region
- SetWindowRgn(rgnFinalA, TRUE);
- }
- else if(m_lBottomBorder == CAPTION_BORDER)
- {
- CRect rect;
- GetWindowRect(rect);
- CRgn rgnRect, rgnRect2, rgnRound, rgnFinalA, rgnFinalB;
-
- rgnRect.CreateRectRgn(0, 0, rect.Width(), rect.Height()-7);
- rgnRound.CreateRoundRectRgn(0, 0, rect.Width()+1, rect.Height()+1, 15, 15);
-
- rgnFinalB.CreateRectRgn(0, 0, 0, 0);
- rgnFinalB.CombineRgn(&rgnRect, &rgnRound, RGN_OR);
-
- rgnRect2.CreateRectRgn(0, 0, rect.Width()-15, rect.Height());
- rgnFinalA.CreateRectRgn(0, 0, 0, 0);
- rgnFinalA.CombineRgn(&rgnRect2, &rgnFinalB, RGN_OR);
-
- //Set the region
- SetWindowRgn(rgnFinalA, TRUE);
- }
- }
- void CWndEx::OnSize(UINT nType, int cx, int cy)
- {
- CWnd::OnSize(nType, cx, cy);
-
- SetRegion();
- }
- void CWndEx::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
- {
- ASSERT(pPopupMenu != NULL);
- // Check the enabled state of various menu items.
-
- CCmdUI state;
- state.m_pMenu = pPopupMenu;
- ASSERT(state.m_pOther == NULL);
- ASSERT(state.m_pParentMenu == NULL);
-
- // Determine if menu is popup in top-level menu and set m_pOther to
- // it if so (m_pParentMenu == NULL indicates that it is secondary popup).
- HMENU hParentMenu;
- if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
- {
- state.m_pParentMenu = pPopupMenu; // Parent == child for tracking popup.
- }
- else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
- {
- CWnd* pParent = this;
- // Child windows don't have menus--need to go to the top!
- if (pParent != NULL &&
- (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
- {
- int nIndexMax = ::GetMenuItemCount(hParentMenu);
- for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
- {
- if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
- {
- // When popup is found, m_pParentMenu is containing menu.
- state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
- break;
- }
- }
- }
- }
-
- state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
- for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
- state.m_nIndex++)
- {
- state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
- if (state.m_nID == 0)
- continue; // Menu separator or invalid cmd - ignore it.
-
- ASSERT(state.m_pOther == NULL);
- ASSERT(state.m_pMenu != NULL);
- if (state.m_nID == (UINT)-1)
- {
- // Possibly a popup menu, route to first item of that popup.
- state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
- if (state.m_pSubMenu == NULL ||
- (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
- state.m_nID == (UINT)-1)
- {
- continue; // First item of popup can't be routed to.
- }
- state.DoUpdate(this, TRUE); // Popups are never auto disabled.
- }
- else
- {
- // Normal menu item.
- // Auto enable/disable if frame window has m_bAutoMenuEnable
- // set and command is _not_ a system command.
- state.m_pSubMenu = NULL;
- state.DoUpdate(this, FALSE);
- }
-
- // Adjust for menu deletions and additions.
- UINT nCount = pPopupMenu->GetMenuItemCount();
- if (nCount < state.m_nIndexMax)
- {
- state.m_nIndex -= (state.m_nIndexMax - nCount);
- while (state.m_nIndex < nCount &&
- pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
- {
- state.m_nIndex++;
- }
- }
- state.m_nIndexMax = nCount;
- }
- }
|