[Three] CSplitterWnd skills of the splitter can be dragged with the background color: enloo
I want to achieve this feature, I have plagued me for a while, and later found some small mistakes.
Function: 1, with background color 2, drag dragbars, can drag the window
The effect is as follows:
Procedure: ================================================= == // MySplitter.h # pragma once # include "stdafx.h" class CMySplitter: public CSplitterWnd {public: CMySplitter (); DECLARE_DYNCREATE (CMySplitter) public: ~ CMySplitter (); protected: afx_msg void OnLButtonDown (UINT nFlags, CPoint point); afx_msg void OnMouseMove (UINT, CPoint); BOOL PreCreateWindow (CREATESTRUCT & cs); protected: HBRUSH m_hbr; // background brush CString m_clsName; // window class name DECLARE_MESSAGE_MAP ()}; ========= ==================================================================================================================================================================================================================================================================================================Plitter .h "
Implement_dyncreate (CMYSPLITTER, CSPLITTERWND)
CMYSPLITTER :: CMYSPLITTER () {m_cxsplitter = 4; // must> = 4 m_cybordershare = -4; m_cxsplittergap = 16; m_Cysplittergap = 16; // splitter Drag width
m_hbr = :: Createsolidbrush (RGB (98, 98, 98)); m_clsname = "";
CMYSPLITTER :: ~ cmysplitter () {}
Begin_MESSAGE_MAP (CMYSPLITTER, CSPLITTERWND) ON_WM_LBUTTONDOWN () ON_WM_MOUSEMOVE () ON_WM_RBUTTONDOWN () end_MESSAGE_MAP ()
void CMySplitter :: OnLButtonDown (UINT nFlags, CPoint point) {// splitter dragging the drag bar, the window can be dragged :: PostMessage (AfxGetMainWnd () -> GetSafeHwnd (), WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM (point.x, point .y); cWnd :: ONLBUTTONDOWN (NFLAGS, POINT);} void cmysplitter :: OnMouseMove (uint nflags, cpoint point) {// Skip call csplitterWnd :: OnMousemove, because he will cause the cursor change CWnd :: OnMousemove (nflags, point);
Bool CMYSPLITTER :: PrecreateWindow (CreateStruct & Cs) {// Window class name must be valid in the class class of the class, otherwise CreateWindowEx gets an invalid class name. // will result in an error that creates a document failed. m_clsName = AfxRegisterWndClass (0, :: LoadCursor (NULL, IDC_ARROW), :: CreateSolidBrush (RGB (255,95,17))); cs.lpszClass = (const char *) m_clsName; return CSplitterWnd :: PreCreateWindow (cs); } ==================================================== =
Note: 1. To implement the dragbark to drag the window, you cannot simply return to HTCAption with the onnchittest introduced by skill 2 to return. Because this can only drag the split window and cannot be dragged the main window. Here is taken here :: PostMessage (AFXGETMAIND () -> getSafehWnd (), WM_NCLBUTTOND (), HTCAPTION, MAKELPAR (Point.x, Point.y)), send a WM_NCLBUTTONDOWN message with HTCAPTION to the main window to implement .
2, the default segmentation window name is AFXMDIFRAME42D, which is similar to the main window in the MDI program, no background brush. A new window class here and specify the background brush. It should be noted that the window class name cannot be declared in PreCreateWindow, and should be placed in the state of the class as a member of the class.