|
-
November 28th, 2007, 04:46 AM
#4
Re: Image dragging
Your approach isn't the standard one, the standard is to use drag and drop for images, but there's a lot of work to do. For your case a color cursor would be enough.
How to create a color cursor...
If you check the cursor functions they use monochrome resources. The catch is to use an icon resource instead of a cursor. Icons can have colors. The system will allow you to execute the SetCursor with an icon handle. The only setback is that you cannot set the position of the hotspot (icons do not have that) but the system will place for you a hot spot right in the center of the image.
(Actually there is a way to create a color cursor with a hotspot in any position but it requires lots of workaround.)
Setting the cursor...
You load the resource, it's ok, it's there. Set the cursor's handle, check it, it's indeed changed to the new handle. Just one problem, despite the fact that the new handle of your color cursor is there, the arrow cursor keeps showing up.
That's because your window class is registered with an arrow cursor and the system will not allow any other cursor beeing used for that window. To be able to change the cursor, the window class must be registered without a cursor handle. To do this, you must change the window class before the window is created. You can do it from PreCreateWindow.
If you use a CView window or one derived from CView here is how to replace the window class with one that doesn't use a cursor handle. The class is identical with the class used by Windows to create CView windows except that it doesn't define a cursor handle:
Code:
BOOL MyAppView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
WNDCLASS wc=
{
CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW,
AfxWndProc,
0,
0,
AfxGetInstanceHandle(),
AfxGetApp()->LoadIcon(AFX_IDI_STD_FRAME),
NULL, // This should be the cursor handle, leave it NULL
CreateSolidBrush(GetSysColor(COLOR_WINDOW)),
NULL,
"MyWndClass"
};
RegisterClass(&wc);
cs.lpszClass=wc.lpszClassName;
return CView::PreCreateWindow(cs);
}
Last edited by srelu; November 28th, 2007 at 04:55 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|