CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [win32] - how add a persistence image to control?

    i have these code for add a persistence image to a control:
    Code:
    void setImage(string FileName)
        {
            //handle the image
            HBITMAP hImage =(HBITMAP)LoadImage(NULL,FileName.c_str(),IMAGE_BITMAP,20,20,LR_LOADFROMFILE);
            //add it to control
            SendMessage(this->hwnd,
                STM_SETIMAGE,//it's the sendmessage 'command'
                (WPARAM)IMAGE_BITMAP,//type\format of image
                reinterpret_cast<LPARAM>(hImage));//the HBITMAP image
        }
    (for the image be showed the control must have SS_BITMAP style... if you want another format, don't forget change the style and in SendMessage() function)
    but i see 2 problems:
    1 - the image is stretch to control... why?
    2 - why the text isn't showed?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: [win32] - how add a persistence image to control?

    Quote Originally Posted by Cambalinho View Post
    but i see 2 problems:
    1 - the image is stretch to control... why?
    2 - why the text isn't showed?
    1. Which styles did you set for this picture/static control?
    2. Read the documentation about picture/static control in MSDN!
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: [win32] - how add a persistence image to control?

    1) because that's how the SS_BITMAP style works.
    2) a static control can EITHER show a tekst, a bitmap or an icon it can't do 2 or more at the same time. (i.e. one style overrides the other).


    If you don't like 1 and/or 2, you'll need to custom draw the image rather than using the build in style/feature.

  4. #4
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - how add a persistence image to control?

    if i use the SS_CENTERIMAGE style the image use the original size(is what i have tested).

    OReubens: if i understand you, the STATIC or show text or an image, right?

    for custom draw i must use the SS_OWNERDRAW style, or just the WM_PAINT it's what i need?

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: [win32] - how add a persistence image to control?

    Quote Originally Posted by Cambalinho View Post
    if i use the SS_CENTERIMAGE style the image use the original size(is what i have tested).
    It is good that you "have tested". And it is bad that you still avoid to read the documentation!
    From MSDN article Static Control Styles:
    SS_BITMAP
    A bitmap is to be displayed in the static control. The text is the name of a bitmap (not a filename) defined elsewhere in the resource file. The style ignores the nWidth and nHeight parameters; the control automatically sizes itself to accommodate the bitmap.
    SS_REALSIZECONTROL
    Adjusts the bitmap to fit the size of the static control. For example, changing the locale can change the system font, and thus controls might be resized. If a static control had a bitmap, the bitmap would no longer fit the control. This style bit dictates automatic redimensioning of bitmaps to fit their controls.
    If SS_CENTERIMAGE is specified, the bitmap or icon is centered (and clipped if needed). If SS_CENTERIMAGE is not specified, the bitmap or icon is stretched or shrunk.
    Note that the redimensioning in the two axes are independent, and the result may have a changed aspect ratio.
    Compare with SS_REALSIZEIMAGE.
    SS_REALSIZEIMAGE
    Specifies that the actual resource width is used and the icon is loaded using LoadImage. SS_REALSIZEIMAGE is always used in conjunction with SS_ICON.
    SS_REALSIZEIMAGE uses LoadImage, overriding the process normally followed under SS_ICON. It does not load cursors; if LoadImage fails, no further attempts to load are made. It uses the actual resource width. The static control is resized accordingly, but the icon remains aligned to the originally specified left and top edges of the control.
    Note that if SS_CENTERIMAGE is also specified, the icon is centered within the control's space, which was specified using the CreateWindow parameters nWidth and nHeight.
    Compare with SS_REALSIZECONTROL
    Last edited by VictorN; January 16th, 2014 at 03:54 PM.
    Victor Nijegorodov

  6. #6
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - how add a persistence image to control?

    sorry can you explain better these: "The text is the name of a bitmap (not a filename) defined elsewhere in the resource file."?

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: [win32] - how add a persistence image to control?

    Every resource in .rc file has either a symbolic name (like "some_bitmap_111") or an ID (like IDB_BITMAP_111)
    Victor Nijegorodov

  8. #8
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - how add a persistence image to control?

    Quote Originally Posted by VictorN View Post
    Every resource in .rc file has either a symbolic name (like "some_bitmap_111") or an ID (like IDB_BITMAP_111)
    i'm sorry, lets go back please. i know add a resource file, but how can i do what you mean?
    (sorry, but until now don't make sence to me )

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: [win32] - how add a persistence image to control?

    Quote Originally Posted by Cambalinho View Post
    Quote Originally Posted by VictorN View Post
    Every resource in .rc file has either a symbolic name (like "some_bitmap_111") or an ID (like IDB_BITMAP_111)
    i'm sorry, lets go back please. i know add a resource file, but how can i do what you mean?
    (sorry, but until now don't make sence to me )
    It was just an answer to your question:
    Quote Originally Posted by Cambalinho View Post
    sorry can you explain better these: "The text is the name of a bitmap (not a filename) defined elsewhere in the resource file."?
    Victor Nijegorodov

  10. #10
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - how add a persistence image to control?

    Quote Originally Posted by VictorN View Post
    It was just an answer to your question:
    can you give me a pratice example, please?(something simple... i know add the resource file to my project)
    can you just show me 2 lines of code show me what to do, please?

  11. #11
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: [win32] - how add a persistence image to control?

    Quote Originally Posted by Cambalinho View Post
    i'm sorry, lets go back please. i know add a resource file, but how can i do what you mean?
    (sorry, but until now don't make sence to me )
    1. Pay attention to LoadImage dcumentation;
    2. focus on lpszName parameter;
    3. discover what MAKEINTRESOURCE macro does;
    4. do not ignore the rest;
    5. repeat 1 to 4 until everything is clear.
    Last edited by ovidiucucu; January 20th, 2014 at 04:35 PM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured