Re: loading bitmap from file at runtime
- From: "MrETS" <xxxxxMrETS@xxxxxxxxxxxxx>
- Date: Sat, 30 Apr 2005 10:22:27 -0600
Suggestion:
Try giving the button an owner-drawn style, then, instead of having 4
separate resource bitmaps,
try making one (4x wider horizontally) resource bitmap with the 4 buttons
pasted together horizontally.
When you draw the bitmap onto the button, you can use 5 styles:
[0-3] are extracted from your bitmap resource, and BitBlit'ted with a horiz
offset and width.
Bitmap [4] is painted from a source bitmap you have opened from a file from
disk.
"peones" <peones@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:484B6E01-CA61-4C6C-BD8B-8DE2D0A326FF@xxxxxxxxxxxxxxxx
> I read all the similar posts, but still can't find a solution for me.
> I have a CBitmapButton object which is loaded with 4 default resources.
> The end-user wants the possibility to specify a custom bmp file to be used
> by the button.
> So I can't use the LoadBitmaps function still it asks for a resource name
or
> ID as argument, and as I said I don't have a resource but a file path.
> Notice that button also displays text.
>
> I tried using LoadImage as specified in similar posts, with the following
> code:
>
> CString strFileName;
>
> strFileName = "<bmp-file-path>";
>
> CBitmapButton m_Button;
> HBITMAP hBitmap;
>
> hbitmap = (HBITMAP)
> LoadImage(NULL,strFileName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
>
> if (hBitmap == NULL)
> {
> CString strError;
> FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
> FORMAT_MESSAGE_FROM_SYSTEM |
> FORMAT_MESSAGE_IGNORE_INSERTS,
> NULL,
> GetLastError(),
> MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
> (LPTSTR) &strError,
> 0,
> NULL);
> }
> else
> {
> m_Button.SetBitmap(m_hBitmap);
> m_Button.RedrawWindow(); // added later - try forcing bmp to show
> }
>
> This code gives no error, LoadImage tells "Operation completed
succesfully".
> Anyway the BitmapButton displays nothing.
>
> I know that SetBitmap is a CButton member, so maybe the
> CBitmapButton.LoadBitmaps should be used, but I repeat that this one asks
for
> resources and I just have a bpm file path.
> If someone can explain me how to obtain a resource at runtime starting
from
> a bmp file, than I'll be happy to use LoadBitmaps as well.
>
> Thanks everyone
.
- References:
- loading bitmap from file at runtime
- From: peones
- loading bitmap from file at runtime
- Prev by Date: Re: Printing with Two Viewss
- Next by Date: Re: CDC::StretchBlt() blowing my mind...
- Previous by thread: Re: loading bitmap from file at runtime
- Next by thread: Ctime class and ::localtime thread-safe?
- Index(es):
Relevant Pages
|