?
Solved

VC++ DefWindowProc Problem

Posted on 2003-02-24
9
Medium Priority
?
353 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:icegroup
  • 5
  • 4
9 Comments
 
LVL 1

Expert Comment

by:codez80
ID: 8007317
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
0
 
LVL 1

Author Comment

by:icegroup
ID: 8011558
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?
0
 
LVL 1

Expert Comment

by:codez80
ID: 8020068
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:icegroup
ID: 8021063
:)

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 ....
0
 
LVL 1

Expert Comment

by:codez80
ID: 8028715
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
0
 
LVL 1

Author Comment

by:icegroup
ID: 8030133
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 );
0
 
LVL 1

Accepted Solution

by:
codez80 earned 400 total points
ID: 8036726
you are very right on that.
IDC_ARROW is a Windows global object, so when you load it you specify module handle as NULL. there is no need to destroy the cursor after you are finished with it either.
however this is not the case for a resource of your application. you have to specify the module handle explictly and then need to destroy it when you are done with it (except icons).

i'm glad your problem is sorted out...

good luck

codez80
0
 
LVL 1

Author Comment

by:icegroup
ID: 8036825
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.
0
 
LVL 1

Expert Comment

by:codez80
ID: 8040196
i'm afraid I don't, but please let me know if you find something...

thanks

codez80

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question