Windows, Bitmaps, and morons (me)

This is a discussion on Windows, Bitmaps, and morons (me) within the Windows Programming forums, part of the Platform Specific Boards category; Ok I have a Dialog Box that a need to display a Bitmap in that has to be loaded from ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    8

    Windows, Bitmaps, and morons (me)

    Ok I have a Dialog Box that a need to display a Bitmap in that has to be loaded from a .bmp file. I'm Using MFC....i can loaded the BMP to a Cbitmap....but when i i try to draw it to the dialog i just get a pink (255,0,255) square the size of my image......cant somebody point out to me what im doing wrong or what i need to do? thanks in advance.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,647

    Re: Windows, Bitmaps, and morons (me)

    Originally posted by w384life
    ...cant somebody point out to me what im doing wrong or what i need to do?
    We sure can!
    Give us something to point at...

    gg

  3. #3
    Registered User BillBoeBaggins's Avatar
    Join Date
    Oct 2003
    Posts
    107
    Are you sure you loaded it into the class, did you verify it?
    Did you bitblit your bitmap into a Device Context matching your dialog?
    Did you then bitblit it to your Dialog?
    What API calls are you using?
    (I don't know if these things are inherently done in this CBitmap class)

    Source code... plz...

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    Code:
    void CTexPropDlg::OnPaint() 
    {
    	CClientDC dc(this);
    	CBitmap bmp;
    
    HBITMAP hBmp = (HBITMAP)::LoadImage(
                    NULL,
                    "test.bmp",
                    IMAGE_BITMAP,
                    0,
                    0,
                    LR_LOADFROMFILE|LR_CREATEDIBSECTION
                    );
    
    	bmp.Attach(hBmp);
    	BITMAP bm;
    	bmp.GetObject(sizeof(BITMAP),&bm);
    	CDC dcMem;
    	dcMem.CreateCompatibleDC(&dc);
    	CBitmap *old = dcMem.SelectObject(&bmp);
    	
    	dc.BitBlt(0,0,32,32,&dcMem,0,0,SRCCOPY);
    	dcMem.SelectObject(old);
    
    }
    ignore how ugly its formated plz all that seems to acomplish is drawing a pink square. i tried the same code in the SDI's client area and it shows my bitmap perfectly.......so idunno if its becasue im trying to draw it onto the grey dialog background or what.

    Thanks

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Are you sure hBmp is valid?

    And also, are you really loading this bmp every time you paint?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,647
    Works fine for me...when there's a test.bmp to be found

    Also, you should be using a CPaintDC since you're within OnPaint().

    gg

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    yeah originally it was a CPaintDC i was playing around with differnt ones to see if it made a differance......yes i am loading the bitmap every time i paint simply becasue i want to make it work lol....ill worry aobut efficient after it works. but it works fine you say? casue all im gettign is a pink square....does it have anything to do with the type of bitmap....like 256 color vs 16 bit color? thanks

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    8
    how do u verify the hBmp? if(hBmp) ?

    thanks

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Check the LoadImage docs on the error return value.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21