[Csplitterwnd skills 2] Make the split window can't change the size
Author: enoloo
Sometimes, you need to keep the size or proportion of each small window in the split window, and the user is not allowed to drag the split bar. I have considered two ways to be realized. The effect is as follows, the mouse is on the split bar, and there is no arrow that can change the size.
Method 1: =============================================== = // cmysplitter.h # prgma overce
#include "stdafx.h"
Class CMYSPLITTER: PUBLIC CSPLITTERWND {Declare_Dynamic (CMYSPLITTER) PUBLIC: DECLARE_MESSAGE_MAP () protected:
// Remove non-client mouse test function AFX_MSG uint onnchittest (cpoint point);}; ============================= =================== // CMYSPLITTER.CPP # include "cmysplitter.h"
Implement_dynamic (CMYSPLITTER, CSPLITTERWND)
Begin_MESSAGE_MAP (CMYSPLITTER, CSPLITTERW) ON_WM_NCHITTEST () end_MESSAGE_MAP ()
UINT CMYSPLITTER:: ONNCHITTEST (CPOINT POINT) {// Return htnowhere ... return htnowhere;} ================================ ===================
Method 2: =============================================== = // CMYSPLITTER.H # prgma once # include "stdafx.h"
Class Cmysplitter: Public CsplitterWnd {Declare_DyncReate (CMYSPLITTER)
protected: afx_msg void OnLButtonDown (UINT nFlags, CPoint point); afx_msg BOOL OnSetCursor (CWnd * pWnd, UINT nHitTest, UINT message); afx_msg void OnMouseMove (UINT nFlags, CPoint point); DECLARE_MESSAGE_MAP ()}; ====== =================================================== // CMYSPLITTER.CPP
#include "cmysplitter.h"
Implement_dyncreate (CMYSPLITTER, CSPLITTERWND)
Begin_MESSAGE_MAP (CMYSPLITTER, CSPLITTERWND) ON_WM_LBUTTONDOWN () ON_WM_SETCURSOR () ON_WM_MOUSEMOVE () end_MESSAGE_MAP ()
Void CMYSPLITTER :: ONLBUTTONDOWN (UINT NFLAGS, CPOINT) {// Return Return directly;}
Bool CMYSPLITTER :: OnsetCursor (CWND * PWND, UINT NHITTEST, UINT Message) {// When the cursor enters the split window, it is not allowed to change the sample Return False;
Void CMYSPLITTER :: ONMOUSEMOVE (UINT NFLAGS, CPOINT) {// Skip call csplitterWnd :: OnMousemove, because he will cause the cursor change CWnd :: ONMOUSEMOVE (NFLAGS, POINT);} ======== ========================================
Although the two methods are, it is easy to analyze and solve problems from different angles. In fact, in the face of an idea, there may be multiple processing options. If we think seriously, we will find that there will be many ways to meet our requirements.