Click here to Skip to main content
16,005,473 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Keyboard buffer Pin
David Crow3-Mar-05 2:02
David Crow3-Mar-05 2:02 
GeneralRe: Keyboard buffer Pin
vidhyas3-Mar-05 2:11
vidhyas3-Mar-05 2:11 
GeneralRe: Keyboard buffer Pin
David Crow3-Mar-05 2:26
David Crow3-Mar-05 2:26 
GeneralRe: Keyboard buffer Pin
vidhyas3-Mar-05 20:24
vidhyas3-Mar-05 20:24 
QuestionHow to add Scroll bars to ActiveX controls? Pin
jahfer3-Mar-05 1:53
jahfer3-Mar-05 1:53 
GeneralGDI+ and ActiveX control Pin
jahfer3-Mar-05 1:46
jahfer3-Mar-05 1:46 
GeneralRe: GDI+ and ActiveX control Pin
Sheng Jiang 蒋晟4-Mar-05 11:57
Sheng Jiang 蒋晟4-Mar-05 11:57 
GeneralDrag and Drop using CImageList, Device contexts and BitBlt Pin
MJWhiteman23-Mar-05 1:41
MJWhiteman23-Mar-05 1:41 
I have a graphical control class, similar to a CListCtrl, and I'm trying to implement drag and drop for it. I've implemented drag and drop for a CListCtrl by creating a CImageList using the CListCtrl's CreateDragImage function, and then Using the CImageList's built in drag and drop functions for animating the dragging.

I'm trying to do something similar with my class (which I'll call CMyClass), but the problem is I don't have a CreateDragImage function that I can call, so I'm trying to create the drag image myself, using WinAPI calls.

I've created some test code, seeing as I'm having problems, which, when the left mouse button is clicked, tries to capture the image of the current object in my list, and then animate it moving across the screen. At the moment, this kind of works, but the image moving across the screen is just a black box which is the same shape as the image I actually want.

There is some test code in the middle which successfully copies the image I want to the clipboard, so that it can be pasted into eg. paintbrush. This suggests to me that the CBitmap is successfully created, and that there's something wrong with the CImageList::Create or CImageList::Add...

void CMyClass::OnLButtonDown(UINT nFlags, CPoint point) <br />
<br />
	CPoint ptCursor = point;<br />
	<br />
	CRect r = this->GetRect();<br />
	<br />
	CImageList DragImage;<br />
	CBitmap CurrentDragImage;	<br />
		<br />
	// Create a DC for the my class<br />
	CDC dc;	<br />
	HDC hdc = ::GetDC(this->hWnd);<br />
	dc.Attach(hdc);<br />
<br />
	// Create a memory DC<br />
	CDC memDC;<br />
	memDC.CreateCompatibleDC(&dc);<br />
<br />
	CSize sz(r.Width(), r.Height());<br />
	CurrentDragImage.CreateCompatibleBitmap(&dc, sz.cx, sz.cy);<br />
	CBitmap * oldbm = memDC.SelectObject(&CurrentDragImage);<br />
<br />
	// Copy the graphics we want to drag to the bitmap<br />
	memDC.BitBlt(0, 0, sz.cx, sz.cy, &dc, r.TopLeft().x, r.TopLeft().y, SRCCOPY);<br />
		<br />
	// ***TEST CODE: This DOES work - it copies the image I want from the screen to the clipboard and can be pasted in pbrush<br />
	this->GetParent()->OpenClipboard();<br />
	::EmptyClipboard();<br />
	::SetClipboardData(CF_BITMAP, (HBITMAP)CurrentDragImage);<br />
	CloseClipboard();<br />
	// ***END TEST CODE		<br />
		<br />
	DragImage.Create(sz.cx, sz.cy, ILC_COLOR32, 0,1);<br />
		<br />
	DragImage.Add(&CurrentDragImage, RGB(0,0,0));<br />
<br />
	DragImage.BeginDrag(0, point);<br />
<br />
	DragImage.DragEnter(this->GetParent(), point);<br />
		<br />
<br />
	for (int i=20; i<200; i++)<br />
	{<br />
		CPoint g;<br />
		g.x = i;<br />
		g.y = i;<br />
		DragImage.DragMove(g);<br />
		<br />
		// Just to slow it down enough to see it	<br />
		for (int h=0; h<20000; h++);<br />
	}<br />
<br />
<br />
}


Does anyone have any ideas why my code isn't working?
Generalsystray menu doesn't hide Pin
ThinkingPrometheus3-Mar-05 1:22
ThinkingPrometheus3-Mar-05 1:22 
GeneralRe: systray menu doesn't hide Pin
Michael Dunn3-Mar-05 8:53
sitebuilderMichael Dunn3-Mar-05 8:53 
Generalproblem in Defining a data member Pin
zahid_ash3-Mar-05 1:09
zahid_ash3-Mar-05 1:09 
GeneralRe: problem in Defining a data member Pin
David Crow3-Mar-05 2:06
David Crow3-Mar-05 2:06 
GeneralRe: problem in Defining a data member Pin
zahid_ash3-Mar-05 2:21
zahid_ash3-Mar-05 2:21 
GeneralRe: problem in Defining a data member Pin
David Crow3-Mar-05 2:30
David Crow3-Mar-05 2:30 
GeneralRe: problem in Defining a data member Pin
zahid_ash3-Mar-05 2:34
zahid_ash3-Mar-05 2:34 
GeneralRe: problem in Defining a data member Pin
Steen Krogsgaard3-Mar-05 3:18
Steen Krogsgaard3-Mar-05 3:18 
GeneralRe: problem in Defining a data member Pin
zahid_ash3-Mar-05 19:31
zahid_ash3-Mar-05 19:31 
GeneralRe: problem in Defining a data member Pin
David Crow4-Mar-05 1:57
David Crow4-Mar-05 1:57 
GeneralDynamic cantrols Pin
Anonymous3-Mar-05 0:42
Anonymous3-Mar-05 0:42 
GeneralRe: Dynamic cantrols Pin
David Crow3-Mar-05 2:08
David Crow3-Mar-05 2:08 
GeneralMFC/ can't reach edit box with mouse Pin
Yaron Abershitz3-Mar-05 0:38
Yaron Abershitz3-Mar-05 0:38 
Generalp/Invoke memory release Pin
ting6683-Mar-05 0:31
ting6683-Mar-05 0:31 
Generalrelease memory used Pin
ting6683-Mar-05 0:29
ting6683-Mar-05 0:29 
GeneralRe: release memory used Pin
jan larsen3-Mar-05 0:48
jan larsen3-Mar-05 0:48 
Questionforce URLDownloadToFile() to &quot;redownload&quot;? Pin
ThinkingPrometheus3-Mar-05 0:00
ThinkingPrometheus3-Mar-05 0:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.