На главную Наши проекты:
Журнал   ·   Discuz!ML   ·   Wiki   ·   DRKB   ·   Помощь проекту
ПРАВИЛА FAQ Помощь Участники Календарь Избранное RSS
msm.ru
Обратите внимание:
1. Прежде чем начать новую тему или отправить сообщение, убедитесь, что вы не нарушаете правил форума!
2. Обязательно воспользуйтесь поиском. Возможно, Ваш вопрос уже обсуждали. Полезные ссылки приведены ниже.
3. Темы с просьбой выполнить какую-либо работу за автора в этом разделе не обсуждаются.
4. Используйте теги [ code=cpp ] ...текст программы... [ /code ] для выделения текста программы подсветкой.
5. Помните, здесь телепатов нет. Старайтесь формулировать свой вопрос максимально грамотно и чётко: Как правильно задавать вопросы
6. Запрещено отвечать в темы месячной и более давности без веских на то причин.

Полезные ссылки:
user posted image FAQ Сайта (C++) user posted image FAQ Форума user posted image Наши Исходники user posted image Поиск по Разделу user posted image MSDN Library Online (Windows Driver Kit) user posted image Google

Ваше мнение о модераторах: user posted image B.V.
Модераторы: B.V.
  
> Как создать Toolbar на Winapi только с текстом, т.е. без иконки ?
    Прикреплённая картинка
    Прикреплённая картинка
    Добрый день!

    Подскажите, пожалуйста, как сформировать toolbar, в которых на кнопках отображается только текст.

    Тестовая программа (классич. прилож. Windows) прилагается.

    По замыслу CreateButtons2 должна создавать Toolbar с кнопками.
    Сам toolbar создается (серая полоска вверху окна), кнопки с текстом - нет.
    Описание кнопок хранится в массиве ButtonsArray.

    ExpandedWrap disabled
      #pragma once
      #define WIN32_LEAN_AND_MEAN
      #include <windows.h>
      #include <stdlib.h>
      #include <malloc.h>
      #include <memory.h>
      #include <tchar.h>
      // ----------------------------------------
      #include <vector>
      #include <string>
      #include <assert.h>
      #include <winuser.h>
       
      #pragma comment( lib, "comctl32" )
      #include <commctrl.h>
       
      void DebugOutput_c(const char* msg) {
          size_t convertedChars = 0;
          size_t newsize = strlen(msg) + 1;
          wchar_t* result_wstring = new wchar_t[newsize];
          mbstowcs_s(&convertedChars, result_wstring, newsize, msg, _TRUNCATE);
       
          OutputDebugStringW(result_wstring);
          delete[] result_wstring;
      }
       
      void DebugOutput_w(const std::wstring& msg) {
          OutputDebugStringW(msg.c_str());
      }
       
      void DebugOutput_s(const std::string& s) {
          DebugOutput_c(s.c_str());
      }
       
      HINSTANCE g_hInst;                                
      const WCHAR* szMainWindowTitle = L"--- TEST ---";
      const WCHAR* szMainWindowClass = L"WinClass";
      HWND g_hMainWindow = NULL;
       
      LRESULT CALLBACK    WndProc_MainWin(HWND, UINT, WPARAM, LPARAM);
       
      // ---------------------------------
       
      struct ButtonDescription_STRUCT {
          std::wstring Caption;
          int ButtonID;
      };
       
      using ButtonDescriptions_ARRAY = std::vector<ButtonDescription_STRUCT>;
       
      #define ID_BUTTON_1     1
      #define ID_BUTTON_2     2
       
      const ButtonDescriptions_ARRAY ButtonsArray = {
          {L"PLUS", ID_BUTTON_1},
          {L"MINUS", ID_BUTTON_2}
      };
       
      bool CreateButtons2(const ButtonDescriptions_ARRAY& ButtonsArray,
          HINSTANCE hInst, HWND hMainWindow) {
       
          bool ok = true;
       
          HWND hToolbar = CreateWindowW(TOOLBARCLASSNAME, NULL,
                                              TBSTYLE_WRAPABLE | TBSTYLE_LIST | WS_CHILD | WS_VISIBLE,
                                              0, 0, 0, 0,
                                              g_hMainWindow, NULL, hInst, NULL);
          DWORD ErrCode = GetLastError();
          assert(hToolbar != NULL);
       
          WPARAM wParam = 0;
          LPARAM lParam = (LPARAM)TBSTYLE_EX_MIXEDBUTTONS;
          DWORD PrevStyles = SendMessageW(hToolbar, TB_SETEXTENDEDSTYLE, wParam, lParam);
       
          RECT rect;
          for (const ButtonDescription_STRUCT& b : ButtonsArray) {
       
              DebugOutput_w(L"Next = " + b.Caption + L"\n");
       
              const int numButtons = 1;
              TBBUTTON tb{ 0 };
              tb.iBitmap = I_IMAGENONE; // 0;
              tb.idCommand = b.ButtonID;
              tb.iString = (INT_PTR) b.Caption.c_str();
              tb.fsState = TBSTATE_ENABLED;
              tb.fsStyle = BTNS_BUTTON | BTNS_SHOWTEXT;
       
              wParam = 1;
              lParam = (LPARAM)&tb;
              int iNew = SendMessageW(hToolbar, TB_ADDBUTTONSW, wParam, lParam);
              assert(iNew >= 0);
       
              DebugOutput_s("iNew = " + std::to_string(iNew) + "\n");
       
          }
       
          ShowWindow(hToolbar, SW_SHOW);
       
          return ok;
      }
       
      ATOM RegisterClass_MainWin() {
          WNDCLASSEXW wcex;
       
          ZeroMemory(&wcex, sizeof(wcex));
       
          wcex.cbSize = sizeof(WNDCLASSEX);
       
          wcex.style = CS_HREDRAW | CS_VREDRAW;
          wcex.lpfnWndProc = WndProc_MainWin;
          wcex.cbClsExtra = 0;
          wcex.cbWndExtra = 0;
          wcex.hInstance = g_hInst;
          
          wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
          wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
          
          wcex.lpszClassName = szMainWindowClass;
       
          return RegisterClassExW(&wcex);
      }
       
       
       
      BOOL InitInstance(HINSTANCE hInstance) {
          g_hInst = hInstance;
       
          g_hMainWindow = CreateWindowW(szMainWindowClass, szMainWindowTitle, WS_OVERLAPPEDWINDOW,
              CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
       
          if (!g_hMainWindow) {
              return FALSE;
          }
       
          return TRUE;
      }
       
      void ShowAndUpdateWin(HWND hWnd, int nCmdShow) {
       
          ShowWindow(hWnd, nCmdShow);
          UpdateWindow(hWnd);
       
      }
       
       
      int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
          _In_opt_ HINSTANCE hPrevInstance,
          _In_ LPWSTR    lpCmdLine,
          _In_ int       nCmdShow)
      {
          UNREFERENCED_PARAMETER(hPrevInstance);
          UNREFERENCED_PARAMETER(lpCmdLine);
       
          INITCOMMONCONTROLSEX icex;
          icex.dwSize = sizeof(icex);
          icex.dwICC = ICC_BAR_CLASSES;
          BOOL res_init = InitCommonControlsEx(&icex);
          assert(res_init == TRUE);
       
          RegisterClass_MainWin();
       
          if (!InitInstance(g_hInst)) {
              return FALSE;
          }
       
          CreateButtons2(ButtonsArray, g_hInst, g_hMainWindow);
       
          ShowAndUpdateWin(g_hMainWindow, SW_NORMAL);
       
          MSG msg;
       
          while (GetMessage(&msg, nullptr, 0, 0))
          {
              TranslateMessage(&msg);
              DispatchMessage(&msg);
          }
       
          return (int)msg.wParam;
      }
       
       
       
       
      LRESULT CALLBACK WndProc_MainWin(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
      {
          switch (message)
          {
          case WM_COMMAND:
          {
              int wmId = LOWORD(wParam);
       
              switch (wmId) {
              default:
                  return DefWindowProc(hWnd, message, wParam, lParam);
              }
          }
          break;
          /*
          case WM_PAINT: {
              PAINTSTRUCT ps;
              HDC hdc = BeginPaint(hWnd, &ps);
              
              EndPaint(hWnd, &ps);
              break;
          }
          */
          case WM_DESTROY:
              PostQuitMessage(0);
              break;
          default:
              return DefWindowProc(hWnd, message, wParam, lParam);
          }
          return 0;
      }
      А документацию прочитать?
      Подсказка: CreateWindowW это макрос который раскрывается в CreateWindowExW
      https://learn.microsoft.com/en-us/windows/w...s/tb-addbuttons

        Ты имеешь в виду это?
        Цитата Remarks
        If the toolbar was created using the CreateWindowEx function, you must send the TB_BUTTONSTRUCTSIZE message to the toolbar before sending TB_ADDBUTTONS
          Да, именно эту ремарку.
          ExpandedWrap disabled
                SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
          Сообщение отредактировано: sharky72 -
            Цитата sharky72 @
            А документацию прочитать?
            Подсказка: CreateWindowW это макрос который раскрывается в CreateWindowExW
            https://learn.microsoft.com/en-us/windows/w...s/tb-addbuttons


            sharky72, спасибо!
            Видимо, на эту часть внимание не обратил.
            С этим сообщением действительно кнопки появились.
            Сообщение отредактировано: Lun2 -
            1 пользователей читают эту тему (1 гостей и 0 скрытых пользователей)
            0 пользователей:


            Рейтинг@Mail.ru
            [ Script execution time: 0,0554 ]   [ 17 queries used ]   [ Generated: 26.02.26, 04:36 GMT ]