• ### Announcements

#### Archived

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

# Cursor

## Recommended Posts

cleves    148
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 on other sites
capn_midnight    1707
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 on other sites
superpig    1825
quote:
Original post by cleves
Now i declare this before WM_create as a global:

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 on other sites
cleves    148
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 on other sites
cleves    148
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 on other sites
dalleboy    324
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 on other sites
cleves    148
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