Archived

This topic is now archived and is closed to further replies.

Cursor

This topic is 5235 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, I''m trying to create that when user press a button the cursor changes. Now i declare this before WM_create as a global: HCURSOR gold = LoadCursor(hinstance, "gold_d.cur"); Then in the WM_command: if (LOWORD(wparam) == 100) { SetCursor(gold); } // end if The only problem is that i need to put hinstance as a global varibale and i don''t know how to do it. Maybe there is another way doing what i want? Thanks in advance

Share this post


Link to post
Share on other sites
quote:
Original post by cleves
The only problem is that i need to put hinstance as a global varibale...

Uhm, go back and read your programming book, somewhere around page 4. A global variable is a variable outside of the scope of any function.

Oh, the hell with it, I''ll show you and get this over with now

#include <windows.h>

HINSTANCE hInstanceGlobal;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR lpCmdLine, int nCmdShow){
hInstanceGlobal=hInstance;
//whatever else you want to do here

}




Do you use your powers for good or for awesome?
My newly updated site | The Cutter Project | Association of Computing Machinery

Share this post


Link to post
Share on other sites
quote:
Original post by cleves
Now i declare this before WM_create as a global:
HCURSOR gold = LoadCursor(hinstance, "gold_d.cur");


Problem is, you can''t (or shouldn''t) do that - try to initialize global variables with a function call (unless you really know what you''re doing). LoadCursor will be called there before your WinMain() even starts.

Have the global variable as
HCURSOR gold = 0; 


and then load it in once your program has started (and your HINSTANCE is available to you).

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4

Share this post


Link to post
Share on other sites
The problem is that i can''t load the icon once the problem has started because the icon needs to change when the user presses a button and that happens in WM_command before the program starts

Share this post


Link to post
Share on other sites
Why not? i learn from the Tricks of the
Windows
Game Programming Gurus

And he advices to do that.

Maybe there is another way to check if a button was clicked?

Share this post


Link to post
Share on other sites
You receive messages using GetMessage or PeekMessage. Those functions take a HWND. That HWND could be NULL but should really be a HWND returned from CreateWindow (or similar), unless you want it to "retrieves messages for any window that belongs to the calling thread and thread messages posted to the calling thread using the PostThreadMessage function".

Tell us what "Tricks of the Windows Game Programming Gurus" says.

Post some code.

[How To Ask Questions|STL Programmer''s Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]

Share this post


Link to post
Share on other sites
Here is the problem i have.
hinstance_app = hinstance;
But the problem is that in his code he dosen''t define the
hinstance_app so i get the error

error C2065: ''hinstance_app'' : undeclared identifier
error C2440: ''='' : cannot convert from ''struct HINSTANCE__ *'' to ''int''
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.

How i need to define hinstance_app so it will work.

thanks

Share this post


Link to post
Share on other sites