Link to home
Start Free TrialLog in
Avatar of icegroup
icegroup

asked on

VC++ DefWindowProc Problem

Hi,

I'm fairly new to the .net environment, but comfortable with C++.

I am experiencing something bizarre and looking for help. The .net wizard creates a template for a working application. That template works fine. I am trying to abstract the windows into actual classes - and have most of it working ... except the following.

I assume the default behaviour for the cursor is to change shape when hovering over something, like a border. That still works. What doesn't work is what happens when I drag the mouse back into the client area. The cursor doesn't change to a pointer. If I take the mouse above the client area - into the window's titlebar, it changes to a pointer. If I resize the upper left or right corners, then cross into the client area, I am fine. The cursor is a pointer.

This tells me that the default window proc is being called correctly. And, this is happening before I'm diverting calls to member methods. In other words, I'm not yet leaving the static callback function.

So to be specific, if I start the small exe and the mouse is over it, it becomes an hourglass and stays that way. If I move to the edge, the mouse turns into something like <----> while its over the border, but when I move back over the client area ... it doesn't change back. If I do move to the titlebar of the window, the mouse correctly turns into a pointer.

It seems to me it related to the client area and I have inadvertently turned something off? Maybe the parameters to WNDCLASSEX ?

Thanks,

-Luther
Avatar of codez80
codez80

it is very likely that it is related to WNDCLASS or WNDCLASSEX.

you can handle the message yourself
it is:
WM_SETCURSOR

so, you call SetCursor() and return TRUE if your cursor style is final for that moment

codez80
Avatar of icegroup

ASKER

Thanks. I'll try it.

This might work in this case, but I guess I'm a little afraid that other default behaviours will be missed so I'm still trying to determine what I did to throw the behaviour off.

Does the OS actually call WM_SETCURSOR whenever you hover over something new? and then its up to you to find out what you're hovering over?

In other words, what kind of action triggers a WM_SETCURSOR event? I could easily see using SetCursor when other events occur - on click, while background processing, but the WM_* signal that I'd watch for would be related to the action that happened - I'm wondering what in the world and event like WM_SETCURSOR actually tells you?
when you move cursor (mouse pointer) over a window, Windows sends a message (WM_SETCURSOR) and gives you the chance to set the cursor style you like. don't worry at all, you are not gonna break anything, it is very easy:

in your window proc do this

...
...

if (uMsg == WM_SETCURSOR)
{
   SetCursor(hYourLovelyCursor);
   return TRUE; // 'TRUE' will tell Windows that your cursor is final
}

...
...



codez80
:)

WM_SETCURSOR is managed by the ::DefWindowProc in the Wizard Program that VC++ starts you with ... something I did turned that off - and who knows what else it turned off :)

I'm not concerned about necessarily handling that particular event, as much as finding out why its not handled by default anymore. I'm sure its somewhere in my code.

Thanks very much for you patience ....
you're welcome,

have you used the wizard to create a Win32 application?
if so, double check the line when you are setting the paramters for WNDCLASS (to register the class). if you are loading a cursor other than Windows default cursors such as IDC_ARROW, make sure that resource exists.
the end of the day you are setting the cursor to hourglass style (could I have the code for that), so you should be able to revert back to arrow style in the same way.

if you've created your application by MFC wizard, you probably used AfxGetApp()->BeginWaitCursor(). you can call AfxGetApp()->EndWaitCursor() to revert back  to arrow style cursor.

let us know if it helps

codez80
Ah - you've found it. It works correctly now.

But maybe you can explain why the odd behavior. I used hInstance in LoadCursor where the wizard uses NULL. Is it possible that IDC_ARROW isn't available as a resource - unless used globally? Does the inclusion of hInstance limit the space from where to draw the arrow object?


// WIZARD GENERATED
WNDCLASSEX wcex
...
wcex.hCursor = LoadCursor ( NULL, IDC_ARROW );


// I CREATED (broken/odd)
WNDCLASSEX wcex
...
wcex.hCursor = LoadCursor ( hInstance, IDC_ARROW );
ASKER CERTIFIED SOLUTION
Avatar of codez80
codez80

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks codez80. Do you know of a good newsgroup that focus on windows c/c++ development with visual studio. I just find smatterings here and there. comp.lang.c++ or comp.lang.c++.std are two good example of the technical content I'm looking for. www.codeguru.com seems to have some excellent discussions.
i'm afraid I don't, but please let me know if you find something...

thanks

codez80