Thread: Loading Bitmaps into BS_OWNERDRAW buttons

  1. #1
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80

    Loading Bitmaps into BS_OWNERDRAW buttons

    I have searched through and only found MFC codes. I don't quite understand those but i have tried using primitive lines to draw the button out and it worked so is it possible to use a bitmap ? using BitBlt or other better functions ?
    Oh yea, i plan to draw a rounded rectangle button with the bitmap enclosed in it, is this possible?
    Last edited by rEtard; 05-03-2005 at 02:04 AM.
    /* Have a nice day */

  2. #2
    Registered User jagi's Avatar
    Join Date
    Mar 2005
    Location
    Poland
    Posts
    21
    Yes it's posible...

    Code:
    case WM_DRAWITEM:
    	pdis = (LPDRAWITEMSTRUCT) lParam;
    
    	switch (pdis->CtlID)
    	{
    	case CONTROLID:
    		HBITMAP hBitmap ;
    		hBitmap = LoadBitmap (hInstance, TEXT ("BITMAP")) ;
    		HDC hdcMem = CreateCompatibleDC (pdis->hDC) ;
    		SelectObject (hdcMem, hBitmap) ;
    
    		BITMAP bm ;
    		GetObject (hBitmap, sizeof(BITMAP), &bitmap) ;
    
    		BitBlt (pdis->hDC, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
    	}
    
    	return 0 ;
    [I'm from Poland]
    [Sorry for my English, because I just learn]

  3. #3
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80
    THANZ ! let me try it and i will ask if theres anymor questions
    Last edited by rEtard; 05-03-2005 at 07:42 AM.
    /* Have a nice day */

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Please note that jagi's code, which I'm sure is provided as a proof of concept, is simplified and so doesn't release any gdi resources. If you are to implement his suggestion then you should use DeleteDC on any memory device context(dc) created with CreateCompatibleDC and DeleteObject on the loaded bitmap. For performance reasons it's better to create the dc and load the bitmap once and then delete them when you are done with them, for example when your program terminates, perhaps in a WM_DESTROY handler.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    rEtaRD r HUMANS TOO !!! rEtard's Avatar
    Join Date
    Feb 2005
    Posts
    80
    Thanz Ken, but i decided to draw the rectangle out and insert an icon instead to minimize space. Bitmaps just take up 2 much space, anyway i heard about a bitmap compressor, how does it work and will it affect the quality of the bitmap ?
    KEN or anyone, can you explain this 2 value from LPDRAWITEMSTRUCT->itemstate ODS_SELECTED and ODS_FOCUS, does ODS_SELECTED refer to when i click the mouse or when the mouse is above ? whereas ODS_FOCUS is thru the keyboard ? I dont quite understand, did a lot of search but they didn't state the meaning.
    /* Have a nice day */

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Loading Bitmaps in Allegro
    By LiNeAr in forum Game Programming
    Replies: 1
    Last Post: 08-15-2005, 04:12 PM
  2. Loading bitmaps with createfile() +CreateDIBSection
    By Stevo in forum Windows Programming
    Replies: 7
    Last Post: 05-13-2004, 09:22 PM
  3. Loading bitmaps without win32
    By /Muad'Dib\ in forum C++ Programming
    Replies: 0
    Last Post: 04-05-2004, 02:47 PM
  4. Loading Bitmaps
    By Neandrake in forum Windows Programming
    Replies: 4
    Last Post: 12-17-2001, 01:50 AM
  5. Loading Resource Bitmaps
    By Xterria in forum Windows Programming
    Replies: 10
    Last Post: 11-11-2001, 01:12 PM