Write the line control yourself, you can display the title above.

xiaoxiao2021-03-06  64

I spent two hours to complete a line control for others, and the title can be displayed above. The email is not convenient, so POST is here. Colorlin.h // Made by zheng017 # prgma overce # include "stdafx.h"

#define COLORLINE_CLASSNAME _T ( "BSColorLine") class ColorLine: public CWnd {public: ColorLine (DWORD dwBkColor = RGB (255,0,0), int iLineHeight = 5, const char * pWndText = "BSColorLine"); ~ ColorLine () DECLARE_DYNCREATE (ColorLine)

protected: BOOL RegisterWindowClass (); HCURSOR m_hHandCursor; bool m_bDrag; bool m_bFirstDrag; CRect m_rectPre; CRect m_rectNow; CRect m_lastTextRect; CPen m_DrawLinePen; DWORD m_dwBkColor; int m_iLineHeight; char m_wndText [256];

DECLARE_MESSAGE_MAP () public: void GetWindowPos (CRect & rect); long PutWindowPos (CRect & rect); long PutWindowText (const char * pWindowText); afx_msg void OnLButtonUp (UINT nFlags, CPoint point); afx_msg void OnLButtonDown (UINT nFlags, CPoint point); afx_msg void OnRButtonUp (UINT nFlags, CPoint point); afx_msg void OnMouseMove (UINT nFlags, CPoint point); afx_msg BOOL OnEraseBkgnd (CDC * pDC); afx_msg void OnPaint ();}; // colorline.cpp made by zheng017 # include " STDAFX.H "#include" colorline.h "

IMPLEMENT_DYNCREATE (ColorLine, CWnd) ColorLine :: ColorLine (DWORD dwBkColor, int iLineHeight, const char * pWndText): m_dwBkColor (dwBkColor), m_iLineHeight (iLineHeight), m_rectNow (0,0,0,0), m_rectPre (0,0, 0,0) {RegisterWindowClass (); m_hHandCursor = LoadCursor (NULL, MAKEINTRESOURCE (32649)); m_DrawLinePen.CreatePen (0,1, m_dwBkColor);! if (pWndText = NULL) lstrcpy (m_wndText, pWndText);}

ColorLine :: ~ colorline () {deleteObject (m_drawlinepen); Destroycursor (m_hhandcursor);

BOOL ColorLine :: RegisterWindowClass () {HINSTANCE hInst = AfxGetInstanceHandle (); WNDCLASS wndcls; if ((:: GetClassInfo (hInst, COLORLINE_CLASSNAME, & wndcls))!) {Wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; wndcls.lpfnWndProc =: : DefWindowProc; wndcls.cbClsExtra = wndcls.cbWndExtra = 0; wndcls.hInstance = hInst; wndcls.hIcon = NULL; wndcls.hCursor = NULL; wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW 1); wndcls.lpszMenuName = NULL; Wndcls.lpszclassName = colorline_classname; if (! AfXRegisterClass (& WndCls)) {AFXTHROWRESOURCEEXCEPTION (); return false;}} return true;

BEGIN_MESSAGE_MAP (ColorLine, CWnd) ON_WM_LBUTTONUP () ON_WM_LBUTTONDOWN () ON_WM_RBUTTONUP () ON_WM_MOUSEMOVE () ON_WM_ERASEBKGND () END_MESSAGE_MAP () void ColorLine :: GetWindowPos (CRect & rect) {GetWindowRect (& rect);} long ColorLine :: PutWindowPos (CRect & rect) { return :: SetWindowPos (GetSafeHwnd (), HWND_TOP, rect.left, rect.top, 0,0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOZORDER);} void ColorLine :: OnLButtonUp (UINT nFlags, CPoint point) {CWnd * pParent = GetParent ( ); if (pParent) {pParent -> InvalidateRect (m_lastTextRect, TRUE);} CWnd :: OnLButtonUp (nFlags, point); ReleaseCapture (); ClipCursor (NULL); SetCursor (LoadCursor (NULL, IDC_ARROW)); m_bDrag = false ;: setwindowpos (GetSafehWnd (), hwnd_top, m_rectpre.left, m_rectpre.top, 0,0, swp_nosize | swp_showwindow | swp_nozorder | swp_framechanged;

} Long ColorLine :: PutWindowText (const char * pWindowText) {lstrcpy (m_wndText, pWindowText); return 0;} void ColorLine :: OnLButtonDown (UINT nFlags, CPoint point) {CWnd :: OnLButtonDown (nFlags, point); SetFocus () ; SetCapture (); SetCursor (m_hHandCursor); CWnd * pParent = GetParent (); pParent-> GetWindowRect (& m_rectNow); m_rectNow.InflateRect (-5, -5, -5, -5); ClipCursor (& m_rectNow); m_bDrag = true; GetWindowRect (& m_rectNow); memset (& m_rectPre, 0x0, sizeof (RECT)); m_bFirstDrag = true;} void ColorLine :: OnRButtonUp (UINT nFlags, CPoint point) {CWnd :: OnRButtonUp (nFlags, point);} void ColorLine :: ONMOUSEMOVE (UINT NFLAGS, CPOINT) {CWND :: OnMousemove (NFLAGS, POINT); if (true == m_bdrag) {CWND * PParent = getParent (); cdc * cdcparent = pParent-> getDC (); if (); True == m_bfirstdrag) {showwindow (sw_hide);

if (cdcParent) {int iOldMode = 0; int iDrawLineCnt = 0;; CPen * pOldPen = (CPen *) cdcParent -> SelectObject (m_DrawLinePen); if (m_rectPre.Width ()> 0) {iOldMode = cdcParent -> SetROP2 ( R2_XORPEN); for (iDrawLineCnt = 0; iDrawLineCnt MoveTo (m_rectPre.left, m_rectPre.top iDrawLineCnt); cdcParent -> LineTo (m_rectPre.right, m_rectPre.top iDrawLineCnt); } cdcParent -> SetROP2 (iOldMode);} int iRectWidth = m_rectNow.Width (); int iRectHeight = m_rectNow.Height (); ClientToScreen (& point); pParent-> ScreenToClient (& point); m_rectNow.left = point.x; m_rectNow .top = point.y; m_rectNow.right = m_rectNow.left iRectWidth; m_rectNow.bottom = m_rectNow.top iRectHeight; if (iRectWidth> 0) {iOldMode = cdcParent -> SetROP2 (R2_XORPEN); for (iDrawLineCnt = 0; iDrawlinecnt moveto (m_rectnow.Left, m_Rectnow.top iDrawlinecnt); cdcparent -> lineto (m_ rectNow.right, m_rectNow.top iDrawLineCnt);} cdcParent -> SetROP2 (iOldMode);} memcpy (& m_rectPre, & m_rectNow, sizeof (RECT));}}} BOOL ColorLine :: OnEraseBkgnd (CDC * pDC) {CBrush backBrush ( m_dwBkColor); CBrush * pOldBrush = pDC-> SelectObject (& backBrush); pDC-> GetClipBox (& m_lastTextRect); pDC-> PatBlt (m_lastTextRect.left, m_lastTextRect.top, m_lastTextRect.Width (), m_lastTextRect.Height (), PATCOPY) PDC-> SelectObject (PoldBrush); if (lstrlen (m_wndtext)> 0 && false == m_bdrag) {CWND * pParent = getParent (); cdc * cdcparent = pParent->

转载请注明原文地址:https://www.9cbs.com/read-84683.html

New Post(0)