You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
In your program
... Load the cursor into GDI using the window Instance handle
Code:
hCursor = LoadCursor(hInstance, "MYCURSOR")
... Set the cursor for the current window
Code:
CASE %WM_SETCURSOR
CALL SetCursor(hCursor)
FUNCTION = 0
' Do not allow default processing for this message, or your cursor reverts to the default window cursor.
' remember to destroy the cursor handle later!
I have known about the process you mentioned, however, I,m not sure what
value to use for the "hInstance" parameter. Is this the window handle (hWnd)
or something else?
I need to load the cursor from a PBR file by ordinal. The WIN32
documentation say I need to convert the ordinal number into a suitable
form using the MAKEINTRESOURCE macro. This apparently is not avaiable
under PBDLL. Does anyone know of a work around?
The 2nd parameter works a little like a UNION... it can take a pointer to a string, or a DWORD/LONG value. The API determines what was passed my it's actual value.
Code:
hcur&= LoadCursor(GethInst, BYVAL MAKLNG(102,0))
or
hcur&= LoadCursor(GethInst, BYVAL 102&)
Lance, thanks again. I'm clear on the resources now.
However, the call still does not work. I was not entirely clear
on what I am doing. I have a DLL file with an attached PBR resource
that is being called from a VB program. I want to extract a cursor resource
from the PBR file. Is the "GethInst" looking at the DLL resources
or the calling EXE resources?
As long as you have a valid cursor as a resource, they should be no
problem to use. The first parameter for LoadCursor() is either the
instance handle of the application if it is a custom cursor or NULL
if you use a standard system cursor.
In a WNDCLASSEX structure, you set the cursor for a particular window
with the following, (in this instance, a standard system cursor).
wcex.hCursor = LoadCursor(%NULL,ByVal %IDC_ARROW)
For a custom cursor, you specify the instance handle of the application
and the resource ID, you can mess around and use a string to identify the
cursor but the Microsoft literature says a numeric ID is more efficient.
To use a numeric ID for the cursor, you need to use ByVal and the number
of the resource.
Thanks to all of you for the input. I picked up a few tips.
However, if you wish to load a cursor which is embedded in a DLL
that is called from another process, you can't read the
DLL resources with the PB GethInst function. The GethInst uses
the GetModuleHandle function with byval %NULL as its parameter.
According to the MS documentation, this will return the instance
handle of the calling application. This was the question I was
asking about previously. To load a cursor from a resource file
embedded in an external DLL, it works this way (at least for me
it does!)
If a call is declared in your app to this DLL, no problem, PB will load the DLL and your solution works.
If you only use it as resource you NEED to load it first..
Using LoadLibrary and Freelibrary.
Loadlibrary is ALLWAYS the best choice because it will allways retrun the same hInstance you need.
But in this case you allways should use freelibrary.
Unf. there's in no double-load for DLL's, in this case you have succes.
Edwin, good point. You're right, I am calling the DLL using a declare
within a VB program. I'm not really sure what benefit I would get
using LoadLibrary though.
You should read the help on this matter. (implicit etc..)
PB loads the DLL imm.
VB does NOT.
The returned handle might be 0.
Force the DLL load by calling a procedure (dummy)
If not possible use loadlibrary wich retuens the nec. handle.
For cleanup purposes, you should use Freelibrary afterwards.
Be sure the DLL is loaded..
PB does not load the DLL if no procedure is implemented IN your code.
And i don't mean the declare, it does not make the DLL load.
You can also include a Function in the DLL for retrieving any
resource in the DLL. In the LibMain function an instance handle is
passed to the DLL. Using this, code in the DLL has easy access to
the resources (including cursors). Lets say you have 10 cursors in
the DLL, then you could have a function :
Function GetCursor(BYVAL N&) as LONG
In this function get the handle to the resource using the DLL
instance handle passed to the DLL in LibMain (put it in a Global
variable). The parameter N& would be the cursor number (or you
could use a string parameter if you wanted to do it by name).
The function could return the handle to the cursor for use in the
main app. You wouldn't not need to use loadlibrary, since once
you declared the function above for retrieving the cursors, the
DLL would be automatically loaded into your apps process space.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment