>
Preface: In the programming of the image, this is often encountered, and a large picture is displayed in a limited area. At this point, the various parts of the image are viewed, which requires the scrolling of the image. Regarding its implementation, many books have mentioned, but the key points and difficulties, that is, the refresh and flashing problems in the drag, but there are not many, this is also the purpose of I write this article, and I will analyze in detail below. Implementation. Implementation and implementation: Press the left mouse button in the image area to drag the image arbitrarily rolled in a limited area. The method is: Calculate the offset of this time when dragging, and then changing the starting point of the image display and refreshes the image area. Implementation section: Step 1: Respond to the WM_LBUTTONDOWN message, the record presses the starting position that started dragging. void CWingImgDlg :: OnLButtonDown (UINT nFlags, CPoint point) {// TODO: Add your message handler code here and / or call default m_lPicOldLeft = point.x; m_lPicOldTop = point.y; CDialog :: OnLButtonDown (nFlags, point); } Step 2: Respond to the WM_MOUSEMOVE message, implement scrolling. void CWingImgDlg :: OnMouseMove (UINT nFlags, CPoint point) {// TODO: Add your message handler code here and / or call default file: // If the mouse is pressed if ((nFlags & MK_LBUTTON) == MK_LBUTTON) {m_lPicNewLeft = point.x; m_lPicNewTop = point.y; DWORD dwLRShift = m_lPicNewLeft - m_lPicOldLeft; DWORD dwTBShift = m_lPicNewTop - m_lPicOldTop; file: // change the starting point of the image display m_lPicLeft = m_lPicLeft - dwLRShift; m_lPicTop = m_lPicTop - dwTBShift; file: // Judgment the statement of the boundary, save. M_lpicold = m_lpicnewleft; m_lpicoldtop = m_lpicnewtop; file: // perform refreshed statements, see the fourth step. } Cdialog :: OnMousemove (NFLAGS, POINT);} Step 3: Displayed in onpain, other parts of the display, such as the image of the image, etc. Void cwingimgdlg :: onpaint () {cpaintdc dc (this); // device context for pointing file: // Other display content, province. IF (m_pimginfo! = Null) Dc.bitblt (m_wshowadjleft, m_wshowadjtop, m_lwidth, m_lheight, & m_adjdc, m_lpicleft, m_lpictop, srcopy); cdialog :: onpaint ();} fourth step: refresh processing.