📄 unawinclasses.pas
字号:
}
function onGetDlgCode(): LRESULT; virtual;
{DP:METHOD
}
function parentResize(dw, dh: int): unaWinWindow; virtual;
{DP:METHOD
This method is called periodically when there are no pending messages in window queue and window is application or is in modal state.
}
procedure idle(); virtual;
{
}
function doCreateWindow(): hWnd; virtual;
public
{DP:METHOD
Creates new Windows window.
}
constructor create(const params: unaWinCreateParams); overload;
{DP:METHOD
Creates new Windows window.
}
constructor create(wndClass: unaWinClass = nil; font: unaWinFont = nil; const caption: string = ''; parent: hWnd = 0; style: unsigned = WS_OVERLAPPEDWINDOW or WS_VISIBLE; exStyle: unsigned = 0; x: int = int(CW_USEDEFAULT); y: int = int(CW_USEDEFAULT); w: int = int(CW_USEDEFAULT); h: int = int(CW_USEDEFAULT); menu: hMenu = 0; instance: hModule = 0; icon: hIcon = 0); overload;
{DP:METHOD
Creates new "standard" Windows window (such as BUTTON, EDIT and so on).
}
constructor createStdWnd(const className: string; const caption: string = ''; parent: unaWinWindow = nil; style: unsigned = 0; exStyle: unsigned = 0; x: int = 2; y: int = 2; w: int = 20; h: int = 20; id: unsigned = 0);
{DP:METHOD
Destroys Windows window. If this window has child windows, they will be also destroyed.
}
destructor Destroy(); override;
//
{DP:METHOD
Creates Windows window. Returns handle on new created window. If window is already created does nothing and returns handle on previously created window.
}
function createWindow(): hWnd;
{DP:METHOD
Enters TM-safe lock state, if possible. Returns False if locking was impossible during given time interval.
}
function enter(timeout: unsigned = 10000): bool;
{DP:METHOD
Frees the window from TM-safe lock state.
}
procedure leave();
{DP:METHOD
Destroys Windows window. Child windows (if any) will NOT be destroyed.
}
procedure destroyWindow();
{DP:METHOD
Returns handle on window. Creates window if necessary.
}
function getHandle(): hWnd; // creates window if necessary
//
procedure addChild(child: unaWinWindow);
{DP:METHOD
Returns pointer on unaWinCreateParams structure.
}
function getCreateParams(): punaWinCreateParams;
{DP:METHOD
Sets anchors for window. Default anchors are [unawinAnchor_LEFT or unawinAnchor_TOP].
}
function setAnchors(anchors: unsigned = unawinAnchor_LEFT or unawinAnchor_TOP): unaWinWindow;
{DP:METHOD
Sets new font for window.
}
function setFont(font: unaWinFont): unaWinWindow;
{DP:METHOD
Returns length of text associated with window.
}
function getTextLength(): int;
{DP:METHOD
Returns text associated with window.
}
function getText(): string;
{DP:METHOD
Sets text to be associated with window.
}
function setText(const text: string): unaWinWindow;
{DP:METHOD
Default value -1 for wnd means window handle will be used instead.
<BR>You can specify 0 as wnd to retrieve the entire screen DC.
<BR>Make sure you call releaseDC() as soon as possible.
}
function getDC(clipRgn: hRGN = 0; flags: unsigned = DCX_WINDOW; wnd: int = -1): hDC;
{DP:METHOD
Default value 0 means last DC returned by getDC() method will be used
<BR>Class and private DCs (i.e. when isCommonDC property is false) will not be
released, and it is safe to call this function for that class styles.
}
function releaseDC(dc: hDC = 0): int;
{DP:METHOD
Posts a message for window.
}
function postMessage(message: unsigned; wParam: int = 0; lParam: int = 0): bool;
{DP:METHOD
Sends a message to window.
}
function sendMessage(message: unsigned; wParam: int = 0; lParam: int = 0): int;
{DP:METHOD
Process all messages waiting in window message queue.
}
function processMessages(): unaWinWindow;
{DP:METHOD
Displays message box with specified text.
}
function messageBox(const text: string; const caption: string = ''; flags: unsigned = MB_OK): unsigned;
//
{DP:METHOD
Show (SW_SHOW) or hides (SW_HIDE) the window.
}
function show(cmd: unsigned = SW_SHOW): unaWinWindow;
{DP:METHOD
}
function showModal(cmd: unsigned = SW_SHOW): int;
{DP:METHOD
}
function endModal(modalResult: int = -1): unaWinWindow;
{DP:METHOD
Updates the window contents.
}
function update(): unaWinWindow;
{DP:METHOD
Redraws the window contents.
}
function redraw(): unaWinWindow;
{DP:METHOD
Sets the focus on window. If firstChild = true sets the focus on first child window.
}
function setFocus(firstChild: bool = false): unaWinWindow;
{DP:METHOD
Enables or disables the window.
}
function enable(doEnable: bool = true): unaWinWindow;
// -- --
{DP:METHOD
For non-common DCs if dc = 0, it will create and release a DC, so use this method carefully (performance issue)
}
function textOut(const text: string; x: int = 0; y: int = 0; dc: hDC = 0): bool;
{DP:METHOD
Y coordinate of top-left window corner (in relative coordinates).
}
property top: int read getTop write setTop;
{DP:METHOD
X coordinate of top-left window corner (in relative coordinates).
}
property left: int read getLeft write setLeft;
{DP:METHOD
Height of the window.
}
property height: int read getHeight write setHeight;
{DP:METHOD
Width of the window.
}
property width: int read getWidth write setWidth;
{DP:METHOD
Window anchors.
}
property anchors: unsigned read f_anchors write setFAnchors;
{DP:METHOD
Minimum value for window width.
}
property minWidth: int read f_minWidth write setMinWidth;
{DP:METHOD
Minimum value for window height.
}
property minHeight: int read f_minHeight write setMinHeight;
//
{DP:METHOD
Window handle.
}
property wnd: hWnd read f_handle; // does not creates window
{DP:METHOD
Window class.
}
property winClass: unaWinClass read getWndClass;
{DP:METHOD
false if this window belongs to class with CS_CLASSDC, CS_OWNDC or CS_PARENTDC style set.
<BR>true otherwise
}
property isCommonDC: bool read f_isCommonDC;
{DP:METHOD
Returns true if window has WS_VISIBLE style.
}
property isVisible: bool index WS_VISIBLE read hasStyle;
{DP:METHOD
Returns true if window has WS_MINIMIZE style.
}
property isMinimized: bool index WS_MINIMIZE read hasStyle;
{DP:METHOD
Returns true if window has WS_MAXIMIZE style.
}
property isMaximized: bool index WS_MAXIMIZE read hasStyle;
{DP:METHOD
Returns true if window has WS_DISABLED style.
}
property isDisabled: bool index WS_DISABLED read hasStyle;
{DP:METHOD
Returns true if window has WS_OVERLAPPED style.
}
property isOverlapped: bool index WS_OVERLAPPED read hasStyle;
{DP:METHOD
This property is valid only if isCommonDC is false.
<BR>Use getDC()/releaseDC() methods otherwise.
}
property deviceContext: hDC read f_dc;
{DP:METHOD
Window font.
}
property font: unaWinFont read getFont write setFFont;
//
property rect: tRECT read f_rect;
//
property unaParent: unaWinWindow read getUnaParent;
{DP:METHOD
Command event. (Handles WM_COMMAND messages).
}
property wmCommand: tmessageEvent read f_wmCommand write f_wmCommand;
end;
//
// -- unaWinSplashWindow --
//
unaWinStatic = class;
{DP:CLASS
This is small centered window without borders.
}
unaWinSplashWindow = class(unaWinWindow)
private
f_static: unaWinStatic;
protected
function parentResize(dw, dh: int): unaWinWindow; override;
function onClick(button: Word; x, y: word): bool; override;
public
{DP:METHOD
Creates splash window with centered text inside.
}
constructor create(const text: string = ''; parent: unaWinWindow = nil; w: int = 200; h: int = 150);
procedure BeforeDestruction(); override;
//
{DP:METHOD
Changes the text displayed inside the window.
}
procedure setText(const text: string; doShow: bool = false);
end;
//
// -- unaWinButton --
//
{DP:CLASS
BUTTON window.
}
unaWinButton = class(unaWinWindow)
public
{DP:METHOD
Creates Windows BUTTON window.
}
constructor create(const caption: string; parent: unaWinWindow; id: unsigned = 0; x: int = 2; y: int = 2; w: int = 64; h: int = 24; style: unsigned = BS_PUSHBUTTON or WS_CHILD or WS_TABSTOP or WS_VISIBLE); overload;
end;
//
// -- unaWinCheckBox --
//
{DP:CLASS
Checkbox window.
}
unaWinCheckBox = class(unaWinButton)
private
function getChecked: bool;
procedure setChecked(value: bool);
public
{DP:METHOD
Creates Windows BUTTON window with BS_CHECKBOX style set by default.
}
constructor create(const caption: string; parent: unaWinWindow; id: unsigned = 0; x: int = 2; y: int = 2; w: int = 64; h: int = 24; style: unsigned = BS_CHECKBOX or BS_AUTOCHECKBOX or WS_CHILD or WS_TABSTOP or WS_VISIBLE); overload;
//
{DP:METHOD
}
property checked: bool read getChecked write setChecked;
end;
//
// -- unaWinCombobox --
//
{DP:CLASS
Combobox window.
}
unaWinCombobox = class(unaWinWindow)
private
function getItemIndex(): int;
procedure setItemIndex(value: int);
function getCount(): unsigned;
public
{DP:METHOD
Creates Windows COMBOBOX window with CBS_DROPDOWNLIST style set by default.
}
constructor create(parent: unaWinWindow; x: int = 2; y: int = 2; w: int = 80; h: int = 120; style: unsigned = CBS_DROPDOWNLIST or WS_CHILD or WS_TABSTOP or WS_VSCROLL or WS_VISIBLE); overload;
//
{DP:METHOD
Adds a string to combobox list.
}
function add(const str: string): unaWinCombobox;
{DP:METHOD
Returns string index in combobox list, or -1 if string was not found.
}
function findString(const str: string): int;
//
{DP:METHOD
Returns current selected item (string) index, or -1 if no item is selected.
}
property itemIndex: int read getItemIndex write setItemIndex;
{DP:METHOD
Returns number of items (strings) in combobox list.
}
property count: unsigned read getCount;
end;
//
// -- unaWinEdit --
//
{DP:CLASS
EDIT window.
}
unaWinEdit = class(unaWinWindow)
protected
function onGetDlgCode(): LRESULT; override;
public
{DP:METHOD
Creates EDIT window.
}
constructor create(const text: string; parent: unaWinWindow; x: int = 2; y: int = 2; w: int = 64; h: int = 24; style: unsigned = ES_LEFT or ES_AUTOHSCROLL or WS_CHILD or WS_TABSTOP or WS_VISIBLE or WS_BORDER; exStyle: unsigned = WS_EX_CLIENTEDGE); overload;
//
{DP:METHOD
Sets/resets read only mode for edit.
}
function setReadOnly(value: bool = true): unaWinEdit;
end;
//
// -- unaWinMemo --
//
{DP:CLASS
Memo window.
}
unaWinMemo = class(unaWinEdit)
protected
function onCommand(cmd: int; wnd: int): bool; override;
public
{DP:METHOD
Creates EDIT window with ES_MULTILINE style set by default.
}
constructor create(const text: string; parent: unaWinWindow; x: int = 2; y: int = 2; w: int = 64; h: int = 18; style: unsigned = ES_LEFT or WS_CHILD or ES_MULTILINE or ES_AUTOVSCROLL or ES_AUTOHSCROLL or WS_HSCROLL or WS_VSCROLL or WS_TABSTOP or WS_VISIBLE); overload;
//
{DP:METHOD
Sets the selection in memo.
}
function setSel(starting, ending: int): unaWinMemo;
{DP:METHOD
Replaces selected text with given string.
}
function replaceSel(const line: string): unaWinMemo;
{DP:METHOD
Returns line from memo with specified index (starting form 0).
<BR>Line length is limited to 65535.
}
function getLine(index: unsigned = 0): string;
end;
//
// -- unaWinListBox --
//
{DP:CLASS
LISTBOX window.
}
unaWinListBox = class(unaWinWindow)
public
{DP:METHOD
Creates LISTBOX window.
}
constructor create(parent: unaWinWindow; x: int = 2; y: int = 2; w: int = 64; h: int = 50; style: unsigned = LBS_STANDARD or WS_CHILD or WS_TABSTOP or WS_VISIBLE); overload;
end;
//
// -- unaWinStatic --
//
{DP:CLASS
STATIC window
}
unaWinStatic = class(unaWinWindow)
public
{DP:METHOD
Creates STATIC window.
}
constructor create(const caption: string; parent: unaWinWindow; x: int = 2; y: int = 2; w: int = 64; h: int = 18; style: unsigned = SS_SIMPLE or WS_CHILD or WS_VISIBLE); overload;
end;
//
// -- unaWinApp --
//
{DP:CLASS
Window class which can be used as main application window.
}
unaWinApp = class(unaWinWindow)
private
f_exitCode: int;
f_okToRun: bool;
f_isRunning: bool;
f_sleepEvent: unaEvent;
f_mustTerminate: bool;
//
protected
function onClose(): bool; override;
//
function initWindow(): bool; override;
{DP:METHOD
WM_NCDESTROY message handler.
<BR>Calls quit() method to terminate the application.
}
function notifyDestroy(): bool; override;
{DP:METHOD
WM_ACTIVATEAPP message handler.
}
function onActivateApp(isActivate: bool; activeThreadId: unsigned): bool; override;
//
function onRunEnterLeave(enter: bool): bool; virtual;
public
procedure AfterConstruction(); override;
procedure BeforeDestruction(); override;
{DP:METHOD
Main window cycle. Do not returns the control until WM_QUIT messages is received.
}
function run(): unaWinApp;
{DP:METHOD
Terminates the application using the PostQuitMessage() routine.
}
procedure quit(exitCode: int = 0); // terminates application
//
procedure wakeUp();
{DP:METHOD
Specifies exit code used when terminating the application.
}
property exitCode: int read f_exitCode write f_exitCode;
{DP:METHOD
Specifies exit code used when terminating the application.
}
property isRunning: bool read f_isRunning;
end;
//
// -- unaWinGraphicsApp --
//
{DP:CLASS
Windows application whith graphics support.
}
unaWinGraphicsApp = class(unaWinApp)
private
f_canResize: bool;
f_memDC: hDC;
f_grDC: hDC;
//
f_fps: unsigned;
f_actualFps: unsigned;
f_fcount: int64;
f_fpsMark: int64;
//
f_frameWidth: unsigned;
f_frameHeight: unsigned;
f_bgColor: COLORREF;
f_bgBrush: hBRUSH;
//
f_memXSize: int;
f_memYSize: int;
f_memBmpInfo: BITMAPINFO;
f_memBmpBits: pointer;
f_memDIB: HBITMAP;
//
f_drawTimer: unaThreadTimer;
f_eraseBg: bool;
//
procedure myOnDrawTimer(sender: tObject);
procedure initApp();
protected
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -