Announcement

Collapse
No announcement yet.

Icon/Image question

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

  • Scott Turchin
    replied
    When I was in the army we had a saying when we went to the woods:

    "If you brought it in, You take it out"...


    I suppose that still applies!! hehe


    Thanks!

    Scott


    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    Cool. Just keep in mind that if you try this technique with other types of images (other than icons loaded from disk or a resource file), you'll need to clean up the mess.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    OK All is well then.
    The original ICON is loaded with the creation of the IMAGE control, from the resource file taht belongs to the DLL..

    The EXE passes it's hIcon to it, so that i can use this function with any EXE and it's icon will be passed to it...

    It's my awesome CCSShellAbout with the PBURL control in it...hehe, works great..

    Thanks, think I'm clear and I shouldn't need to destroy that icon because it's being used by the EXE...and technically I'm just pas sing a pointer to it....Doh! OK That makes sense..


    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    I have to ask... why change the icon at all, since the dialog has yet to be drawn...? Or is this because the icon is being passed from the EXE? Dah... complicated!

    BTW, please re-read my last message about {not} destroying loaded icons...


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    OK Gotcha, I do understand then!!

    The original image is an ICON loaded into an image, then a flash later I send the control send command to change it to the icon that was sent in...which SHOULD be destroyed, and is by the DestroyObject hIcon that i use..

    That should work?





    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    Scott, I did not mean to panic you before!

    I'm fairly sure DDT releases the curent image during DIALOG END, so your code will be trying to delete an object that has been deleted already.

    Further, if you created a DDT image control with CONTROL ADD IMAGE|IMAGEX|IMGBUTTON|IMGBUTTONX then you must have specified an image for the control to initially load. At the point of closure, this object will remain allocated when your code is used.

    Ideally, if you wish to change the image subsequent to the control being created, you should use the technique I outlined above.

    That said, DeleteObject (or more specifically, DestroyIcon) is not necessary for Icons loaded from a resource or disk file, as the O/S handles that automatically when the module terminates. Icons and Cursors created from scratch created from scratch and all forms of BMP are a different story and these must be destroyed/deleted to avoid a memory leak.

    See http://msdn.microsoft.com/library/ps...icons_5kxa.htm



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    What about this??

    Code:
    Control Set Focus aDlg, %IDCANCEL
    Control Send aDlg, %IDIMAGE1,%STM_SETICON,hIcon,0
    Dialog Show Modal aDlg Call AboutProc  'Goes to dialog proc and ends when user presses ok
    DeleteObject hIcon    
    End Function 'Winmain
    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    I've posted this a few times, but to re-recap:
    Code:
    CONTROL SEND CBHNDL, Id&, %STM_GETIMAGE, %IMAGE_BITMAP, 0 TO hBmp&
    CONTROL SET IMAGE hDlg&, Id&, NewImage$ ' example uses ID from resource file.
    DeleteObject hBmp&

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    Yikes, how do I release that?
    Egads that's a little trick I better learn before I become on NTBUGTRAQ or something hehe..


    ReleaseIcon?


    Scott


    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    Oh Ok, that was not clear, since you commented on this statement in your 1st message. To cap, neither CONTROL SET IMAGE or SendMessage(%STM_SETICON) release the previous image handle, so to avoid a memory leak you must explicitly delete the "old" handle after you set the new icon.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    Lance that won't work because it's in a DLL, unless I could get a string pointer to the EXE's #4011 bitmap (???)
    I was only passing hIcon to the DLL ....



    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Lance Edmonds
    replied
    You could also use CONTROL SET IMAGE|IMAGEX.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    In fact I took it a step further, this works GREAT!
    Thank you!

    Control Send aDlg, %IDIMAGE1,%STM_SETICON,hIcon,0


    Piece of pie (Or is it cake?)


    Scott


    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Scott Turchin
    replied
    Took a bit of fanagaling, made a g_hIcon in the DLL for the hIcon passed to the function:

    g_hIcon = hIcon

    Then in the callback:

    Control Handle aDlg, %IDIMAGE1 To hImage
    SendMessage hImage, %STM_SETICON, g_hIcon, 0


    Life is good, thanks!


    Scott


    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Chris Boss
    replied
    Scott;

    Notice what the PB docs say:

    image$ Name of the bitmap or icon in the resource file (.PBR).
    If the image resource uses an integer identifier, image$ should
    begin with a pound symbol (#), followed by the integer identifier
    in ASCII format. For example, "#998". Otherwise, the text identifier
    name should be used.
    The value for Control Add Image is not an Icon Handle, but a resource
    name or identifier. You can't pass a handle to that command.

    For a Static control use the following :

    Code:
    ' hIcon is the handle (not resource indentifier) returned from
    ' LoadIcon .
    RV& = SendMessage(hButton, %STM_SETICON, hIcon, 0)


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

    Leave a comment:


  • Scott Turchin
    replied
    Hi again,
    Should I have to use DrawIcon, when I am putting it on an Image control?

    I should be able to specify a pointer to the icon, through hIcon itself but how to convert that to a string pointer is beyond me..

    I'll go back and look at the samples, thot I saw it in the pbnote or somewhere...

    But thanks!


    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Hello again,

    It apears as though I connot read very well. I misunderstood what you were asking. So maybe this will help. Try using the API function DrawIcon(hDC,x,y,hIcon).


    ------------------
    Cheers

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Here is a FULL working example.

    Code:
    #compile exe
    #include "win32api.inc"
    
    
    function pbmain as long
        local hdlg as long
        
        dialog new %NULL,"Test",%CW_USEDEFAULT,%CW_USEDEFAULT,256,64,%WS_CAPTION or %WS_SYSMENU to hdlg
        control add label,hdlg,100,format$(%IDI_APPLICATION,"\##"),4,4,32,32,%SS_ICON
        dialog show modal hdlg
    end function
    ------------------
    Cheers

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Hello Scott,

    When you specify a numerical resource ID in a string you must prefix the string with "#". Here is an example...

    Code:
    %IDHELPICON = 1002
    %IDLABEL = -1
    
    control add label,hDialog,%IDLABEL,"#1002",4,4,32,32, etc...
    or

    Code:
    string = format$(%IDHELPICON,"\##")

    I hope that helps

    ------------------
    Cheers

    Leave a comment:


  • Scott Turchin
    started a topic Icon/Image question

    Icon/Image question

    I have an app that has a DLL it calls to display my generic Help->About box.

    I send an Icon to the function in the form of hIcon (From LoadIcon Api)..

    How would I display this on the screen?

    I'm using control add Image in this format with a DLL built in icon and it works.
    I send it an icon and well, it's just a question of how to insert it I suppose:


    'This works fine with built in image #2015 (an icon in the resource file)
    Control Add Image, aDlg, %IDIMAGE1, "#2015",5,5,18,18


    I recall seeing using a pointer in times gone by and had some issues with that..


    Thanks

    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    [This message has been edited by Scott Turchin (edited January 21, 2001).]
Working...
X