Announcement

Collapse
No announcement yet.

Cursors in PBR files

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cursors in PBR files

    This probably has a simple answer, but how do I load a cursor that
    I have embedded in a PBR file?

    Any direction would be appreciated.

    Jeff

    ------------------

  • #2
    Jeffrey,
    In the RC file:
    Code:
    MYCURSOR CUIRSOR filename.cur
    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!

    Regards,

    ------------------
    [email protected]
    :) IRC :)

    Comment


    • #3
      Ian, Thanks much!

      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?

      Please pardon my ignorance.

      Jeff

      ------------------

      Comment


      • #4
        See GethInst() in your win32api.inc

        Or use the handle from Winmain.

        In case of exe's > 1mb, download my freetips help (See profile)
        There's a problem loading cursors/icons in that case..


        ------------------
        [email protected]
        hellobasic

        Comment


        • #5
          Edwin, thanks for the info.

          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?

          Jeff

          ------------------

          Comment


          • #6
            value& = MAKLNG(loword, hiword)


            ------------------
            Fred
            mailto:[email protected][email protected]</A>
            http://www.oxenby.se

            Fred
            mailto:[email protected][email protected]</A>
            http://www.oxenby.se

            Comment


            • #7
              Thanks Fred,

              The LoadCursor command requires a string parameter, so I am trying
              to get the following to work, with no success.

              hcur&= LoadCursor(GethInst,STR$(MAKLNG(102,0)))

              Any experience in this area?

              Jeff



              ------------------

              Comment


              • #8
                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
                PowerBASIC Support
                mailto:[email protected][email protected]</A>
                Lance
                mailto:[email protected]

                Comment


                • #9
                  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?

                  Jeff

                  ------------------

                  Comment


                  • #10
                    Jeff,

                    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.

                    hCursor = LoadCursor(hInstance,ByVal 3001)
                    SetCursor hCursor

                    If your code changes the cursor dynamically, (for example when you press
                    the left mouse button), you may need to use SetCursor() as well.

                    Regards & good luck with it.

                    [email protected]

                    ------------------
                    hutch at movsd dot com
                    The MASM Forum

                    www.masm32.com

                    Comment


                    • #11
                      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!)

                      hcur&= LoadCursor(GetModuleHandle("dllname.dll"),BYVAL ordinal&)

                      I hope this can help someone else also.

                      Thanks againg guys!!

                      Jeff

                      ------------------

                      Comment


                      • #12
                        It depends HOW you load the DLL!

                        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.


                        ------------------
                        [email protected]
                        hellobasic

                        Comment


                        • #13
                          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.

                          Jeff

                          ------------------

                          Comment


                          • #14
                            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.


                            ------------------
                            [email protected]
                            hellobasic

                            Comment


                            • #15
                              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.



                              ------------------
                              Chris Boss
                              Computer Workshop
                              Developer of "EZGUI"
                              http://cwsof.com
                              http://twitter.com/EZGUIProGuy

                              Comment

                              Working...
                              X