Skip to content

SysWin Gui

Paul Squires edited this page Oct 31, 2026 · 1 revision

Home › All Categories › sys/win › sys/win/gui

sys/win/gui

Creates windows, dialogs and common controls, with one namespace of helpers per control.

sys/win/gui is the part of sys/win that builds user interfaces. It has two kinds of contents:

  • Classes for windows and the things in them. CWindow creates a main window, adds controls with ready-made styles, scales everything for the display's DPI and runs the message loop; CDialog does the same for dialog boxes; the other classes are controls of their own (a themed button, a masked edit box, a drawing surface), tab pages, printing, the Explorer browser and the open and save dialogs.
  • One namespace per common control, holding functions over that control's messages: ListView.AddColumn( hList, 0, "Name", 200 ) instead of filling an LVCOLUMNW and sending LVM_INSERTCOLUMNW. Namespaces are always written out, also after using gui.

The module also brings the Win32 headers for common controls, the shell, the common dialogs and DWM into the importing file, the RGB_* colour constants, the ANCHOR_* layout constants and the CB* message helpers. It imports sys/win itself; import sys/win as well to call its functions bare.

Importing

#import "sys/win"
#import "sys/win/gui"
using win, gui

Example

A window with a list box filled through the ListBox namespace and a button that reports the selection.

#import "sys/win"
#import "sys/win/gui"
using win, gui

const IDC_LIST = 101
const IDC_SHOW = 102

declare function WndProc( byval hwnd as HWND, byval uMsg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT

function main() as long
    SetProcessDpiAwareness( PROCESS_SYSTEM_DPI_AWARE )
    dim pWindow as CWindow = "GuiDemo"
    dim hWin as HWND = pWindow.Create( NULL, "sys/win/gui", @WndProc )
    pWindow.SetClientSize( 300, 240 )
    pWindow.Center()
    dim hList as HWND = pWindow.AddControl( "ListBox", hWin, IDC_LIST, "", 10, 10, 280, 180 )
    for i as long = 1 to 12
        ListBox.AddString( hList, "Item " & i )
    next
    ListBox.SetCurSel( hList, 0 )
    pWindow.AddControl( "Button", hWin, IDC_SHOW, "&Show", 190, 202, 100, 28 )
    pWindow.AnchorControl( hList, ANCHOR_HEIGHT_WIDTH )
    pWindow.AnchorControl( IDC_SHOW, ANCHOR_BOTTOM_RIGHT )
    return pWindow.DoEvents( SW_NORMAL )
end function

function WndProc( byval hwnd as HWND, byval uMsg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
    select case uMsg
        case WM_COMMAND
            select case CBCTL( wParam, lParam )
                case IDC_SHOW
                    dim hList as HWND = GetDlgItem( hwnd, IDC_LIST )
                    SetWindowText( hwnd, "Selected: " & ListBox.GetText( hList, ListBox.GetCurSel( hList ) ) )
                case IDCANCEL
                    SendMessageW( hwnd, WM_CLOSE, 0, 0 )
            end select
            return 0
        case WM_DESTROY
            PostQuitMessage( 0 )
            return 0
    end select
    return DefWindowProcW( hwnd, uMsg, wParam, lParam )
end function

end main()

Pages

Classes

Page Covers
CWindow the main window class: creating windows and controls, DPI scaling, the message loop, colours, anchors, accelerators, scrolling
CTabPage a CWindow that is one page of a tab control
CDialog dialog boxes built from an in-memory template, with the same services as CWindow
CXpButton an owner-drawn button that follows the visual style and shows images beside or instead of its text
CMaskedEdit an edit box that accepts input only in the shape of a mask
CMemBmp a memory bitmap with its own device context, blank or loaded from a file or resource
CPrint choosing and setting up a printer, its page measurements and printing
CGraphCtx a graphic control: a child window that keeps what is drawn on it, with GDI, GDI+ or OpenGL
CExplorerBrowser the Windows Explorer browser hosted in a window, with its events
File dialogs CIOpenFileDialog and CISaveFileDialog, the Windows open and save dialogs
CIFileDialogCustomize adding check boxes, lists, buttons and other controls to an open or save dialog
File dialog events handling the events of an open or save dialog and of the controls added to it
gui macros and helpers CBCTL, CBCTLMSG, CBNMHDR and the other macros that read wParam and lParam

Control namespaces

Page Covers
ListView list views: columns, items, subitems, selection, image lists, views
TreeView tree views: inserting, finding and expanding items, selection, images
Header header controls: items, widths, order, filters, image lists
ToolBar toolbars: buttons, states, image lists, sizes
Rebar rebars: bands and their child windows
Menu menus: creating them, adding, checking, enabling and finding items
StatusBar status bars: parts, text, icons
ToolTip tooltips: adding tools, text, delays, colours, titles
Edit edit boxes: text, selection, lines, limits, margins, undo
Combo combo boxes: adding, finding and selecting strings, the drop-down list
CBEx extended combo boxes, with images
ListBox list boxes: adding, finding and selecting strings, multiple selection
Button buttons, check boxes and radio buttons: state, images, split buttons, notes
Label static controls: text, icons, bitmaps, cursors and metafiles
ProgBar progress bars: range, position, step, state, colours
TabCtl tab controls: tabs, selection, image lists, and destroying CTabPage pages
TrackBar trackbars: range, position, ticks, selection, buddies
UpDown up-down controls: range, position, base, buddy
Pager pager controls: the child window, buttons, position
MonthCal month calendars: the selected date or range, limits, colours
DTP date and time pickers: the date and time, format, the drop-down calendar
Animate animation controls: opening, playing and stopping a clip
HotKey hot key controls: reading and setting the key and its rules
IPAddress IP address controls: the address, its fields and their ranges
PropSheet property sheets and wizards: creating them, their buttons
ScrollBar scroll bar controls: range, position, showing and enabling
SysLink SysLink controls: links, their state and size

See also

Clone this wiki locally