-
January 15th, 2014, 04:51 PM
#1
[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?
-
January 16th, 2014, 08:57 AM
#2
Re: [win32] - how add a persistence image to control?
Originally Posted by Cambalinho
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
-
January 16th, 2014, 09:30 AM
#3
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.
-
January 16th, 2014, 02:51 PM
#4
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?
-
January 16th, 2014, 03:25 PM
#5
Re: [win32] - how add a persistence image to control?
Originally Posted by Cambalinho
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
-
January 16th, 2014, 03:29 PM
#6
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."?
-
January 16th, 2014, 05:00 PM
#7
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
-
January 17th, 2014, 03:20 PM
#8
Re: [win32] - how add a persistence image to control?
Originally Posted by VictorN
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 )
-
January 18th, 2014, 04:38 AM
#9
Re: [win32] - how add a persistence image to control?
Originally Posted by Cambalinho
Originally Posted by VictorN
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:
Originally Posted by Cambalinho
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
-
January 18th, 2014, 04:22 PM
#10
Re: [win32] - how add a persistence image to control?
Originally Posted by VictorN
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?
-
January 20th, 2014, 04:32 PM
#11
Re: [win32] - how add a persistence image to control?
Originally Posted by Cambalinho
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 )
- Pay attention to LoadImage dcumentation;
- focus on lpszName parameter;
- discover what MAKEINTRESOURCE macro does;
- do not ignore the rest;
- repeat 1 to 4 until everything is clear.
Last edited by ovidiucucu; January 20th, 2014 at 04:35 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|