Sunday, July 27, 2008

Image Loaded Button in VC++(Win32)

We can load images on buttons in VC++ by using
below code code snippet.


m_hBitmap = (HBITMAP)::LoadBitmap( g_hModule, MAKEINTRESOURCE(
IDB_BITMAP_BACKX ));
if( m_hBitmap ){
HWND h = Item( IDC_BU_XP ).handle;
LONG dw = ::GetWindowLong( h, GWL_STYLE );
::SetWindowLong( h, GWL_STYLE, ( dw & ~SS_ENHMETAFILE ) | BS_BITMAP | BS_CENTER );
::SendMessage( Item( IDC_BU_XP), BM_SETIMAGE,
(WPARAM)IMAGE_BITMAP, (LPARAM)m_hBitmap );
}

Here IDB_BITMAP_BACKX :- control id of bitmap control.
IDC_BU_XP :-control id of Button Control.
Also m_hBitmap is the object of HBITMAP.