Assign and image

Posted on 2005-05-13
Last Modified: 2010-04-05
I am working with dialog boxes and am looking for a way to change an image within the dialog box by code to one from a resource file.

I have used LoadImage to load the image with no problem but cannot figure out how to assign it to the control in the dialog box (i have tried SendMessge, SendDlgItemMessage and others but they don't work)

Can anyone help?
Question by:GroundFloor
    LVL 33

    Expert Comment

    what is the control?

    some other?
     I am guessing that the dialog control already is showing an Image?

    and what message do you use?
    LVL 15

    Expert Comment

    If your trying to change the image for a message dialog, take a look at

    Author Comment

    its a CONTROL, SS_BITMAP with an ID of 188

    I can add the graphic if i add the resource into the same dialog creation script but if i add the graphic as a resource and try to add it it is then i run into the problem of what command to use to assign the image to the control.

    Author Comment

    aslo, i looked through and couldn't find anything about it.
    LVL 33

    Accepted Solution

    if you are using API then you better get use to constantly looking at and reading the Win32 Help, if you look at the Help for static controls you can see the messages that are just for STATIC controls, these messages include -

    here is some code from the Help -

    SendDlgItemMessage(hDlg,  /* dialog box window handle */
                   IDI_ICON,              /* icon identifier          */
                   STM_SETIMAGE,          /* message to send          */
                   (WPARAM) IMAGE_ICON,   /* image type               */
                   (LPARAM) aIcons[i++]); /* icon handle              */

    in Pascal -

    SendDlgItemMessage(hDlg, 188,  STM_SETIMAGE, IMAGE_BITMAP, hBitmap);

    maybe this will work?

    Author Comment

    Thanks Slick812

    I looked in the Win32 Help and on MSDN but didn't find anything about STM_IMAGE.

    I am using your suggestion of SendDlgItemMessage but the image is not displaying - but i think that may be something i am doing wrong and am trying different ways to see if i can get it to work.

    Maybe you should write a book about all of this - i would buy it because there is nothing of use out there.

    LVL 33

    Expert Comment

    are you sure that your LoadImage is not returning Zero? You need a valid bitmap Handle, , , ,
    there are only 5 parameters in the SendDlgItemMessage( ), have you checked all 5 to see if they are valid?

    as to the MSDN Library, I could not beleive that you got nothing for a STM_SETIMAGE search so I went to the MSDN Library and did a search for -

    and got more than 30 hits

    the MSDN page for the STM_SETIMAGE in Win32 API is -

    and it specifically lists the   SS_BITMAP  STATIC control style

    anyway I meant that you read the whole section about Static controls, at -

    you might read the overviews and stuff about messages and the others

    the Win32 Help Files that came with delphi, may also be used, reading the stuff about controls like , , index

    Button Controls

    Static Controls

    Scroll Bars



    . . . . . . . . . .

    can give you very helpful info for API

    Author Comment

    Yep, the problem was with no handle being returned - seems if i add in a # in front of the resource number it works.

    What i did a search on was for SendDlgItemMessage on MSDN and got nothing more than what was in the Win32 help.

    Again, thanks very much for the help and sorry to be such a pain in the a** :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
    Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video discusses moving either the default database or any database to a new volume.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now