To znaczy tylko że jesteś leniem albo w ogóle nie ogarniasz WinAPI (choć ten przykład da się rady przerobić nawet bez jego znajomości).
Wystarczy tylko trochę pomyśleć - od myślenia głowa nie boli.
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define UNICODE
#include <Windows.h>
#include <Commctrl.h>
#define IDC_EXIT_BUTTON 101
#define IDC_PUSHLIKE_BUTTON 102
HBRUSH CreateColorBrush( COLORREF color, LPNMCUSTOMDRAW item )
{
HBRUSH Brush = NULL;
RECT temp;
HDC hdcmem = CreateCompatibleDC( item->hdc );
HBITMAP hbitmap = CreateCompatibleBitmap( item->hdc, item->rc.right - item->rc.left, item->rc.bottom - item->rc.top );
SelectObject( hdcmem, hbitmap );
int r = GetRValue( color ), g = GetGValue( color ), b = GetBValue( color );
Brush = CreateSolidBrush( RGB( r, g, b ) );
temp.left = 0;
temp.top = 0;
temp.right = item->rc.right - item->rc.left;
temp.bottom = item->rc.bottom - item->rc.top;
FillRect( hdcmem, & temp, Brush );
DeleteObject( Brush );
HBRUSH pattern = CreatePatternBrush( hbitmap );
DeleteDC( hdcmem );
DeleteObject( Brush );
DeleteObject( hbitmap );
return pattern;
}
LRESULT CALLBACK MainWindow( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
static HBRUSH defaultbrush = NULL;
static HBRUSH hotbrush = NULL;
static HBRUSH selectbrush = NULL;
static HBRUSH push_uncheckedbrush = NULL;
static HBRUSH push_checkedbrush = NULL;
static HBRUSH push_hotbrush1 = NULL;
static HBRUSH push_hotbrush2 = NULL;
switch( msg )
{
case WM_CREATE:
{
HWND Exit_Button = CreateWindowEx( NULL, L"BUTTON", L"EXIT",
WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
50, 50, 100, 100, hwnd,( HMENU ) IDC_EXIT_BUTTON, NULL, NULL );
if( Exit_Button == NULL )
{
MessageBox( NULL, L"Button Creation Failed!", L"Error!", MB_ICONEXCLAMATION );
exit( EXIT_FAILURE );
}
HWND Pushlike_Button = CreateWindowEx( NULL, L"BUTTON", L"PUSH ME!",
WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | BS_PUSHLIKE,
200, 50, 100, 100, hwnd,( HMENU ) IDC_PUSHLIKE_BUTTON, NULL, NULL );
if( Pushlike_Button == NULL )
{
MessageBox( NULL, L"Button Creation Failed!", L"Error!", MB_ICONEXCLAMATION );
exit( EXIT_FAILURE );
}
}
break;
case WM_COMMAND:
{
switch( LOWORD( wParam ) )
{
case IDC_EXIT_BUTTON:
{
SendMessage( hwnd, WM_CLOSE, 0, 0 );
}
break;
}
}
break;
case WM_NOTIFY:
{
LPNMHDR some_item =( LPNMHDR ) lParam;
if( some_item->idFrom == IDC_EXIT_BUTTON && some_item->code == NM_CUSTOMDRAW )
{
LPNMCUSTOMDRAW item =( LPNMCUSTOMDRAW ) some_item;
if( item->uItemState & CDIS_SELECTED )
{
if( selectbrush == NULL )
selectbrush = CreateColorBrush( RGB( 180, 0, 0 ), item );
HPEN pen = CreatePen( PS_INSIDEFRAME, 0, RGB( 0, 0, 0 ) );
HGDIOBJ old_pen = SelectObject( item->hdc, pen );
HGDIOBJ old_brush = SelectObject( item->hdc, selectbrush );
RoundRect( item->hdc, item->rc.left, item->rc.top, item->rc.right, item->rc.bottom, 5, 5 );
SelectObject( item->hdc, old_pen );
SelectObject( item->hdc, old_brush );
DeleteObject( pen );
return CDRF_DODEFAULT;
}
else
{
if( item->uItemState & CDIS_HOT )
{
if( hotbrush == NULL )
hotbrush = CreateColorBrush( RGB( 255, 230, 0 ), item );
HPEN pen = CreatePen( PS_INSIDEFRAME, 0, RGB( 0, 0, 0 ) );
HGDIOBJ old_pen = SelectObject( item->hdc, pen );
HGDIOBJ old_brush = SelectObject( item->hdc, hotbrush );
RoundRect( item->hdc, item->rc.left, item->rc.top, item->rc.right, item->rc.bottom, 5, 5 );
SelectObject( item->hdc, old_pen );
SelectObject( item->hdc, old_brush );
DeleteObject( pen );
return CDRF_DODEFAULT;
}
if( defaultbrush == NULL )
defaultbrush = CreateColorBrush( RGB( 255, 180, 0 ), item );
HPEN pen = CreatePen( PS_INSIDEFRAME, 0, RGB( 0, 0, 0 ) );
HGDIOBJ old_pen = SelectObject( item->hdc, pen );
HGDIOBJ old_brush = SelectObject( item->hdc, defaultbrush );
RoundRect( item->hdc, item->rc.left, item->rc.top, item->rc.right, item->rc.bottom, 5, 5 );
SelectObject( item->hdc, old_pen );
SelectObject( item->hdc, old_brush );
DeleteObject( pen );
return CDRF_DODEFAULT;
}
}
else if( some_item->idFrom == IDC_PUSHLIKE_BUTTON && some_item->code == NM_CUSTOMDRAW )
{
LPNMCUSTOMDRAW item =( LPNMCUSTOMDRAW ) some_item;
if( IsDlgButtonChecked( hwnd, some_item->idFrom ) )
{
if( item->uItemState & CDIS_HOT )
{
if( push_hotbrush1 == NULL )
push_hotbrush1 = CreateColorBrush( RGB( 0, 0, 245 ), item );
HPEN pen = CreatePen( PS_INSIDEFRAME, 0, RGB( 0, 0, 0 ) );
HGDIOBJ old_pen = SelectObject( item->hdc, pen );
HGDIOBJ old_brush = SelectObject( item->hdc, push_hotbrush1 );
RoundRect( item->hdc, item->rc.left, item->rc.top, item->rc.right, item->rc.bottom, 10, 10 );
SelectObject( item->hdc, old_pen );
SelectObject( item->hdc, old_brush );
DeleteObject( pen );
return CDRF_DODEFAULT;
}
if( push_checkedbrush == NULL )
push_checkedbrush = CreateColorBrush( RGB( 0, 0, 180 ), item );
HPEN pen = CreatePen( PS_INSIDEFRAME, 0, RGB( 0, 0, 0 ) );
HGDIOBJ old_pen = SelectObject( item->hdc, pen );
HGDIOBJ old_brush = SelectObject( item->hdc, push_checkedbrush );
RoundRect( item->hdc, item->rc.left, item->rc.top, item->rc.right, item->rc.bottom, 10, 10 );
SelectObject( item->hdc, old_pen );
SelectObject( item->hdc, old_brush );
DeleteObject( pen );
return CDRF_DODEFAULT;
}
else
{
if( item->uItemState & CDIS_HOT )
{
if( push_hotbrush2 == NULL )
push_hotbrush2 = CreateColorBrush( RGB( 255, 230, 0 ), item );
HPEN pen = CreatePen( PS_INSIDEFRAME, 0, RGB( 0, 0, 0 ) );
HGDIOBJ old_pen = SelectObject( item->hdc, pen );
HGDIOBJ old_brush = SelectObject( item->hdc, push_hotbrush2 );
RoundRect( item->hdc, item->rc.left, item->rc.top, item->rc.right, item->rc.bottom, 10, 10 );
SelectObject( item->hdc, old_pen );
SelectObject( item->hdc, old_brush );
DeleteObject( pen );
return CDRF_DODEFAULT;
}
if( push_uncheckedbrush == NULL )
push_uncheckedbrush = CreateColorBrush( RGB( 255, 180, 0 ), item );
HPEN pen = CreatePen( PS_INSIDEFRAME, 0, RGB( 0, 0, 0 ) );
HGDIOBJ old_pen = SelectObject( item->hdc, pen );
HGDIOBJ old_brush = SelectObject( item->hdc, defaultbrush );
RoundRect( item->hdc, item->rc.left, item->rc.top, item->rc.right, item->rc.bottom, 10, 10 );
SelectObject( item->hdc, old_pen );
SelectObject( item->hdc, old_brush );
DeleteObject( pen );
return CDRF_DODEFAULT;
}
}
return CDRF_DODEFAULT;
}
break;
case WM_CTLCOLORBTN:
{
return( LRESULT ) GetSysColorBrush( COLOR_WINDOW + 1 );
}
break;
case WM_CLOSE:
{
DestroyWindow( hwnd );
return 0;
}
break;
case WM_DESTROY:
{
DeleteObject( defaultbrush );
DeleteObject( selectbrush );
DeleteObject( hotbrush );
DeleteObject( push_checkedbrush );
DeleteObject( push_hotbrush1 );
DeleteObject( push_hotbrush2 );
DeleteObject( push_uncheckedbrush );
PostQuitMessage( 0 );
return 0;
}
break;
default:
return DefWindowProc( hwnd, msg, wParam, lParam );
}
return 0;
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
const wchar_t ClassName[] = L"Main_Window";
wc.cbSize = sizeof( WNDCLASSEX );
wc.style = 0;
wc.lpfnWndProc = MainWindow;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = GetSysColorBrush( COLOR_WINDOW + 1 );
wc.lpszMenuName = NULL;
wc.lpszClassName = ClassName;
wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
if( !RegisterClassEx( & wc ) )
{
MessageBox( NULL, L"Window Registration Failed!", L"Error", MB_ICONEXCLAMATION | MB_OK );
exit( EXIT_FAILURE );
}
hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, ClassName, L"Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 368, 248, NULL, NULL, hInstance, NULL );
if( hwnd == NULL )
{
MessageBox( NULL, L"Window Creation Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK );
exit( EXIT_FAILURE );
}
ShowWindow( hwnd, nCmdShow );
UpdateWindow( hwnd );
while( GetMessage( & msg, NULL, 0, 0 ) > 0 )
{
TranslateMessage( & msg );
DispatchMessage( & msg );
}
return msg.message;
}