Label in TabControl?
-
Wie bekomme ich ein Label in ein TabControl - habs mal so versucht:
HWND WINAPI DoCreateTabControl(HWND hwndParent) { RECT rcClient; HWND hwndTab; TCITEM tie; int i; // Get the dimensions of the parent window's client area, and // create a tab control child window of that size. GetClientRect(hwndParent, &rcClient); InitCommonControls(); hwndTab = CreateWindow( WC_TABCONTROL, L"", WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 0, 0, rcClient.right, rcClient.bottom, hwndParent, NULL, g_hinst, NULL ); if (hwndTab == NULL) return NULL; // Add tabs for each day of the week. tie.mask = TCIF_TEXT | TCIF_IMAGE; tie.iImage = -1; tie.pszText = g_achTemp; for (i = 0; i < 4; i++) { //LoadString(g_hinst, ""IDS_FIRSTDAY + i, // g_achTemp, sizeof(g_achTemp)/sizeof(g_achTemp[0])); if (TabCtrl_InsertItem(hwndTab, i, &tie) == -1) { DestroyWindow(hwndTab); return NULL; } } TC_ITEM ti; ti.mask = TCIF_TEXT | TCIF_PARAM; ti.pszText = L"texto"; ti.lParam = (LPARAM) CreateWindowEx (0, L"STATIC", L"label", WS_VISIBLE | WS_CHILD, 50, 50, 100,100, hwndTab, (HMENU) NULL, (HINSTANCE) GetModuleHandle (NULL), NULL); TabCtrl_InsertItem(hwndTab, 2, &ti); return hwndTab; }Wollte in das 2te Tab Control das Label setzen - funzt aber so nicht - hat jemand vielleicht Beispielprogrammcode rumliegen oder sieht jemand was ich falsch mache?
Hier der ganze Code zum Rumspielen:
#include <windows.h> #include <commctrl.h> // Global variables HINSTANCE g_hinst; // handle to application instance wchar_t g_achTemp[256]; // temporary buffer for strings //HWND g_hwndMain; // main application window //HWND g_hwndTab; // tab control //HWND g_hwndDisplay; // handle to static control in // // tab control's display area LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { switch(msg) { case WM_DESTROY: PostQuitMessage(0); return 0; default: break; } return (DefWindowProc(hwnd, msg, wparam, lparam)); } // DoCreateTabControl - creates a tab control, sized to fit the // specified parent window's client area, and adds some tabs. // Returns the handle to the tab control. // hwndParent - parent window (the application's main window). HWND WINAPI DoCreateTabControl(HWND hwndParent) { RECT rcClient; HWND hwndTab; TCITEM tie; int i; // Get the dimensions of the parent window's client area, and // create a tab control child window of that size. GetClientRect(hwndParent, &rcClient); InitCommonControls(); hwndTab = CreateWindow( WC_TABCONTROL, L"", WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 0, 0, rcClient.right, rcClient.bottom, hwndParent, NULL, g_hinst, NULL ); if (hwndTab == NULL) return NULL; // Add tabs for each day of the week. tie.mask = TCIF_TEXT | TCIF_IMAGE; tie.iImage = -1; tie.pszText = g_achTemp; for (i = 0; i < 4; i++) { //LoadString(g_hinst, ""IDS_FIRSTDAY + i, // g_achTemp, sizeof(g_achTemp)/sizeof(g_achTemp[0])); if (TabCtrl_InsertItem(hwndTab, i, &tie) == -1) { DestroyWindow(hwndTab); return NULL; } } TC_ITEM ti; ti.mask = TCIF_TEXT | TCIF_PARAM; ti.pszText = L"texto"; ti.lParam = (LPARAM) CreateWindowEx (0, L"STATIC", L"label", WS_VISIBLE | WS_CHILD, 50, 50, 100,100, hwndTab, (HMENU) NULL, (HINSTANCE) GetModuleHandle (NULL), NULL); TabCtrl_InsertItem(hwndTab, 2, &ti); return hwndTab; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdline, int nCmdShow) { g_hinst = hInstance; WNDCLASSEX winclass; winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC | CS_DBLCLKS; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; // extra class info space winclass.cbWndExtra = 0; // extra window info space winclass.hInstance = hInstance; // assign the application instance winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); winclass.lpszMenuName = NULL; // the name of the menu to attach winclass.lpszClassName = L"WINCLASS1"; // the name of the class itself winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&winclass); HWND hwnd; if((hwnd = CreateWindowEx(NULL, L"WINCLASS1", L"Fenstertitel", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 400, 400, NULL, // handle to parent NULL, // handle to menu hInstance, // instance of this application NULL)) == NULL) return 0; DoCreateTabControl(hwnd); //UpdateWindow(); MSG msg; while(GetMessage(&msg, NULL, 0, 0)) { // translate any accelerator keys TranslateMessage(&msg); // send the message to the window proc DispatchMessage(&msg); } return 0; }
-
Hi,
Nee so geht das nicht :p ... Man erstellt erst das Tab-Control, fügt dann Items
hinzu, setzt dann Dialoge, auf denen man zu guter Letzt die Child-Controls
plaziert.Hier ist n Turorial
.
-
ich will keine Resourcen verwenden - nur reines WinAPI
-
Vertexwahn schrieb:
ich will keine Resourcen verwenden - nur reines WinAPI
Wo ist das Problem ?
-
ok aus der Resource was aus reinem WinAPI zu machen ist kein Problem, aber:
if((nCurSel >= 0) && (nCurSel <= 1)) ShowWindow(phDlg[nCurSel], SW_HIDE);wtf? das ist doch nicht ernst gemeint - oder
- ich soll alle Controls verstecken und nur die Anzeigen die auf dem jeweiligen Tab sichtbar sein sollen - das kanns doch nicht sein - hat dieses Tab Control nicht selber eigene Verwaltungfunktionen für sowas?
-
Nop, ist eben WinAPI...
Du kannst sie auch alle platt machen (DestroyWindow) um Speicher zu sparen und später wieder erstellen...aber um diesen Mechanismus kommste mit reiner WinAPI nit herum :p .