Note that there are some explanatory texts on larger screens.

plurals
  1. POSize of button in a toolbar - win32 program
    text
    copied!<p>I am creating toolbar with my bitmap images, and I have problem with the button size.<br> this image size is 20/20 pixels. </p> <p><img src="https://i.stack.imgur.com/DA5t6.png" alt="enter image description here"></p> <p>and I create a toolbar, and set the button size to 20/20 pixels, by this code: </p> <pre><code>SendMessage(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(20, 20)); </code></pre> <p>and I set the color scheme to red and green, so the button frame will display clearly when the cursor standing over the button. </p> <p>and this what I see when cursor standing over the button: </p> <p><img src="https://i.stack.imgur.com/3X6JE.jpg" alt="enter image description here"></p> <p>As you can see the button size is not 20 \ 20 pixels, but 26 pixels. so why it happened? </p> <p>And one more question, is it possible to cancel the highlighting button when the mouse cursor is over it, and instead I will set hot image list (by <code>TB_SETHOTIMAGELIST</code> message), so when the cursor will stand over the button, the hot image will display, without highlighting the button. </p> <p>and this is the full code: </p> <pre><code>#include &lt;windows.h&gt; #include &lt;stdlib.h&gt; #include &lt;CommCtrl.h&gt; #pragma comment(lib, "comctl32.lib") #define IDB_PRINT 40000 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); HINSTANCE instance; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { instance = hInstance; WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = L"Example"; wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION)); RegisterClassEx(&amp;wcex); HWND hWnd = CreateWindow(L"Example", L"", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, NULL, NULL, hInstance, NULL); // Initialize common controls. INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(INITCOMMONCONTROLSEX); icex.dwICC = ICC_COOL_CLASSES | ICC_BAR_CLASSES; InitCommonControlsEx(&amp;icex); // create toolbar HWND hToolbar = CreateWindowExW(WS_EX_TOOLWINDOW | TBSTYLE_EX_HIDECLIPPEDBUTTONS, TOOLBARCLASSNAME, NULL, CCS_NODIVIDER | WS_CHILD | WS_VISIBLE | CCS_ADJUSTABLE | TBSTYLE_ALTDRAG | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS, 0, 0, 0, 0, hWnd, (HMENU)0, instance, NULL); SendMessage(hToolbar, TB_SETMAXTEXTROWS, 0, 0); // create image list HIMAGELIST hImageList = ImageList_Create(20,20, ILC_COLORDDB, 4, 0); ImageList_Add(hImageList, LoadBitmap(instance, MAKEINTRESOURCEW(IDB_PRINT)), NULL); // set the image list SendMessage(hToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hImageList); SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); // create button TBBUTTON tbb[1] = { {0, 0, TBSTATE_ENABLED, BTNS_AUTOSIZE, {0}, 0, (INT_PTR)L"Print"}, }; // add button to the toolbar SendMessage(hToolbar, (UINT)TB_ADDBUTTONS, 1, (LPARAM)&amp;tbb); SendMessage(hToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(20, 20)); SendMessage(hToolbar, TB_AUTOSIZE, 0, 0); // set color scheme to blue COLORSCHEME cs; cs.dwSize = sizeof(cs); cs.clrBtnShadow = RGB(255, 0, 0); cs.clrBtnHighlight = RGB(0, 255, 0); SendMessage(hToolbar, TB_SETCOLORSCHEME, 0, (LPARAM)&amp;cs); // show the toolbar ShowWindow(hToolbar , SW_SHOW); // show the main window ShowWindow(hWnd, nCmdShow); MSG msg; while (GetMessage(&amp;msg, NULL, 0, 0)) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); } return (int) msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: return 0; default: return DefWindowProc(hWnd, message, wParam, lParam); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload