Note that there are some explanatory texts on larger screens.

plurals
  1. POToolbar scrolls when I scrolling the window
    text
    copied!<p>I am writing win32 program, and I have a window with a scroll bar, and now I added a toolbar. My problem is, the toolbar is scrolls when I scrolling the window. how do I set the toolbar to stand in his place, such as a menu? </p> <p>This is an example of code that shows how the toolbar scrolls when scrolling the window, the code is not perfect, but it shows how the toolbar scroll when you sroll the window line up, or line down: </p> <pre><code>#include &lt;windows.h&gt; #include &lt;stdlib.h&gt; #include &lt;CommCtrl.h&gt; #pragma comment(lib, "comctl32.lib") 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); 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: { // create toolbar HWND hWndToolbar = CreateWindowEx(0 , TOOLBARCLASSNAME, NULL, WS_CHILD | TBSTYLE_TOOLTIPS, 0, 0, 0, 0, hWnd, (HMENU)0, instance, NULL); HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR16 | ILC_MASK, 3, 0); SendMessage(hWndToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hImageList); SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); TBBUTTON tbb[4] = { {0,0,TBSTATE_ENABLED,TBSTYLE_BUTTON,}, {1,1,TBSTATE_ENABLED,TBSTYLE_BUTTON,}, {2,2,TBSTATE_ENABLED,TBSTYLE_BUTTON,}, {0,0,TBSTATE_ENABLED,BTNS_SEP} }; SendMessage(hWndToolbar, (UINT) TB_ADDBUTTONS, 4, (LPARAM)&amp;tbb); SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0); ShowWindow(hWndToolbar , SW_SHOW); // scrollbar SCROLLINFO si; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_ALL; si.nMax = 1000; si.nMin = 0; si.nPos = 0; si.nPage = 500; SetScrollInfo(hWnd, SBS_VERT, &amp;si, TRUE); } break; case WM_VSCROLL: switch(LOWORD(wParam)) { case SB_LINEDOWN: ScrollWindow(hWnd, 0, -20, NULL, NULL); break; case SB_LINEUP: ScrollWindow(hWnd, 0, 20, NULL, NULL); break; } 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