?
Solved

VC++ DefWindowProc Problem

Posted on 2003-02-24
9
Medium Priority
?
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

801 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