Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a picture control in which i have both vertical and horizontal scroll bars so that when i click and drag an region in an image so that if the region of selection is larger in picturecontrol how it automatically scrolls in mfc vc++ dialog based

What I have tried:

C#
m_ROIPicctrl.GetClientRect( &rectStaticClient );
	rectStaticClient.NormalizeRect();
	m_size.cx=rectStaticClient.Size().cx;
	m_size.cy=rectStaticClient.Size().cy;
	m_size.cx = rectStaticClient.Width();    // zero based
	m_size.cy = rectStaticClient.Height();    // zero based

	// Convert to screen coordinates using static as base,
	// then to DIALOG (instead of static) client coords 
	// using dialog as base
	m_ROIPicctrl.ClientToScreen( &rectStaticClient );
	ScreenToClient(&rectStaticClient);

	m_pt.x = rectStaticClient.left;
	m_pt.y = rectStaticClient.top;
	GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo );
	VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew )  );
	CRect irectnew;
	GetDlgItem(IDC_STC_ROIPICCTRL)->GetClientRect(irectnew);
	GetDlgItem(IDC_STC_ROIPICCTRL)->GetWindowRect(irectnew);
	//m_nLastPicctlValue = m_recDispViewWnd.right ;
	ScreenToClient(irectnew);

	
	m_noffsetx= m_pt.x;
	m_noffsety=m_pt.y;
	m_vbar.MoveWindow(m_noffsetx+m_size.cx,m_noffsety,18,m_size.cy);
	m_hbar.MoveWindow(m_noffsetx,m_noffsety+m_size.cy,m_size.cx,18);
	horz.cbSize = sizeof(SCROLLINFO);
	horz.fMask = SIF_ALL;
	horz.nMin = 0;
	horz.nMax = m_bmInfo.bmWidth-m_size.cx;
	horz.nPage =0;
	horz.nPos = 0;
	horz.nTrackPos=0;
	if(m_bmInfo.bmWidth<=m_size.cx)
	{
		if((m_size.cx-m_bmInfo.bmWidth)==0)
			m_noffsetx= m_pt.x;
		else
			m_noffsetx= m_pt.x+((m_size.cx-m_bmInfo.bmWidth)/2);
		m_vbar.MoveWindow(m_noffsetx+m_bmInfo.bmWidth,m_noffsety,18,m_size.cy);
		m_hbar.ShowWindow(false);

	}
	else
		m_hbar.ShowWindow(true);

	m_hbar.SetScrollInfo(&horz);
	vert.cbSize = sizeof(SCROLLINFO);
	vert.fMask = SIF_ALL;
	vert.nMin = 0;
	vert.nMax = m_bmInfo.bmHeight-(m_size.cy);
	vert.nPage = 0;
	vert.nPos = 0;
	vert.nTrackPos=0;
	if(m_bmInfo.bmHeight<=m_size.cy)
	{
		if((m_size.cy-m_bmInfo.bmHeight)==0)
			m_noffsety= m_pt.y;
		else
			m_noffsety= m_pt.y+((m_size.cy-m_bmInfo.bmHeight)/2);
		m_hbar.MoveWindow(m_noffsetx,m_noffsety+m_bmInfo.bmHeight,m_size.cx,18);
		m_vbar.ShowWindow(false);
		//DispImage(m_iplSrc);
	}
	else
		m_vbar.ShowWindow(true);

	m_vbar.SetScrollInfo(&vert);

	//InvalidateRect(&rectStaticClient);
	//}


}
m_vbar.setscrollpos(m_noffsetx);
m_hbar.setscrollpos(m_noffsety);
Posted
Updated 15-Dec-16 1:17am
Comments
Richard MacCutchan 13-Dec-16 4:28am    
What is the problem?
NANDA KUMAR 13-Dec-16 4:38am    
i want to select roi in a picturecontrol and while drag the region of interest the window should move
Richard MacCutchan 13-Dec-16 4:57am    
Scrolling is just a matter of repainting the content in a window in a different position. Have you checked the methods of the control to see how it manages scrolling?

1 solution

You must handle some mouse inputs. Here you find some Microsoft documentations about it.

Handle the Mouse Movement in some message handling functions to do want you want. I think you want to change the offset in your control.

The WM_MOUSEMOVE message could be the right one.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900