Custom dialog box splitter WND

Source: Internet
Author: User

In the following code, the DC drawing coordinate is the screen coordinate. When you press the mouse, the drag and drop splitter is drawn directly on the screen, and the coordinates are also the screen coordinates.

 

The test code is as follows:

 

Crect lrect;
Lrect. Left = lrect. Top = 0;
Lrect. Right = lrect. Bottom = 100;
Cpen lpen (0, 5, RGB (255, 0, 0 ));
Cpen * lopen = Dc. SelectObject (& lpen );

// Set the exception or operation of the paint brush

Int looop2 = Dc. setrop2 (r2_notxorpen );

// Resultcolr = origcolr ^ curpencolr;

// Result color: the original pixel is different or the current paint color

DC. moveTo (0, 0 );
DC. lineto (100,100 );
 
Sleep (1000 );

// Restore the original Pixel

DC. moveTo (0, 0 );
DC. lineto (100,100 );

 

DC. setrop2 (looop2 );
DC. SelectObject (lopen );

 

 

The core code is as follows:

 

Press the mouse:

Void csplittercontrol: onlbuttondown (uint nflags, cpoint point) <br/>{< br/> cstatic: onlbuttondown (nflags, point ); </P> <p> m_bispressed = true; </P> <p> // capture the mouse <br/> setcapture (); <br/> crect rcwnd; <br/> getwindowrect (rcwnd); </P> <p> If (m_ntype = sps_vertical) <br/> m_nx = rcwnd. left + rcwnd. width ()/2; // In the middle of the vertical bar <br/> else <br/> m_ny = rcwnd. top + rcwnd. height ()/2; // In the middle of the horizontal bar </P> <p> If (m_ntype = sps_vertical) <br/> m_nsavepos = m_nx; <br/> else <br/> m_nsavepos = m_ny; </P> <p> // draw on the entire screen, screen coordinates required <br/> cwindowdc DC (null); <br/> drawline (& DC, m_nx, m_ny); <br/>}

 

 

 

Move the cursor:

Void csplittercontrol: onmousemove (uint nflags, cpoint point) <br/>{< br/> If (m_bispressed) <br/>{< br/> cwindowdc (null ); <br/> drawline (& DC, m_nx, m_ny); </P> <p> cpoint Pt = point; <br/> clienttoscreen (& pt ); <br/> getparent ()-> screentoclient (& pt ); // The Screen coordinate conversion is relative to the client coordinate of the parent window </P> <p> // check whether the coordinate is out of the range <br/> If (pt. x <m_nmin) <br/> PT. X = m_nmin; <br/> If (pt. Y <m_nmin) <br/> PT. y = m_nmin; </P> <p> If (pt. x> m_nmax) <br/> PT. X = m_nmax; <br/> If (pt. y> m_nmax) <br/> PT. y = m_nmax; </P> <p> // convert to the channel coordinate <br/> getparent ()-> clienttoscreen (& pt); <br/> m_nx = pt. x; <br/> m_ny = pt. y; </P> <p> drawline (& DC, m_nx, m_ny); <br/>}</P> <p> cstatic: onmousemove (nflags, point); </P> <p >}< br/>

 

Mouse release:

Void csplittercontrol: onlbuttonup (uint nflags, cpoint point) <br/>{< br/> If (m_bispressed) <br/>{< br/> clienttoscreen (& Point ); <br/> cwindowdc DC (null); </P> <p> drawline (& DC, m_nx, m_ny); <br/> cpoint Pt (m_nx, m_ny ); <br/> m_bispressed = false; <br/> cwnd * powner = getowner (); <br/> If (powner & iswindow (powner-> m_hwnd )) <br/>{< br/> crect RC; <br/> int delta; <br/> powner-> getclientrect (RC ); <br/> powner-> screentoclient (& pt); <br/> moveworkflow WTO (PT); </P> <p> If (m_ntype = sps_vertical) <br/> Delta = m_nx-m_nsavepos; <br/> else <br/> Delta = m_ny-m_nsavepos; </P> <p> spc_nmhdr NMSP; </P> <p> NMSP. HDR. hwndfrom = m_hwnd; <br/> NMSP. HDR. idfrom = getdlgctrlid (); <br/> NMSP. HDR. code = spn_sized; <br/> NMSP. delta = delta; <br/> // notify the parent window to adjust the size of each window <br/> powner-> sendmessage (wm_notify, NMSP. HDR. idfrom, (lparam) & NMSP); <br/>}</P> <p> cstatic: onlbuttonup (nflags, point ); <br/> // release Mouse capture <br/> releasecapture (); <br/>}

 

The parent window receives the splitter change notification:

 

If (Message = wm_notify) <br/>{< br/> If (wparam = idc_splitter1) <br/>{< br/> spc_nmhdr * phdr = (spc_nmhdr *) lparam; <br/> csplittercontrol: changewidth (& m_wndtype, phdr-> delta); <br/> csplittercontrol: changewidth (& m_lstitem,-phdr-> delta, cw_rightalign); <br/> csplittercontrol: changewidth (& m_txtcontent,-phdr-> delta, cw_rightalign); <br/> csplittercontrol: changewidth (& m_wndsplitter2, -phdr-> delta, cw_rightalign); <br/>}< br/>}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.