CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1

    Loading a bitmap in a CStatic

    How would i load a resource bitmap into a CStatic? Thanks.


  2. #2
    Join Date
    May 1999
    Location
    Republic of Korea
    Posts
    74

    Re: Loading a bitmap in a CStatic

    1. Lay a static control to a dialog box.
    2. At property setting, change the Type attribute to "Bitmap".
    3. Assign resource ID to Image attribute.



  3. #3
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Loading a bitmap in a CStatic

    and if I want to do it dynamically?

    Sally


  4. #4
    Join Date
    May 1999
    Location
    Republic of Korea
    Posts
    74

    Re: Loading a bitmap in a CStatic

    You can SetBitmap function of CStatic class.
    You can associate your static control to a member veriable of CStatic class at "Member Variables"
    section of Class Wizard.



  5. #5
    Join Date
    Apr 1999
    Location
    Alabama, USA
    Posts
    261

    Re: Loading a bitmap in a CStatic

    search help for ::LoadImage(). This function does what you want.




  6. #6
    Join Date
    Jun 1999
    Posts
    2

    Re: Loading a bitmap in a CStatic

    I have just tried using your suggestion for a modal dialog box, but get an ASSERTion failure (NULL hWnd) from SetBitmap(). My code is:

    HBITMAP hBitmap = ::GetTrackSymbol( tempBitmap, PPLI_AIR, tempStr );
    d_Filters->m_Page1.m_ppli_air.SetBitmap( hBitmap );

    if(d_Filters->DoModal()==IDOK) {




    This is in the event handler for the menu item to open the dialog. GetTrackSymbol() returns a handle to either the built-in resource or a bitmap in a file in the folder named in tempStr.


  7. #7
    Join Date
    Jun 1999
    Posts
    2

    Re: Loading a bitmap in a CStatic

    what i would like 2 know is how do i change the image in a CStatic (bitmap) as a result of some event in the dialog box (eg: different radio buttons). i have tried everything. somebody help me


  8. #8
    Join Date
    Jun 1999
    Posts
    319

    Re: Loading a bitmap in a CStatic

    Try this on your event procedure :
    [CBitmap bitmap;
    bitmap.LoadBitmap(IDB_YOUR_SPECIAL_BITMAP);
    m_static.SetBitmap((HBITMAP)bitmap);]
    Please let me know if it works

    Regards,
    Fabi


  9. #9
    Join Date
    Jun 1999
    Posts
    2

    Re: Loading a bitmap in a CStatic

    fabi's code really hit the spot. it got the job done PRONTO. excellent advice chum.

    thanx
    irfan


  10. #10
    Join Date
    Jun 1999
    Posts
    2

    Re: Loading a bitmap in a CStatic

    If you want to load the bitmap from a file use:


    hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), iconPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);




    then use SetBitmap(hBitmap)

    The problem I'm having is that I am unable to free the resources when the dialog containing the CStatics are destroyed. Calling DeleteObject()

    also deletes the bitmap of which hBitmap is the handle. This is not what I want as that bitmap is used in the main part of the app.

    Does anyone know how to free resources after a SetBitmap call?


  11. #11

    Re: Loading a bitmap in a CStatic

    I used your code for changing the bitmap in the static control and the static control changes to the new image size, but the control is blank. Help!


  12. #12
    Join Date
    Jun 1999
    Posts
    319

    Re: Loading a bitmap in a CStatic

    Send me your e-mail adress to : [email protected]. I'll sent you a source code.
    P.S. Sorry for my late answer. Diferent country, Diferent time zones.
    Best regards,
    Fabi


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