Custom controls for windows (custom buttons, radio buttons and check boxes) without using MFC’s
DOWNLOAD SAMPLE PROJECT CODE - 5MB
The above sample project demo contains three following three functions
- LRESULT DrawButton(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, TCHAR szContent[], int idc, IMGLIST imglist, HWND ParentWnd)
Draw Button:
This function draws a custom button based on the images provided to it. Its behavior is same as that of default as it also sends message WM_COMMAND (with wParam containing the Control ID).
Usage:
LRESULT DrawButton(HWND hWnd,//window handle(one which is sent by WndProc)
UINT message,//message one which is sent by WndProc
WPARAM wParam, LPARAM lParam,//same
TCHAR szContent[],//title of the button
int idc,//control ID
IMGLIST imglist,//list of images (clicked,hover,normal)
HWND ParentWnd)//HWND of the parent window
Draw Radio button and Draw check box:
These will create custom radio button and check boxes based on the images you provide to it.You also need to send a BOOL state variable to these functions which monitor the check state of the controls
Example:
First create the window which you want to act like a control
MyRegisterClass(hInst,BtnWndProc,L"btn");
buttonHwnd=CreateWindow(L"btn",L"btn",WS_VISIBLE | WS_CHILD ,50,90,BTN_WIDTH,BTN_HEIGHT,hWnd,(HMENU)IDC_BTN,hInst,NULL);
Than call above custom functions inside the wndproc as shown below
LRESULT CALLBACK BtnWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND ParentWnd = GetParent(hWnd);
IMGLIST imglist;
imglist.hit = IDB_BTN_HIT;
imglist.normal=IDB_BTN_NORMAL;
imglist.hover=IDB_BTN_HOVER;
imglist.disabled = IDB_BTN_NORMAL;
return DrawButton(hWnd, message,wParam,lParam,L"Test", IDC_BTN, imglist,ParentWnd);
}
For more information go through the sample project code