Re: loading bitmap from file at runtime

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: Display resource in PPC2003
    ... >First I Insert Bitmap resource(IDR_123) in my resource file and use the ... >"HBITMAP hBitmap = LoadBitmap, ... If you know the _full_ path for the DLL, ...
    (microsoft.public.pocketpc.developer)
  • Re: Convert PNG file to Bitmap without a DC?
    ... To load such a resource and get it converted to a bitmap for the ... CBitmap's LoadBitmap method. ... the PNG to a bitmap seems to require a DC compatible with my device. ... HBITMAP CxImage::MakeBitmap ...
    (microsoft.public.vc.mfc)
  • Re: GDI Bitmap Prob.
    ... The "required resource not found" is a message which should be findable in the MFC source ... >the OnDraw() and Draw the data needed. ... >stretching the bitmap ... >> rendered does not declare a CPaintDC, you first render the bitmap and then ...
    (microsoft.public.vc.mfc)
  • Re: customise button appearences
    ... button look with such things a gradient color fills and effects and ... As far as doing something vector-based, it seems to me that you could instead of using a Bitmap, use a Metafile which is essentially a vector-based thing. ... Well, you can include a bitmap as a resource in the application, which you can then use to create a Bitmap instance using the Bitmap.FromResourcemethod. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Add my own bitmaps into a resource file?
    ... I want to use a resource file to load my own bitmaps. ... a new bitmap. ... Then place a {$R <filename>} compiler directive with the resource ...
    (comp.lang.pascal.delphi.misc)