/
sxfour
/
cpp_winapi_all_projects
Обзор
Документация
Войти
/
sxfour
/
cpp_winapi_all_projects
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
WinAPI_Basic_templates/WinApiSampleTabControl/main.cpp
76 строк
3 KB
Egor Levashov
Add files via upload
26 апр 2024, 18:00
Не верифицирован
26 апр 2024, 18:00
cc5c3d8
Код
Авторство
О чём код?
#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #include <string> #include <vector> #include <Windows.h> #include <CommCtrl.h> using namespace std; using namespace std::literals; struct TabPage { HWND panel; TCITEM tabControlItem; wstring text; }; HWND window = nullptr; HWND tabControl1 = nullptr; vector<TabPage> tabPages(3); WNDPROC defWndProc = nullptr; LRESULT OnWindowClose(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PostQuitMessage(0); return CallWindowProc(defWndProc, hWnd, message, wParam, lParam); } LRESULT OnWindowNotify(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { for (size_t index = 0; index < tabPages.size(); index++) { ShowWindow(tabPages[index].panel, index == SendMessage(tabControl1, TCM_GETCURSEL, 0, 0) ? SW_SHOW : SW_HIDE); } return CallWindowProc(defWndProc, hWnd, message, wParam, lParam); } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_CLOSE && hWnd == window) { return OnWindowClose(hWnd, message, wParam, lParam); } if (message == WM_NOTIFY && hWnd == window) { return OnWindowNotify(hWnd, message, wParam, lParam); } return CallWindowProc(defWndProc, hWnd, message, wParam, lParam); } int main() { window = CreateWindowEx(0, WC_DIALOG, L"TabControl example", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 406, 316, nullptr, nullptr, nullptr, nullptr); tabControl1 = CreateWindowEx(0, WC_TABCONTROL, nullptr, WS_CHILD | WS_VISIBLE, 10, 10, 370, 250, window, nullptr, nullptr, nullptr); for (size_t index = 0; index < tabPages.size(); index++) { tabPages[index].text = L"tabPages"s + to_wstring(index + 1); tabPages[index].tabControlItem.mask = TCIF_TEXT; tabPages[index].tabControlItem.pszText = const_cast<LPWSTR>(tabPages[index].text.c_str()); TabCtrl_InsertItem(tabControl1, TabCtrl_GetItemCount(tabControl1), &tabPages[index].tabControlItem); RECT tabPageRectangle{ 0, 0, 370, 250 }; SendMessage(tabControl1, TCM_ADJUSTRECT, false, reinterpret_cast<LPARAM>(&tabPageRectangle)); tabPages[index].panel = CreateWindowEx(0, WC_DIALOG, nullptr, WS_CHILD | WS_CLIPSIBLINGS, tabPageRectangle.left, tabPageRectangle.top, tabPageRectangle.right - tabPageRectangle.left, tabPageRectangle.bottom - tabPageRectangle.top, tabControl1, nullptr, nullptr, nullptr); } defWndProc = reinterpret_cast<WNDPROC>(SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(WndProc))); ShowWindow(tabPages[0].panel, SW_SHOW); ShowWindow(window, SW_SHOW); MSG message = { 0 }; while (GetMessage(&message, nullptr, 0, 0)) { DispatchMessage(&message); } return 0; }