Code:
#include <windows.h>
#if defined __MINGW_H
#define _WIN32_IE 0x400
#endif // defined
#include <commctrl.h>
#include <stdio.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szWinName[]= "MyWin";
HINSTANCE hInst;
HWND hwnd;
HWND hTabWnd;
int maxX,maxY;
HPEN hOldpen;
HBITMAP hbit;
HBRUSH hbrush, hOldBrush;
HPEN hRedpen;
RECT windowRect;
int WINAPI WinMain (HINSTANCE hThisInst,
HINSTANCE hPrevInstance,
LPSTR lpszArgst,
int nWinMode)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wcl;
INITCOMMONCONTROLSEX cc;
wcl.cbSize = sizeof (WNDCLASSEX);
/* The Window structure */
wcl.hInstance = hThisInst;
wcl.lpszClassName = szWinName;
// wcl.lpfnWndProc = WindowFunc;
wcl.lpfnWndProc = WindowProcedure;
wcl.style = CS_DBLCLKS;
/* Use default icon and mouse-pointer */
wcl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wcl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wcl.hCursor = LoadCursor (NULL, IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
if (!RegisterClassEx (&wcl))
return 0;
hwnd = CreateWindowEx (
0,
szWinName,
"Tab Control Demo",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL
);
cc.dwSize = sizeof(INITCOMMONCONTROLSEX);
cc.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&cc);
hInst=hThisInst;
ShowWindow (hwnd, nWinMode);
UpdateWindow(hwnd);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
NMHDR *nmptr;
int tabnumber;
HDC hdc;
char str[80];
TCITEM tci;
RECT WinDim;
HDC memdc;
switch (message)
{
case WM_CREATE:
maxX=GetSystemMetrics(SM_CXSCREEN);
maxY=GetSystemMetrics(SM_CYSCREEN);
GetClientRect(hwnd,&WinDim);
hRedpen=CreatePen(PS_SOLID,1,RGB(255,0,0));
hTabWnd= CreateWindow(
WC_TABCONTROL,
"",
WS_VISIBLE|WS_TABSTOP|WS_CHILD,0,0,WinDim.right,WinDim.bottom,
hwnd,
NULL,
hInst,
NULL
);
tci.mask=TCIF_TEXT;
tci.iImage=-1;
tci.pszText="One";
TabCtrl_InsertItem(hTabWnd,0,&tci);
tci.pszText="Two";
TabCtrl_InsertItem(hTabWnd,1,&tci);
tci.pszText="Three";
TabCtrl_InsertItem(hTabWnd,2,&tci);
break;
case WM_NOTIFY:
nmptr=(LPNMHDR) lParam;
if(nmptr->code==TCN_SELCHANGE)
{
tabnumber=TabCtrl_GetCurSel((HWND)nmptr->hwndFrom);
hdc=GetDC(hTabWnd);
LineTo(hdc,200,200);
/*
memdc=CreateCompatibleDC(hdc);
hbit=CreateCompatibleBitmap(hdc,maxX,maxY);
SelectObject(memdc, hbit);
hbrush=(HBRUSH)GetStockObject(WHITE_BRUSH);
hOldpen=(HPEN)SelectObject(memdc,hRedpen);
LineTo(memdc,30,200);
PatBlt(memdc,0,0,maxX,maxY,PATCOPY);
InvalidateRect(hwnd,NULL,1);
*/
//sprintf(str,"Changed to Tab %d", tabnumber+1);
//TextOut(hdc,40,100,str,strlen(str));
ReleaseDC(hTabWnd,hdc);
}
break;
case WM_DESTROY:
DeleteObject(hRedpen);
DeleteDC(memdc);
PostQuitMessage (0);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
hdc=BeginPaint(hwnd, &ps);
BitBlt(hdc,0,0,maxX,maxY,memdc,0,0,SRCCOPY);
EndPaint(hwnd,&ps);
break;
}
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
Basically at this point I've only been able to get a line drawn to the tabbed window by directly drawing to it, which is what this code does. If you click on one of the tabs it will draw a line from (0,0) to (200,200).