#include "$/inc/minwin.inc"
'#include "$/inc/console.inc"
cr=chr(13,10)
' Some constants and functions
% COLOR_3DFACE = 15
% ICC_TAB_CLASSES = 8
% TCIF_TEXT = 1
% TCM_GETITEMCOUNT = 4868
% TCM_GETCURSEL = 4875
% TCM_INSERTITEM = 4871
% TCM_DELETEITEM = 4872
% TCM_DELETEALLITEMS = 4873
type TCITEM
int mask,dwState,dwStateMask
char* pszText
int cchTextMax,iImage
sys lParam
end type
! GetSysColorBrush lib "user32.dll" (int nIndex) as sys
! GetWindowText alias"GetWindowTextA" lib "user32.dll" (sys hWnd, char *lpString, int nMaxCount) as int
function CreateWindow(string lpClassName, lpWindowName,int dwStyle, x, y, nWidth, nHeight,sys hWndParent, hMenu, hInstance, lpParam) as sys
return CreateWindowEx(0, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
end function
'===========
'MAIN CODE
'===========
dim cmdline as asciiz ptr, hInst as sys
&cmdline=GetCommandLine
hInst=GetModuleHandle(0)
'--------------------------------------------
#define ID_TABCTRL 1
#define ID_EDIT 2
#define BTN_ADD 3
#define BTN_DEL 4
#define BTN_CLR 5
sys hTab, hEdit;
string classname="Tab control"
function WinMain(sys hInst, sys hPrev, asciiz *cmdLine, int cmdShow)
{
MSG msg ;
WNDCLASS wc = {0};
wc.lpszClassName = strptr classname
wc.hInstance = hInst;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = @WndProc;
wc.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClass(&wc);
CreateWindowEx(0, classname, "Tab control",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
100, 100, 380, 230,
0, 0, hInst, 0);
while( GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
function WndProc (sys hWnd, uint Msg, sys wParam, sys lParam) as sys callback
{
TCITEM tie;
zstring text[250];
sys id
int count;
INITCOMMONCONTROLSEXt icex;
switch(msg) {
case WM_CREATE:
icex.dwSize = sizeof(INITCOMMONCONTROLSEXt);
icex.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icex);
hTab = CreateWindow("SysTabControl32", NULL, WS_CHILD | WS_VISIBLE,
0, 0, 200, 150, hwnd, ID_TABCTRL, hInst, NULL);
hEdit = CreateWindow("Edit", "One", WS_CHILD | WS_VISIBLE | WS_BORDER,
250, 20, 100, 25, hwnd, ID_EDIT, hInst, NULL);
CreateWindow("Button", "Add", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
250, 50, 100, 25, hwnd, BTN_ADD, hInst, NULL);
CreateWindow("Button", "Delete", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
250, 80, 100, 25, hwnd, BTN_DEL, hInst, NULL);
CreateWindow("Button", "Clear", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
250, 110, 100, 25, hwnd, BTN_CLR, hInst, NULL);
break;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case BTN_ADD:
GetWindowText(hEdit, text, 250);
if (len(text) != 0 ) {
tie.mask = TCIF_TEXT;
tie.pszText = text;
count = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
SendMessage(hTab, TCM_INSERTITEM, count, &tie);
}
break;
case BTN_DEL:
id = SendMessage(hTab, TCM_GETCURSEL, 0, 0);
if (id != -1) {
SendMessage(hTab, TCM_DELETEITEM, 0, id);
}
break;
case BTN_CLR:
SendMessage(hTab, TCM_DELETEALLITEMS, 0, 0);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return(DefWindowProc(hwnd, msg, wParam, lParam));
}
WinMain(hInst, 0, cmdline, SW_NORMAL )