No announcement yet.

"Make into a Resource"

  • Filter
  • Time
  • Show
Clear All
new posts

  • "Make into a Resource"


    I have a static control created as follows:

    hWndStatic = CreateWindowEx(0,"STATIC","NAME",%WS_CHILD OR %WS_VISIBLE OR %SS_BITMAP, _
    rc.nleft,rc.ntop,,rc.nbottom, _
    hWnd, ByVal %NULL, hInst, ByVal %NULL

    This(%SS_BITMAP sytle) will load a bitmap image from the resource using the "NAME" Identifier.
    This Static window will do its own repainting for the Image.

    Now, when I load an image using:

    hBitmap = LoadImage(0,ByVal StrPtr(BmpFileName), %IMAGE_BITMAP,0,0,%LR_LOADFROMFILE)

    I have the handle(hBitmap) to an image in memory. Now I would like to create the static
    control using the above method(%SS_BITMAP) using a Resource Identifier.

    Is it possible to convert this handle(returned by LoadImage) to a Resource Identifier/name?

    Yes, I could do this...

    Create the Static panel, Subclass the control, Load the image into memory, and handle
    the WM_PAINT myself.

    But the above method would be much simpler. (I want this control to be self painting)

    Any tips or help is appreciated!

    Thank you! Jules [email protected]

  • #2
    I reread your question a couple of times and I am still not sure I
    understand what you are asking. I will give it a shot though. Are you
    asking how to change the image in a static control with the SS_BITMAP style?
    Then the following does the trick.

    hBitmap = LoadImage(0,ByVal StrPtr(BmpFileName),
    SendMessage hWndStatic, %STM_SETIMAGE, %IMAGE_BITMAP, hBitmap

    Hmm...I am still scratching my head.

    Dominic Mitchell

    [This message has been edited by Dominic Mitchell (edited September 05, 2000).]
    Dominic Mitchell
    Phoenix Visual Designer


    • #3
      Hi Dominic!

      Sorry for making it clear as Mud. But you made a pretty good guess.

      Let's just narrow it down to this question,
      Can you turn the bitmap that was loaded into memory, into a resource name?

      The message %STM_SETIMAGE works GREAT and the Static control will paint
      itself, as long as the bitmap stays in memory. I think this would
      be okay for what I am doing. I have one default bitmap that could
      be used for many Static(Image) controls and if the user decides to
      change the images, then it is just a matter of saving the Bitmap handles
      for each control and delete them upon the WM_DESTROY message.

      Thank you for your help!

      Regards, Jules

      Thanks! Jules



      • #4
        What has me confused is your use of the term 'resource name'. I take that term
        to mean a string or numeric id from a resource file. The following is a short
        explanation of how I do what you are attempting my program.
        ' Cursor, IconLarge, IconSmall, Picture
        TYPE IMG
          hImage      AS LONG
          bType       AS BYTE                 ' Type of image(IMAGE_ICON, IMAGE_BITMAP etc.)
          bTrans      AS BYTE
          cxImage     AS LONG
          cyImage     AS LONG
          lIdNumber   AS LONG
          szIdSymbol  AS ASCIIZ * 128
          szImage     AS ASCIIZ * 128
          szFile      AS ASCIIZ * %CBPATH
        END TYPE
        The struct above is part of a larger struct of type CONTROLPROP. The hImage
        field is the handle of the image that is currently loaded in the control.
        The important fields here are lIdNumber, szIdSymbol and szFile. These user
        definable fields eventually end up in a resource file. Data for the image is
        acually in two forms unparsed and parsed. The parsed form is the struct shown
        above and the unparsed form(the szFile field). The unparsed form is the generated
        data used for a default value, clipboard data or data in a file and looks as follows
        ' Unparsed formats(examples)
        ' No image- (None)
        ' Stock icon- IDI_WARNING
        ' Custom icon- d:\generic.ico
        ' Custom bmp- d:\toolbox.bmp|TRUE
        This info is in the szFile field and is how the program tracks the use of an image.
        That is, I do not use the image handle for tacking. This allows me to freely copy
        a control between forms of open projects or between parent controls on a from etc.

        Dominic Mitchell
        Dominic Mitchell
        Phoenix Visual Designer