Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a custom control from which I want to spawn a new window. Then I want to pass a substantial graphic to the new window to use as a cursor.

I'm hoping to spawn the new window from within the control's OnLButtonDown message handler.

After having done a fair amount of research into how I might do this I think this article 'Set cursor for a child window' purports to solve most nearly the problem I have than anything else I have found...

http://www.cplusplus.com/forum/windows/61689/[^]

I have replicated the call back function and put it in place.

In my OnLButtonDown function I have

HWND hDialog = CreateWindow(WC_DIALOG, _T("Win32 testing"), WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                            200, 200, 500, 400, NULL, NULL, hInst, NULL);

SetWindowLongPtrW(hDialog, DWLP_DLGPROC, &CScrollBarEx::DialogProc);
::SendMessage(hDialog, WM_INIT, 0, (LPARAM)hInst);


but am having trouble getting the SetWindowLongPtrW call to get past the compiler. I have tried a number of casts etc on the last parameter but can't eliminate the following error...

cannot convert parameter 3 from 'INT_PTR (__stdcall CScrollBarEx::* )(HWND,UINT,WPARAM,LPARAM)' to 'LONG'


I am prepared to accept the probable fact that I am completely out of my depth here. If this is the case then please let me know - preferably with a kindly direction towards shallower water...
Posted

I always have trouble using function pointers like this, and as far as I recall the target must be a static function. You also do not need the & (addressOf operator). Try:
C++
SetWindowLongPtr(hDialog, DWLP_DLGPROC, (LONG)CScrollBarEx::DialogProc);

Note that I have removed the W suffix from SetWindowLongPtr, it is best to let the preprocessor add the A or W suffixes based on your project's setting of the define for UNICODE.
 
Share this answer
 
Richard, you are my hero. I have added 'static' to my declaration of DialogProg and now my code compiles.

Edit: Oh yes, and I took out the ampersand, too.

Thank you very much.
 
Share this answer
 
v2
Comments
Richard MacCutchan 12-Jun-14 4:01am    
Thank you for your kind comments. For the record you should post comments using the "Have a Question or Comment?" link below a suggested solution, rather than posting as a new Solution entry. Not really important in this case, but one to remember.
Richard MacCutchan 12-Jun-14 4:02am    
I just noticed your articles, and there are a couple that I am interested in reading.

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