//rebar control example
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")
int     WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND     CreateRebar(HWND);
void     MoveRebar(HWND);
#define ID_REBAR     1000
#define ID_BUTTON    2000
#define ID_EDIT  2001
HINSTANCE   g_hInst;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// load common control class ICC_COOL_CLASSES from the dynamic-link library (DLL)
INITCOMMONCONTROLSEX iccex;
iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccex.dwICC = ICC_COOL_CLASSES;
InitCommonControlsEx(&iccex);
MSG      msg;
WNDCLASS  wc;
wc.style          = 0;
wc.lpfnWndProc    = (WNDPROC)WndProc;
wc.cbClsExtra     = 0;
wc.cbWndExtra     = 0;
wc.hInstance      = hInstance;
wc.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName   = MAKEINTRESOURCE(104);
wc.lpszClassName  = TEXT("myWindowClass");
RegisterClass(&wc);
CreateWindowEx(WS_EX_CLIENTEDGE,TEXT("myWindowClass"),TEXT("Rebar Demo"), WS_VISIBLE | WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 500,200, NULL, NULL, hInstance, NULL);
while(GetMessage( &msg, NULL, 0, 0) > 0){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
switch (uMessage){
case WM_CREATE:
CreateRebar(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
break;
}
return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
HWND CreateRebar(HWND hwndParent)
{
HWND     hwndRebar = NULL;
LRESULT  lResult;
hwndRebar = CreateWindowEx(WS_EX_TOOLWINDOW, REBARCLASSNAME,
NULL,
WS_VISIBLE | WS_BORDER | WS_CHILD | WS_CLIPCHILDREN |
WS_CLIPSIBLINGS | RBS_VARHEIGHT | RBS_BANDBORDERS |
CCS_NODIVIDER | CCS_NOPARENTALIGN |
0, 0, 0, 200, 100,
hwndParent, (HMENU)ID_REBAR, g_hInst, NULL);
if(hwndRebar){
REBARINFO      rbi;
HIMAGELIST     himlRebar;
HICON          hIcon;
REBARBANDINFO  rbbi;
HWND           hwndChild;
RECT           rc;
//set up the ReBar
himlRebar = ImageList_Create(32, 32, ILC_COLORDDB | ILC_MASK, 1, 0);
hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(101));
ImageList_AddIcon(himlRebar, hIcon);
rbi.cbSize  = sizeof(rbi);
rbi.fMask   = RBIM_IMAGELIST;
rbi.himl    = himlRebar;
lResult = SendMessage(hwndRebar, RB_SETBARINFO, 0, (LPARAM)&rbi);
//add a band that contains a textbox
hwndChild=CreateWindow(TEXT("edit"), NULL,WS_CHILD | WS_VISIBLE | WS_BORDER,20, 60, 100, 30, hwndRebar, (HMENU) ID_EDIT, g_hInst, NULL);//edit control
GetWindowRect(hwndChild, &rc);
ZeroMemory(&rbbi, sizeof(rbbi));
rbbi.cbSize        = sizeof(REBARBANDINFO);
rbbi.fMask        = RBBIM_SIZE | RBBIM_CHILD | RBBIM_CHILDSIZE |
RBBIM_ID | RBBIM_STYLE | RBBIM_TEXT |
RBBIM_BACKGROUND | RBBIM_IMAGE |0;
rbbi.cxMinChild   = rc.right - rc.left;
rbbi.cyMinChild   = rc.bottom - rc.top;
rbbi.cx           = 100;
rbbi.fStyle       = RBBS_CHILDEDGE | RBBS_FIXEDBMP |
RBBS_GRIPPERALWAYS | 0;
rbbi.wID          = ID_EDIT;
rbbi.hwndChild    = hwndChild;
rbbi.lpText       = TEXT("TextBox");
rbbi.cch          = 2;
rbbi.hbmBack      = LoadBitmap(g_hInst, MAKEINTRESOURCE( 102));
rbbi.iImage       = 0;
lResult = SendMessage(hwndRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)(LPREBARBANDINFO)&rbbi);
//add a band that contains a button
hwndChild = CreateWindowEx(0, TEXT("button"), TEXT("Button"),
WS_CHILD | BS_PUSHBUTTON | 0,
0, 0, 100, 50,
hwndRebar, (HMENU)ID_BUTTON, g_hInst, NULL);
GetWindowRect(hwndChild, &rc);
ZeroMemory(&rbbi, sizeof(rbbi));
rbbi.cbSize       = sizeof(REBARBANDINFO);
rbbi.fMask        = RBBIM_SIZE | RBBIM_CHILD | RBBIM_CHILDSIZE |
RBBIM_ID | RBBIM_STYLE | RBBIM_TEXT | RBBIM_BACKGROUND | 0;
rbbi.cxMinChild   = rc.right - rc.left;
rbbi.cyMinChild   = rc.bottom - rc.top;
rbbi.cx           = 100;
rbbi.fStyle       = RBBS_CHILDEDGE | RBBS_FIXEDBMP | RBBS_GRIPPERALWAYS | 0;
rbbi.wID          = ID_BUTTON;
rbbi.hwndChild    = hwndChild;
rbbi.lpText       = TEXT("Button");
rbbi.hbmBack      = LoadBitmap(g_hInst, MAKEINTRESOURCE( 102));
lResult = SendMessage(hwndRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)(LPREBARBANDINFO)&rbbi);
}
MoveRebar(hwndParent);
return hwndRebar;
}
void MoveRebar(HWND hWnd)
{
RECT  rc, rcRebar;
int   x, y, cx, cy;
GetClientRect(hWnd, &rc);
GetWindowRect(GetDlgItem(hWnd, ID_REBAR), &rcRebar);
x = 0;
y = 0;
cx = rc.right - rc.left;
cy = rc.bottom - rc.top;

MoveWindow(GetDlgItem(hWnd, ID_REBAR), x, y, cx, cy, TRUE);

}