Now I feel dumb, re-read the code in the book and it had wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
in it, I just skipped it when typing it in
Now I feel dumb, re-read the code in the book and it had wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
in it, I just skipped it when typing it in
It looks like this code is from chapter 3 of Charles Petzold's Programming Windows. You should note that you can copy the code from CD that comes with the book to your computer, so you needn't type it all in when you want to try out some examples. Also, note that there are several coding errors and typos in the book. Check the link in my signature below for a errata list.
Good guess of where its from. Problem is that in my move I seem to have lost the CD.
Don't know if that's the case. My first window didn't have a HCURSOR, but it wasn't just a "garbage" cursor in the strictest sense; if the cursor changed outside the window, the new cursor would be used inside the window. Maybe that's just Windows98, but I think leaving it blank just tells Windows not to bother changing the cursor when it goes on the window.because otherwise, the hCursor member would be set to any old garbage that was on the stack before wndclass.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Probably, the value present in the memory location of hCursor is simply invalid, ie, it doesn't point to a cursor resource or similar. Windows would then load the default cursor. I suppose it could happen that hCursor gets a value that corresponds to a cursor resource, but that would be unlikely.
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
This result may be the case, but Tada was right when he said, "because otherwise, the hCursor member would be set to any old garbage that was on the stack before wndclass." The fact that hCursor contains garbage does not dictate what will happen to the cursor when you run the program - he was just saying it would contain garbage.Originally posted by Hunter2
Don't know if that's the case. My first window didn't have a HCURSOR, but it wasn't just a "garbage" cursor in the strictest sense; if the cursor changed outside the window, the new cursor would be used inside the window. Maybe that's just Windows98, but I think leaving it blank just tells Windows not to bother changing the cursor when it goes on the window.
It is likely that it contained 0. Especially if you are testing this in debug mode, since I believe all variables are initialized to 0 in debug mode (someone correct me if I am wrong). And from the MSDN page for WNDCLASS:
hCursor
Handle to the class cursor. This member must be a handle to a cursor resource. If this member is NULL, an application must explicitly set the cursor shape whenever the mouse moves into the application's window.
I would assume if an application does NOT set the cursor, it remains the same.
Right, and I always memset the WndClass struct, so it does contain zero or NULL, so since the application is supposed to be the one setting the cursor, Windows will set the cursor outside but won't bother changing it for you once it goes in. If hCursor were a "garbage" value, you would probably get Thantos's problem
Basically, what I meant by "leaving it blank" was "don't change it after the struct has been zeromemoried". Sorry if I miscommunicated...
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Ok, I follow you now - just a misunderstanding. In the context of your reply to Tada's message, I assumed "leaving it blank" implied no initialization whatsoever, as Tada already explained about zeroing out all members of the struct in that very post you (partially) quoted.Originally posted by Hunter2
Basically, what I meant by "leaving it blank" was "don't change it after the struct has been zeromemoried".