I've just been learning how to draw UI for a few months. Now I have a problem. We can implement the top tab with owner draw TabControl, but in terms of UI, it's not what I need
What I want is a side tab of the type shown in the following figure [windows 10 settings application]. Click and execute the corresponding message processing
picture↓
查看图片view picture
please do it with WIN32 and no MFC
Does anyone can tell me how to create sidetab like the picture?
thank you.
What I have tried:
I have tired to use ownerdraw button to do it,but it cannot Click to switch the interface,
Want sidetab to use this style for ownerdraw
<pre>HWND g_bt1;
HWND g_bt2;
WNDPROC BToldProc;
typedef struct tagBTN
{ HWND hWnd; BOOL x1; BOOL x2; LPWSTR in;
UINT style;
} BTN_PARAM;
LRESULT CALLBACK BTProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{ PAINTSTRUCT ps;
HDC hdc = NULL;
RECT rc;
GetClientRect(hWnd, &rc);
LOGFONT lf;
HFONT hFont = 0;
HBRUSH br;
TCHAR txt[40];
switch (Msg)
{ case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
br = CreateSolidBrush(RGB(7, 130, 215));
FillRect(hdc, &rc, br);
GetWindowText(hWnd, txt, 40);
SetBkMode(hdc, TRANSPARENT);
if (hFont == 0)
{
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = -16;
wcscpy(lf.lfFaceName, L"黑体");
hFont = CreateFontIndirect(&lf); }
HFONT old = (HFONT)SelectObject(hdc, hFont);
TextOut(hdc, 18, 7, txt, wcslen(txt) );
ReleaseDC(hWnd, hdc);
UpdateWindow(hWnd);
DeleteObject(br);
EndPaint(hWnd, &ps);
break;
}
case WM_MOUSEMOVE:
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_HOVER | TME_LEAVE;
tme.dwHoverTime = 1;
tme.hwndTrack = hWnd;
BOOL boRet = _TrackMouseEvent(&tme);
}break;
case WM_MOUSELEAVE:
{
PAINTSTRUCT ps1;
HBRUSH hbr = NULL;
hdc = GetDC(hWnd);
hbr = CreateSolidBrush(RGB(0,255,191));
SelectObject(hdc, hbr);
FillRect(hdc, &rc, hbr);
ReleaseDC(hWnd, hdc);
DeleteObject(hbr);
OutputDebugStringA("Leave\n");
break;
}
case WM_MOUSEHOVER:
{
HBRUSH hbr = NULL;
hdc = GetDC(hWnd);
hbr = CreateSolidBrush(RGB(99, 184, 255));
SelectObject(hdc, hbr);
FillRect(hdc, &rc, hbr);
GetWindowText(hWnd, txt, 40);
SetBkMode(hdc, TRANSPARENT);
if (hFont == 0)
{
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = -16;
wcscpy(lf.lfFaceName, L"黑体");
hFont = CreateFontIndirect(&lf); }
HFONT old = (HFONT)SelectObject(hdc, hFont);
TextOut(hdc, 18, 7, txt, wcslen(txt) );
ReleaseDC(hWnd, hdc);
DeleteObject(hbr);
OutputDebugStringA("Over\n");
break;
}
}
return CallWindowProc(BToldProc, hWnd, Msg, wParam, lParam);
}
int Button(
HWND hWnd, BOOL x1,
BOOL x2,
LPWSTR in,
UINT style )
{
static HFONT hFont;
BTN_PARAM btn;
btn.hWnd = hWnd;
btn.style = style;
g_bt1 = CreateWindow(L"Button", in, WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, x1, x2, 180, 60, hWnd, (HMENU)style, b_hInstance, NULL);
BToldProc = (WNDPROC)SetWindowLong(g_bt1, GWL_WNDPROC, (LONG)BTProc);
return -1;
}
use
#define test 0xcc1
Button(hwnd,x,y,"TEXT",test);
case test:
{}
to use button
But this is not the normal way
Does anyone can tell me how to create sidetab like the picture?