Author Topic: TabControl - a bit different  (Read 2171 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
TabControl - a bit different
« on: February 04, 2016, 02:58:34 AM »
sometimes I am indeed impressed by the flexibility of Oxygen's syntax and I am tempted to test these capabilities.

This is a small code snippet from the website of zetcode.com. Adding some constants and some small modifications and voila - a working app. It is really astonishing.

Roland

Code: OxygenBasic
  1. #include "$/inc/minwin.inc"
  2. '#include "$/inc/console.inc"
  3. cr=chr(13,10)
  4.  
  5. ' Some constants and functions
  6.  
  7. % COLOR_3DFACE = 15
  8. % ICC_TAB_CLASSES = 8
  9. % TCIF_TEXT = 1
  10. % TCM_GETITEMCOUNT = 4868
  11. % TCM_GETCURSEL = 4875
  12. % TCM_INSERTITEM = 4871
  13. % TCM_DELETEITEM = 4872
  14. % TCM_DELETEALLITEMS = 4873
  15.  
  16. type TCITEM
  17.   int   mask,dwState,dwStateMask
  18.   char* pszText
  19.   int   cchTextMax,iImage
  20.   sys   lParam
  21. end type
  22.  
  23. ! GetSysColorBrush lib "user32.dll" (int nIndex) as sys
  24. ! GetWindowText alias"GetWindowTextA" lib "user32.dll" (sys hWnd, char *lpString, int nMaxCount) as int
  25.  
  26. function CreateWindow(string lpClassName, lpWindowName,int dwStyle, x, y, nWidth, nHeight,sys hWndParent, hMenu, hInstance, lpParam) as sys
  27.    return CreateWindowEx(0, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
  28. end function
  29.  
  30. '===========
  31.  'MAIN CODE
  32. '===========
  33.  
  34. dim cmdline as asciiz ptr, hInst as sys
  35. &cmdline=GetCommandLine
  36. hInst=GetModuleHandle(0)
  37.  
  38. '--------------------------------------------
  39.  
  40. #define ID_TABCTRL 1
  41. #define ID_EDIT 2
  42. #define BTN_ADD 3
  43. #define BTN_DEL 4
  44. #define BTN_CLR 5
  45.  
  46.  
  47. sys hTab, hEdit;
  48. string classname="Tab control"
  49.  
  50. function WinMain(sys hInst, sys hPrev, asciiz *cmdLine, int cmdShow)
  51. {
  52.   MSG  msg ;    
  53.   WNDCLASS wc = {0};
  54.   wc.lpszClassName = strptr classname
  55.   wc.hInstance     = hInst;
  56.   wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  57.   wc.lpfnWndProc   = @WndProc;
  58.   wc.hCursor       = LoadCursor(0, IDC_ARROW);
  59.  
  60.   RegisterClass(&wc);
  61.  
  62.   CreateWindowEx(0, classname, "Tab control",
  63.                 WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  64.                 100, 100, 380, 230,
  65.                 0, 0, hInst, 0);                
  66.                  
  67.   while( GetMessage(&msg, NULL, 0, 0)) {
  68.     TranslateMessage(&msg);
  69.     DispatchMessage(&msg);
  70.   }
  71.  
  72.   return msg.wParam;
  73. }
  74.  
  75.  
  76. function WndProc (sys hWnd, uint Msg, sys wParam, sys lParam) as sys callback
  77. {
  78.    TCITEM tie;
  79.    zstring text[250];
  80.    sys id
  81.    int count;
  82.    INITCOMMONCONTROLSEXt icex;
  83.  
  84.    switch(msg) {
  85.  
  86.        case WM_CREATE:
  87.  
  88.            icex.dwSize = sizeof(INITCOMMONCONTROLSEXt);
  89.            icex.dwICC = ICC_TAB_CLASSES;
  90.            InitCommonControlsEx(&icex);
  91.  
  92.            hTab = CreateWindow("SysTabControl32", NULL, WS_CHILD | WS_VISIBLE,
  93.                0, 0, 200, 150, hwnd, ID_TABCTRL, hInst, NULL);
  94.  
  95.            hEdit = CreateWindow("Edit", "One", WS_CHILD | WS_VISIBLE | WS_BORDER,
  96.                250, 20, 100, 25, hwnd,  ID_EDIT, hInst, NULL);
  97.  
  98.            CreateWindow("Button", "Add", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  99.                250, 50, 100, 25, hwnd,  BTN_ADD, hInst, NULL);
  100.  
  101.            CreateWindow("Button", "Delete", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  102.                250, 80, 100, 25, hwnd,  BTN_DEL, hInst, NULL);
  103.  
  104.            CreateWindow("Button", "Clear", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  105.                250, 110, 100, 25, hwnd,  BTN_CLR, hInst, NULL);
  106.            break;
  107.  
  108.        case WM_COMMAND:
  109.  
  110.            switch(LOWORD(wParam)) {
  111.  
  112.                case BTN_ADD:
  113.  
  114.                    GetWindowText(hEdit, text, 250);
  115.  
  116.                    if (len(text) != 0 ) {
  117.  
  118.                        tie.mask = TCIF_TEXT;
  119.                        tie.pszText = text;
  120.                        count = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
  121.                        SendMessage(hTab, TCM_INSERTITEM, count, &tie);
  122.                    }
  123.                    break;
  124.  
  125.                case BTN_DEL:
  126.                    id = SendMessage(hTab, TCM_GETCURSEL, 0, 0);
  127.                    if (id != -1) {
  128.                        SendMessage(hTab, TCM_DELETEITEM, 0, id);
  129.                    }
  130.                    break;
  131.  
  132.                case BTN_CLR:
  133.                    SendMessage(hTab, TCM_DELETEALLITEMS, 0, 0);
  134.                    break;
  135.            }
  136.            break;
  137.  
  138.        case WM_DESTROY:
  139.            PostQuitMessage(0);
  140.            break;
  141.    }
  142.  
  143.    return(DefWindowProc(hwnd, msg, wParam, lParam));
  144. }
  145.  
  146. WinMain(hInst, 0, cmdline, SW_NORMAL )
  147.  
  148.  


.
« Last Edit: February 04, 2016, 10:51:38 AM by Arnold »

JRS

  • Guest
Re: TabControl - a bit different
« Reply #1 on: February 04, 2016, 05:27:51 AM »
Great to see the progress being made with porting BCX to O2.

« Last Edit: February 04, 2016, 06:52:42 PM by John »