LRESULT CHtmlColorCtrl::OnMouseMove(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/) { CPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); RECT rcClient; if( GetClientRect(&rcClient) ) { if(!m_bTrackingMouse) { TRACKMOUSEEVENT tme; tme.cbSize = sizeof(tme); tme.hwndTrack = m_hWnd; tme.dwFlags = /*TME_HOVER|*/TME_LEAVE; m_bTrackingMouse = TrackMouseEvent(&tme); } m_ptMouse.x=min(pt.x/BOX_SIZE, COL_COUNT-1); m_ptMouse.y=min(pt.y/BOX_SIZE, LINE_COUNT-1); CRect rcBtn(0, LINE_COUNT*BOX_SIZE+20, COL_COUNT*BOX_SIZE, rcClient.bottom); m_bOnButton=rcBtn.PtInRect(pt); if( m_bOnButton ) m_ptMouse.x=m_ptMouse.y=-1; InvalidateRect(&rcClient); } return 0; }
BOOL CExampleDemoDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here // 设置窗口为屏幕宽高 MoveWindow(0, 0, GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)); SetDlgItemInt(ID_MSG, 0); m_tempplate=LoadTemplateImg("template"); //1、动态创建进入下一张图片按钮 CRect rcBtn(20, 0, 120, 15); //按钮高度为15,间隔高度为10 DWORD dwStyle = WS_CHILD | BS_PUSHBUTTON; m_nextimageb = new CButton(); m_nextimageb->Create("下一张", dwStyle, rcBtn, this, IDC_NEXT_BUTTON); //2、动态创建单选框按钮 for (int i = 0; i < m_tempplate.size(); i++) { DWORD dwStyle = WS_CHILD | BS_AUTORADIOBUTTON; rcBtn.top += 25; rcBtn.bottom += 25; CButton *pButton = new CButton(); if (0 == i) { dwStyle |= WS_GROUP; //第一个按钮时添加分组风格 } CString index; index.Format("%d", i); pButton->Create(index, dwStyle, rcBtn, this, IDC_GROUP_BUTTON + i); pButton->SetFont(GetFont()); //设置为父窗口的字体 m_radioList.push_back(pButton); } ::SetWindowPos(this->m_hWnd, HWND_BOTTOM, 200, 0, 1400, 1000, SWP_NOZORDER); return TRUE; // return TRUE unless you set the focus to a control }
DWORD CDrawButton::Click (CWnd* pWnd, CPoint pt, UINT nIDRepeat) const { // don't handle if capture already set if ( ::GetCapture() != NULL || !DB_ISENABLED(m_wStyle) ) { return DB_DEFAULT; } // set capture to the window which received this message pWnd->SetCapture(); ASSERT(pWnd == CWnd::GetCapture()); bool bDown = false, bClick = false; int nSpinType = DB_PRESSED; CRect rcBtn(m_Rect); if ( DB_GETTYPE(m_wStyle) == DB_UPDOWN ) { if ( pt.y >= (rcBtn.top+rcBtn.bottom)/2 ) { nSpinType = DB_PRESSED2; rcBtn.top = (rcBtn.top+rcBtn.bottom)/2; } else { rcBtn.bottom = (rcBtn.top+rcBtn.bottom)/2; } if ( nIDRepeat != 0 ) { s_wNotify = (nSpinType == DB_PRESSED) ? LOWORD(nIDRepeat) : HIWORD(nIDRepeat); if ( !pWnd->SetTimer (nIDRepeat, 100, &CDrawButton_TimerProcRepeat) ) { nIDRepeat = 0; } } } // get messages until capture lost or cancelled/accepted for(;;) //while ( true ) { bool bNewDown = ::PtInRect (rcBtn, pt) != 0; if ( bNewDown != bDown ) { bDown = bNewDown; if ( DB_ISWINDOWDC(m_wStyle) ) { CWindowDC cDC (pWnd); Draw (&cDC, m_wStyle|(bDown ? nSpinType : DB_DEFAULT)); } else { CClientDC cDC (pWnd); Draw (&cDC, m_wStyle|(bDown ? nSpinType : DB_DEFAULT)); } } MSG msg; VERIFY(::GetMessage(&msg, NULL, 0, 0)); if ( CWnd::GetCapture() != pWnd ) { DispatchMessage (&msg); goto ExitLoop; } switch ( msg.message ) { // handle movement messages case WM_MOUSEMOVE: pt.x = (short signed)LOWORD(msg.lParam); pt.y = (short signed)HIWORD(msg.lParam); if ( DB_ISWINDOWDC(m_wStyle) ) { pWnd->ClientToScreen (&pt); pt -= CWindowRect(pWnd).TopLeft(); } break; // handle accept messages case WM_LBUTTONUP: bClick = bDown; goto ExitLoop; // handle cancel messages case WM_KEYDOWN: if ( msg.wParam != VK_ESCAPE ) { break; } // continue... case WM_CANCELMODE: case WM_RBUTTONDOWN: goto ExitLoop; case WM_TIMER: if ( msg.wParam == nIDRepeat && !bDown ) { break; } // continue... default: // just dispatch rest of the messages DispatchMessage (&msg); break; } } ExitLoop: ReleaseCapture(); if ( DB_GETTYPE(m_wStyle) == DB_UPDOWN && nIDRepeat != 0 ) { pWnd->KillTimer (nIDRepeat); } if ( bDown ) { if ( DB_ISWINDOWDC(m_wStyle) ) { CWindowDC cDC (pWnd); Draw (&cDC); } else { CClientDC cDC (pWnd); Draw (&cDC); } } return bClick ? (DB_GETTYPE(m_wStyle)|nSpinType) : DB_DEFAULT; }
DWORD CXTPTabCtrlButton::Click (CXTPTabCtrlButtons* pWnd, CPoint pt, BOOL bRepeat) { if ((::GetCapture() != NULL) || !DB_ISENABLED(m_wStyle)) { return FALSE; } pWnd->SetCapture(); ASSERT(pWnd == CWnd::GetCapture()); BOOL bDown = FALSE, bClick = FALSE; CRect rcBtn(m_Rect); UINT_PTR nTimer = (bRepeat == FALSE) ? 0 : SetTimer(pWnd->GetSafeHwnd(), 1, 150, NULL); for (;;) { if (bRepeat && DB_ISENABLED(m_wStyle)) { ASSERT(m_pTabCtrl); if (!m_pTabCtrl) return FALSE; int nCount = m_pTabCtrl->GetItemCount(); CRect rc; m_pTabCtrl->GetItemRect(-1, rc); TCHITTESTINFO hi = {{5, rc.CenterPoint().y}}; int nFirst = m_pTabCtrl->HitTest(&hi); if (m_wStyle & DB_LEFT) { if (nFirst > 0) m_pTabCtrl->SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, nFirst - 1), 0); } else if (nCount > 0) { m_pTabCtrl->SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, nFirst + 1), 0); } m_pTabCtrl->Invalidate(FALSE); pWnd->Invalidate(FALSE); } BOOL bNewDown = ::PtInRect (rcBtn, pt) != 0; if (bNewDown != bDown) { bDown = bNewDown; if (bDown) m_wStyle = m_wStyle | DB_PRESSED; else m_wStyle &= ~DB_PRESSED; pWnd->InvalidateRect (m_Rect, FALSE); } MSG msg; VERIFY(::GetMessage(&msg, NULL, 0, 0)); if (CWnd::GetCapture() != pWnd) { DispatchMessage (&msg); goto ExitLoop; } switch (msg.message) { case WM_MOUSEMOVE: pt = CPoint((short signed)LOWORD(msg.lParam), (short signed)HIWORD(msg.lParam)); break; case WM_LBUTTONUP: bClick = bDown; goto ExitLoop; case WM_KEYDOWN: if (msg.wParam != VK_ESCAPE) break; case WM_CANCELMODE: case WM_RBUTTONDOWN: goto ExitLoop; default: DispatchMessage (&msg); break; } } ExitLoop: ReleaseCapture(); if (nTimer) KillTimer(*pWnd, nTimer); m_wStyle &= ~DB_PRESSED; CheckForMouseOver (pWnd, pt); pWnd->InvalidateRect (m_Rect, FALSE); return bClick; }