Rebar control example

To create a Rebar control specify REBARCLASSNAME as the window class and register the class by specifying the ICC_COOL_CLASSES bit flag in the accompanying INITCOMMONCONTROLSEX structure.p>


#define _WIN32_WINNT 0x0501 #include <windows.h> #include <commctrl.h> #pragma comment(lib, "comctl32.lib") #define ID_REBAR 1000 #define ID_BUTTON 2000 #define ID_EDIT 2001 HINSTANCE g_hInst; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); HWND CreateRebar(HWND); void MoveRebar(HWND); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) { g_hInst = hInstance; INITCOMMONCONTROLSEX icc; icc.dwSize = sizeof(icc); icc.dwICC = ICC_COOL_CLASSES; InitCommonControlsEx(&icc); WNDCLASS wc = {0}; wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszClassName = TEXT("myWindowClass"); RegisterClass(&wc); CreateWindowEx( WS_EX_CLIENTEDGE, TEXT("myWindowClass"), TEXT("Rebar Demo"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 500, 200, NULL, NULL, hInstance, NULL); MSG msg; while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: CreateRebar(hwnd); return 0; case WM_SIZE: MoveRebar(hwnd); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd,msg,wParam,lParam); } HWND CreateRebar(HWND hwndParent) { HWND hwndRebar; hwndRebar = CreateWindowEx( WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | RBS_VARHEIGHT | RBS_BANDBORDERS | CCS_NODIVIDER | CCS_NOPARENTALIGN, 0, 0, 0, 0, hwndParent, (HMENU)ID_REBAR, g_hInst, NULL); if(hwndRebar==NULL) return NULL; HIMAGELIST himl; himl = ImageList_Create(16,16,ILC_COLOR16|ILC_MASK,1,1); REBARINFO rbi; ZeroMemory(&rbi,sizeof(rbi)); rbi.cbSize = sizeof(rbi); rbi.fMask = RBIM_IMAGELIST; rbi.himl = himl; SendMessage(hwndRebar,RB_SETBARINFO,0,(LPARAM)&rbi); //------------------------------------------------- // Edit band //------------------------------------------------- HWND hEdit = CreateWindow( TEXT("EDIT"), TEXT(""), WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL, 0, 0, 120, 22, hwndRebar, (HMENU)ID_EDIT, g_hInst, NULL); RECT rc; GetWindowRect(hEdit,&rc); REBARBANDINFO rbbi; ZeroMemory(&rbbi,sizeof(rbbi)); rbbi.cbSize = sizeof(rbbi); rbbi.fMask = RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE | RBBIM_ID | RBBIM_TEXT; rbbi.fStyle = RBBS_GRIPPERALWAYS; rbbi.lpText = TEXT("TextBox"); rbbi.cch = lstrlen(rbbi.lpText); rbbi.hwndChild = hEdit; rbbi.cxMinChild = rc.right-rc.left; rbbi.cyMinChild = rc.bottom-rc.top; rbbi.cx = 150; rbbi.wID = ID_EDIT; SendMessage(hwndRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbbi); //------------------------------------------------- // Button band //------------------------------------------------- HWND hButton = CreateWindow( TEXT("BUTTON"), TEXT("Button"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 90, 24, hwndRebar, (HMENU)ID_BUTTON, g_hInst, NULL); GetWindowRect(hButton,&rc); ZeroMemory(&rbbi,sizeof(rbbi)); rbbi.cbSize = sizeof(rbbi); rbbi.fMask = RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_STYLE | RBBIM_ID | RBBIM_TEXT; rbbi.fStyle = RBBS_GRIPPERALWAYS; rbbi.lpText = TEXT("Button"); rbbi.cch = lstrlen(rbbi.lpText); rbbi.hwndChild = hButton; rbbi.cxMinChild = rc.right-rc.left; rbbi.cyMinChild = rc.bottom-rc.top; rbbi.cx = 120; rbbi.wID = ID_BUTTON; SendMessage(hwndRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbbi); MoveRebar(hwndParent); return hwndRebar; } void MoveRebar(HWND hwnd) { RECT rc; GetClientRect(hwnd,&rc); HWND hRebar = GetDlgItem(hwnd,ID_REBAR); MoveWindow( hRebar, 0, 0, rc.right, 40, TRUE); }