Cursor

Started by
6 comments, last by cleves 20 years, 8 months ago
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
Advertisement
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

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

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

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

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
You can/should not receive WM_COMMAND before WinMain.

[How To Ask Questions|STL Programmer''s Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
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?
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]
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
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

This topic is closed to new replies.

Advertisement