📄 qwindows.pas
字号:
{-------------------------------------------------------------------------------
QWindows.pas
Copyright (c) 2003,2004, Andre Snepvangers (asn att xs4all dott nl),
All rights reserved.
Version 1.0
Description: Qt based wrappers for common MS Windows API's
Purpose: Reduce coding effort for porting VCL based components to VisualCLX
compatible components. Simplify VCL code sharing.
Contributor(s): Andreas Hausladen [Andreas dott Hausladen att gmx dott de]
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files(the "Software"), to deal in
the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The origin of this software must not be misrepresented, you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
Altered source versions must be plainly marked as such, and must not
be misrepresented as being the original software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
--------------------------------------------------------------------------------
Known Issues:
- Covers only a small part of the Windows APIs
- Not all functionality is supported
{-----------------------------------------------------------------------------}
// $Id: QWindows.pas,v 1.64 2005/02/20 18:56:04 asnepvangers Exp $
unit QWindows;
interface
uses
{$IFDEF MSWINDOWS}
Windows,
{$ENDIF MSWINDOWS}
{$IFDEF LINUX}
Libc, DateUtils,
{$ENDIF LINUX}
Types, StrUtils, SysUtils, Classes, Math, Contnrs, SyncObjs, QDialogs,
QTypes, Qt, QConsts, QGraphics, QControls, QForms, QExtCtrls, QStdCtrls,
QButtons, QImgList, QStyle;
type
IPerformControl = interface
['{B11AA73D-D7C2-43E5-BED8-8F82DE6152AB}']
function Perform(Msg: Cardinal; WPar, LPar: Longint): Longint;
end;
{$IFDEF LINUX}
resourcestring
SFCreateError = 'Unable to create file %s';
SFOpenError = 'Unable to open file %s';
SReadError = 'Error reading file';
SWriteError = 'Error writing file';
SQThreadError = 'Thread Error in QWindows: %s (%d)';
{$ENDIF LINUX}
var
NewStyleControls: Boolean = True;
const
{ SetBkMode: background modes }
TRANSPARENT = 1; // BGMode_TransparentMode
OPAQUE = 2; // BGMode_OpaqueMode
{ constants for CreateDIBitmap }
CBM_INIT = 4; { initialize bitmap }
DIB_RGB_COLORS = 0;
// DIB_PAL_COLORS = 1; // not supported by CreateDIBitmap
{ windows symbolic colors } { mapping VisualCLX Symbolic colors}
COLOR_SCROLLBAR = 0; // clNormalButton
COLOR_BACKGROUND = 1; // clNormalBackground
COLOR_ACTIVECAPTION = 2; // clActiveHighlightedText
COLOR_INACTIVECAPTION = 3; // clDisabledHighlightedText
COLOR_MENU = 4; // clNormalMid
COLOR_WINDOW = 5; // clNormalBase
COLOR_WINDOWFRAME = 6; // clNormalHighlight
COLOR_MENUTEXT = 7; // clNormalButtonText
COLOR_WINDOWTEXT = 8; // clNormalText
COLOR_CAPTIONTEXT = 9; // clNormalHighlightedText
COLOR_ACTIVEBORDER = 10; // clActiveHighlight
COLOR_INACTIVEBORDER = 11; // clDisabledHighlight
COLOR_APPWORKSPACE = 12; // clNormalMid
COLOR_HIGHLIGHT = 13; // clNormalHighlight
COLOR_HIGHLIGHTTEXT = 14; // clNormalHighlightedText
COLOR_BTNFACE = 15; // clNormalButton
COLOR_BTNSHADOW = $10; // clNormalDark
COLOR_GRAYTEXT = 17; // clNormalDisabledText
COLOR_BTNTEXT = 18; // clNormalButtonText
COLOR_INACTIVECAPTIONTEXT = 19; // clDisabledHighlightedText
COLOR_BTNHIGHLIGHT = 20; // clActiveLight
COLOR_3DDKSHADOW = 21; // clNormalMid
COLOR_3DLIGHT = 22; // clNormalMidLight
COLOR_INFOTEXT = 23; // clNormalText
COLOR_INFOBK = 24; // TColor($E1FFFF)
// = 25; // ?? (asn: defined as clBlack for now)
COLOR_HOTLIGHT = 26; // clActiveHighlight (asn: ??)
COLOR_GRADIENTACTIVECAPTION = 27; // clActiveHighLight (asn: ??)
COLOR_GRADIENTINACTIVECAPTION = 28; // clDisabledHighlight (asn: ??)
COLOR_ENDCOLORS = COLOR_GRADIENTINACTIVECAPTION;
(*
COLOR_MENUHILIGHT = 29;
COLOR_MENUBAR = 30;
COLOR_ENDCOLORS = COLOR_MENUBAR;
*)
COLOR_DESKTOP = COLOR_BACKGROUND;
COLOR_3DFACE = COLOR_BTNFACE;
COLOR_3DSHADOW = COLOR_BTNSHADOW;
COLOR_3DHIGHLIGHT = COLOR_BTNHIGHLIGHT;
COLOR_3DHILIGHT = COLOR_BTNHIGHLIGHT;
COLOR_BTNHILIGHT = COLOR_BTNHIGHLIGHT;
{ CombineRgn return values }
NULLREGION = 1; // Region is empty
SIMPLEREGION = 2; // Region is a rectangle
COMPLEXREGION = 3; // Region is not a rectangle
ERROR = 0; // Region error
RGN_ERROR = ERROR;
{ constants for CreatePolygon }
ALTERNATE = 1;
WINDING = 2;
{ flags for DrawFrameControl }
DFC_CAPTION = 1;
DFC_MENU = 2;
DFC_SCROLL = 3;
DFC_BUTTON = 4;
DFC_POPUPMENU = 5;
DFCS_CAPTIONCLOSE = 0;
DFCS_CAPTIONMIN = 1;
DFCS_CAPTIONMAX = 2;
DFCS_CAPTIONRESTORE = 3;
DFCS_CAPTIONHELP = 4;
DFCS_MENUARROW = 0;
DFCS_MENUCHECK = 1;
DFCS_MENUBULLET = 2;
DFCS_MENUARROWRIGHT = 4;
DFCS_SCROLLUP = 0;
DFCS_SCROLLDOWN = 1;
DFCS_SCROLLLEFT = 2;
DFCS_SCROLLRIGHT = 3;
DFCS_SCROLLCOMBOBOX = 5;
DFCS_SCROLLSIZEGRIP = 8;
DFCS_SCROLLSIZEGRIPRIGHT = $10;
DFCS_BUTTONCHECK = 0;
DFCS_BUTTONRADIOIMAGE = 1;
DFCS_BUTTONRADIOMASK = 2;
DFCS_BUTTONRADIO = 4;
DFCS_BUTTON3STATE = 8;
DFCS_BUTTONPUSH = $10;
DFCS_INACTIVE = $100;
DFCS_PUSHED = $200;
DFCS_CHECKED = $400;
DFCS_TRANSPARENT = $800;
DFCS_HOT = $1000;
DFCS_ADJUSTRECT = $2000;
DFCS_FLAT = $4000;
DFCS_MONO = $8000;
{ 3D border styles }
BDR_RAISEDOUTER = 1;
BDR_SUNKENOUTER = 2;
BDR_RAISEDINNER = 4;
BDR_SUNKENINNER = 8;
BDR_OUTER = BDR_SUNKENOUTER or BDR_RAISEDOUTER;
BDR_INNER = BDR_SUNKENINNER or BDR_SUNKENOUTER;
BDR_RAISED = BDR_RAISEDINNER or BDR_RAISEDOUTER;
BDR_SUNKEN = BDR_SUNKENINNER or BDR_SUNKENOUTER;
EDGE_RAISED = BDR_RAISEDOUTER or BDR_RAISEDINNER;
EDGE_SUNKEN = BDR_SUNKENOUTER or BDR_SUNKENINNER;
EDGE_ETCHED = BDR_SUNKENOUTER or BDR_RAISEDINNER;
EDGE_BUMP = BDR_RAISEDOUTER or BDR_SUNKENINNER;
{ Border flags }
BF_LEFT = 1;
BF_TOP = 2;
BF_RIGHT = 4;
BF_BOTTOM = 8;
BF_DIAGONAL = $10;
BF_TOPLEFT = BF_TOP or BF_LEFT;
BF_TOPRIGHT = BF_TOP or BF_RIGHT;
BF_BOTTOMLEFT = BF_BOTTOM or BF_LEFT;
BF_BOTTOMRIGHT = BF_BOTTOM or BF_RIGHT;
BF_RECT = BF_TOPLEFT or BF_BOTTOMRIGHT;
{ For diagonal lines, the BF_RECT flags specify the end point of the}
{ vector bounded by the rectangle parameter.}
BF_DIAGONAL_ENDTOPRIGHT = BF_DIAGONAL or BF_TOP or BF_RIGHT;
BF_DIAGONAL_ENDTOPLEFT = BF_DIAGONAL or BF_TOP or BF_LEFT;
BF_DIAGONAL_ENDBOTTOMLEFT = BF_DIAGONAL or BF_BOTTOM or BF_LEFT;
BF_DIAGONAL_ENDBOTTOMRIGHT = BF_DIAGONAL or BF_BOTTOM or BF_RIGHT;
BF_MIDDLE = $800; { Fill in the middle }
BF_SOFT = $1000; { For softer buttons }
BF_ADJUST = $2000; { Calculate the space left over }
BF_FLAT = $4000; { For flat rather than 3D borders }
BF_MONO = $8000; { For monochrome borders }
{ DrawIconEx diFlags }
DI_MASK = 1;
DI_IMAGE = 2;
DI_NORMAL = 3;
// DI_COMPAT = 4; not supported
DI_DEFAULTSIZE = 8;
{ DrawText format (windows) flags }
DT_TOP = 0;
DT_LEFT = 0;
DT_CENTER = 1;
DT_RIGHT = 2;
DT_VCENTER = 4;
DT_BOTTOM = 8;
DT_WORDBREAK = $10;
DT_SINGLELINE = $20;
DT_EXPANDTABS = $40;
DT_TABSTOP = $80;
DT_NOCLIP = $100;
(* DT_EXTERNALLEADING = $200; // not supported *)
DT_CALCRECT = $400;
DT_NOPREFIX = $800;
DT_INTERNAL = $1000; // Uses the system font to calculate text metrics.
DT_EDITCONTROL = $2000; // ignored
DT_PATH_ELLIPSIS = $4000;
DT_ELLIPSIS = $8000;
DT_END_ELLIPSIS = DT_ELLIPSIS;
DT_MODIFYSTRING = $10000;
DT_RTLREADING = $20000; // ignored
DT_WORD_ELLIPSIS = $40000;
DT_HIDEPREFIX = $100000;
DT_PREFIXONLY = $200000;
{ ExtTextOut format flags }
ETO_OPAQUE = 2;
ETO_CLIPPED = 4;
ETO_RTLREADING = $80; // ignored
{ font metrics }
DEFAULT_PITCH = 0;
FIXED_PITCH = 1;
VARIABLE_PITCH = 2;
DEFAULT_CHARSET = 1;
{$IFDEF LINUX}
HINSTANCE_ERROR = 0;
HINSTANCE_OK = HINSTANCE_ERROR + 1;
{$ENDIF LINUX}
{ BrushStyle mappings}
HS_BDIAGONAL = BrushStyle_BDiagPattern; // 45-degree downward left-to-right hatch
HS_CROSS = BrushStyle_CrossPattern; // Hor. and vertical crosshatch
HS_DIAGCROSS = BrushStyle_DiagCrossPattern;// 45-degree crosshatch
HS_FDIAGONAL = BrushStyle_FDiagPattern; // 45-degree upward left-to-right hatch
HS_HORIZONTAL = BrushStyle_HorPattern; // Horizontal hatch
HS_VERTICAL = BrushStyle_VerPattern; // Vertical hatch
HWND_TOP = Cardinal(0);
HWND_BOTTOM = Cardinal(1);
HWND_TOPMOST = Cardinal(-1);
HWND_NOTOPMOST = Cardinal(-2);
{$IFDEF LINUX}
{ GlobalMemory }
GMEM_FIXED = 0;
GMEM_MOVEABLE = 2;
GMEM_NOCOMPACT = $10;
GMEM_NODISCARD = $20;
GMEM_ZEROINIT = $40; // only supported flag
GMEM_MODIFY = $80;
GMEM_DISCARDABLE = $100;
GMEM_NOT_BANKED = $1000;
GMEM_SHARE = $2000;
GMEM_DDESHARE = $2000;
GMEM_NOTIFY = $4000;
GMEM_LOWER = GMEM_NOT_BANKED;
GMEM_VALID_FLAGS = 32626;
GMEM_INVALID_HANDLE = $8000;
GHND = GMEM_MOVEABLE or GMEM_ZEROINIT;
GPTR = GMEM_FIXED or GMEM_ZEROINIT;
{$ENDIF LINUX}
INFINITE = Longword($FFFFFFFF); // Infinite timeout
INVALID_HANDLE_VALUE = DWORD(-1);
MaxWord = High(Cardinal);
{ MessageBox() return values }
IDCLOSE = 0;
IDOK = 1;
IDCANCEL = 2;
IDYES = 3;
IDNO = 4;
IDABORT = 5;
IDRETRY = 6;
IDIGNORE = 7;
{ aliases }
ID_OK = IDOK;
ID_CANCEL = IDCANCEL;
ID_ABORT = IDABORT;
ID_RETRY = IDRETRY;
ID_IGNORE = IDIGNORE;
ID_YES = IDYES;
ID_NO = IDNO;
ID_CLOSE = IDCLOSE;
IDHELP = 9; // not supported
ID_HELP = IDHELP; // not supported
IDTRYAGAIN = IDRETRY;
IDCONTINUE = IDIGNORE;
{$EXTERNALSYM LB_OKAY}
LB_OKAY = 0;
{$EXTERNALSYM LB_ERR}
LB_ERR = -1;
{$EXTERNALSYM LB_ERRSPACE}
LB_ERRSPACE = -2;
{$EXTERNALSYM CB_OKAY}
CB_OKAY = 0;
{$EXTERNALSYM CB_ERR}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -