unit general; //{$DEFINE _DEBUG} {$IFNDEF _DEBUG} {$A+,B-,C-,D-,E-,F-,G+,H+,I-,J-,K-,L-,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y-,Z1} {$MINSTACKSIZE $00004000} {$MAXSTACKSIZE $00100000} {$IMAGEBASE $00400000} {$APPTYPE GUI} {$ENDIF} interface {$IFDEF _DEBUG} uses SysUtils, Windows; {$ENDIF} //--- Types.pas ---------------------------------------------------------------- type TSmallPoint = packed record x: SmallInt; y: SmallInt; end; TPoint = packed record X: Longint; Y: Longint; end; PPoint = ^TPoint; TRect = packed record case Integer of 0: (Left, Top, Right, Bottom: Longint); 1: (TopLeft, BottomRight: TPoint); end; PRect = ^TRect; TSize = packed record cx: Longint; cy: Longint; end; //--- Windows.pas -------------------------------------------------------------- const CCHDEVICENAME = 32; { size of a device name string } CCHFORMNAME = 32; { size of a form name string } LF_FACESIZE = 32; SHIFTJIS_CHARSET = $80; FF_MODERN = (3 shl 4); { Constant stroke width, serifed or sans-serifed. } type // MakeIntResourceA = PAnsiChar; // MakeIntResourceW = PWideChar; // MakeIntResource = MakeIntResourceA; MakeIntResource = PAnsiChar; ATOM = Word; BOOL = LongBool; DWORD = LongWord; COLORREF = DWORD; FARPROC = Pointer; HBITMAP = LongWord; HBRUSH = LongWord; HDC = LongWord; HGDIOBJ = LongWord; HICON = LongWord; HCURSOR = HICON; { HICONs & HCURSORs are polymorphic } HFONT = LongWord; HLOCAL = THandle; HMENU = LongWord; HMONITOR = Integer; HPEN = LongWord; HRGN = LongWord; HWND = LongWord; LPCSTR = PAnsiChar; LPCWSTR = PWideChar; SHORT = Smallint; UINT = LongWord; WPARAM = Longint; LPARAM = Longint; LRESULT = Longint; TFarProc = Pointer; TFNTimerProc = TFarProc; TFNWndEnumProc = TFarProc; { TLogFontW = packed record lfHeight : Longint; lfWidth : Longint; lfEscapement : Longint; lfOrientation : Longint; lfWeight : Longint; lfItalic : Byte; lfUnderline : Byte; lfStrikeOut : Byte; lfCharSet : Byte; lfOutPrecision : Byte; lfClipPrecision : Byte; lfQuality : Byte; lfPitchAndFamily : Byte; lfFaceName : array[0..LF_FACESIZE - 1] of WideChar; end; } TPaintStruct = packed record hdc : HDC; fErase : BOOL; rcPaint : TRect; fRestore : BOOL; fIncUpdate : BOOL; rgbReserved : array[0..31] of Byte; end; TFNWndProc = TFarProc; TMsg = packed record hwnd : HWND; message : UINT; wParam : WPARAM; lParam : LPARAM; time : DWORD; pt : TPoint; end; TWndClassA = packed record style : UINT; lpfnWndProc : TFNWndProc; cbClsExtra : Integer; cbWndExtra : Integer; hInstance : HINST; hIcon : HICON; hCursor : HCURSOR; hbrBackground : HBRUSH; lpszMenuName : PAnsiChar; lpszClassName : PAnsiChar; end; TMenuItemInfoA = packed record cbSize : UINT; fMask : UINT; fType : UINT; { used if MIIM_TYPE} fState : UINT; { used if MIIM_STATE} wID : UINT; { used if MIIM_ID} hSubMenu : HMENU; { used if MIIM_SUBMENU} hbmpChecked : HBITMAP; { used if MIIM_CHECKMARKS} hbmpUnchecked : HBITMAP; { used if MIIM_CHECKMARKS} dwItemData : DWORD; { used if MIIM_DATA} dwTypeData : PAnsiChar; { used if MIIM_TYPE} cch : UINT; { used if MIIM_TYPE} hbmpItem : HBITMAP; { used if MIIM_BITMAP} end; TSecurityAttributes = record nLength : DWORD; lpSecurityDescriptor : Pointer; bInheritHandle : BOOL; end; PSecurityAttributes = ^TSecurityAttributes; TOverlapped = record Internal : DWORD; InternalHigh : DWORD; Offset : DWORD; OffsetHigh : DWORD; hEvent : THandle; end; POverlapped = ^TOverlapped; const CAPTUREBLT = $40000000; //レイヤーウィンドウも含めたキャプチャを行うフラグ SRCCOPY = $00CC0020; { dest = source } PS_SOLID = 0; R2_COPYPEN = 13; { P } R2_MASKPEN = 9; { DPa } R2_NOP = 11; { D } R2_NOT = 6; { Dn } RGN_OR = 2; RGN_COPY = 5; WHITE_BRUSH = 0; BLACK_BRUSH = 4; DEFAULT_GUI_FONT = 17; COLOR_WINDOWTEXT = 8; COLOR_WINDOW = 5; HWND_TOPMOST = HWND(-1); HWND_NOTOPMOST = HWND(-2); SWP_NOSIZE = 1; SWP_NOMOVE = 2; SWP_NOZORDER = 4; SWP_NOACTIVATE = $10; SC_SIZE = 61440; SC_MAXIMIZE = 61488; MF_BYCOMMAND = 0; MF_BYPOSITION = $400; MF_CHECKED = 8; MF_POPUP = $10; MF_SEPARATOR = $800; MF_STRING = 0; MF_UNCHECKED = 0; MIIM_ID = 2; MIIM_STATE = 1; MIIM_FTYPE = $100; MIIM_STRING = $40; MFT_RADIOCHECK = $200; MFT_STRING = MF_STRING; MFS_CHECKED = MF_CHECKED; IDC_ARROW = MakeIntResource(32512); CS_VREDRAW = DWORD(1); CS_HREDRAW = DWORD(2); CS_OWNDC = $20; WS_VISIBLE = $10000000; WS_CAPTION = $C00000; { WS_BORDER or WS_DLGFRAME } WS_POPUP = DWORD($80000000); WS_SYSMENU = $80000; WS_MINIMIZEBOX = $20000; WS_BORDER = $800000; WS_THICKFRAME = $40000; GA_PARENT = 1; // CWP_SKIPINVISIBLE = 1; // CWP_SKIPDISABLED = 2; // CWP_SKIPTRANSPARENT = 4; // SMTO_ABORTIFHUNG = 2; SM_SWAPBUTTON = 23; MB_OK = $00000000; MB_SETFOREGROUND = $00010000; SW_SHOWNORMAL = 1; CF_TEXT = 1; CF_UNICODETEXT = 13; GMEM_MOVEABLE = 2; GMEM_ZEROINIT = $40; GMEM_SHARE = $2000; GHND = GMEM_MOVEABLE or GMEM_ZEROINIT; MAXDWORD = DWORD($FFFFFFFF); // FILE_ATTRIBUTE_DIRECTORY = $00000010; INVALID_HANDLE_VALUE = DWORD(-1); GENERIC_READ = DWORD($80000000); GENERIC_WRITE = $40000000; FILE_SHARE_READ = $00000001; FILE_SHARE_WRITE = $00000002; CREATE_ALWAYS = 2; OPEN_EXISTING = 3; FILE_ATTRIBUTE_NORMAL = $00000080; SEM_FAILCRITICALERRORS = 1; VK_LBUTTON = 1; VK_RBUTTON = 2; VK_SHIFT = $10; VK_CONTROL = 17; // VK_MENU = 18; VK_ESCAPE = 27; VK_PRIOR = 33; VK_NEXT = 34; VK_LEFT = 37; VK_UP = 38; VK_RIGHT = 39; VK_DOWN = 40; VK_F1 = 112; // VK_F4 = 115; // VK_F5 = 116; // VK_F10 = 121; const gdi32 = 'gdi32.dll'; kernel32 = 'kernel32.dll'; user32 = 'user32.dll'; function AppendMenuA(hMenu: HMENU; uFlags, uIDNewItem: UINT; lpNewItem: PAnsiChar): BOOL; stdcall; external user32; function CreateFileA(lpFileName: PAnsiChar; dwDesiredAccess, dwShareMode: DWORD; lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD; hTemplateFile: THandle): THandle; stdcall; external kernel32; function CreateWindowExA(dwExStyle: DWORD; lpClassName: PAnsiChar; lpWindowName: PAnsiChar; dwStyle: DWORD; X, Y, nWidth, nHeight: Integer; hWndParent: HWND; hMenu: HMENU; hInstance: HINST; lpParam: Pointer): HWND; stdcall; external user32; function DefWindowProcA(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; external user32; function DispatchMessageA(const lpMsg: TMsg): Longint; stdcall; external user32; //function GetClassNameW(hWnd: HWND; lpClassName: PWideChar; nMaxCount: Integer): Integer; stdcall; external user32; //function GetCommandLineW: PWideChar; stdcall; external kernel32; //function GetFileAttributesW(lpFileName: PWideChar): DWORD; stdcall; external kernel32; function GetMessageA(var lpMsg: TMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax: UINT): BOOL; stdcall; external user32 //function GetSystemDirectoryW(lpBuffer: PWideChar; uSize: UINT): UINT; stdcall; external kernel32; function GetTextExtentPoint32A(DC: HDC; Str: PAnsiChar; Count: Integer; var Size: TSize): BOOL; stdcall; external gdi32; function InsertMenuItemA(p1: HMENU; p2: UINT; p3: BOOL; const p4: TMenuItemInfoA): BOOL; stdcall; external user32; function LoadCursorA(hInstance: HINST; lpCursorName: PAnsiChar): HCURSOR; stdcall; external user32; function LoadIconA(hInstance: HINST; lpIconName: PAnsiChar): HICON; stdcall; external user32; //function LoadLibraryW(lpLibFileName: PWideChar): HMODULE; stdcall; external kernel32; function lstrcpyA(lpString1, lpString2: PAnsiChar): PAnsiChar; stdcall; external kernel32; //function lstrcpyW(lpString1, lpString2: PWideChar): PWideChar; stdcall; external kernel32; function MessageBoxA(hWnd: HWND; lpText, lpCaption: PAnsiChar; uType: UINT): Integer; stdcall; external user32; function RegisterClassA(const lpWndClass: TWndClassA): ATOM; stdcall; external user32; function SendMessageA(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; external user32; //function SendMessageTimeoutW(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM; fuFlags, uTimeout: UINT; var lpdwResult: DWORD): LRESULT; stdcall; external user32; function TextOutA(DC: HDC; X, Y: Integer; Str: PAnsiChar; Count: Integer): BOOL; stdcall; external gdi32; function BeginPaint(hWnd: HWND; var lpPaint: TPaintStruct): HDC; stdcall; external user32; function BitBlt(DestDC: HDC; X, Y, Width, Height: Integer; SrcDC: HDC; XSrc, YSrc: Integer; Rop: DWORD): BOOL; stdcall; external gdi32; function CheckMenuItem(hMenu: HMENU; uIDCheckItem, uCheck: UINT): DWORD; stdcall; external user32; //function ChildWindowFromPointEx(hWnd: HWND; Point: TPoint; Flags: UINT): HWND; stdcall; external user32; function CloseClipboard: BOOL; stdcall; external user32; function CloseHandle(hObject: THandle): BOOL; stdcall; external kernel32; function CombineRgn(p1, p2, p3: HRGN; p4: Integer): Integer; stdcall; external gdi32; function CreateCompatibleBitmap(DC: HDC; Width, Height: Integer): HBITMAP; stdcall; external gdi32; function CreateCompatibleDC(DC: HDC): HDC; stdcall; external gdi32; function CreatePen(Style, Width: Integer; Color: COLORREF): HPEN; stdcall; external gdi32; function CreatePopupMenu: HMENU; stdcall; external user32; function CreateRectRgnIndirect(const p1: TRect): HRGN; stdcall; external gdi32; function DeleteDC(DC: HDC): BOOL; stdcall; external gdi32; //function DeleteMenu(hMenu: HMENU; uPosition, uFlags: UINT): BOOL; stdcall; external user32; function DeleteObject(p1: HGDIOBJ): BOOL; stdcall; external gdi32; function DestroyMenu(hMenu: HMENU): BOOL; stdcall; external user32; function DestroyWindow(hWnd: HWND): BOOL; stdcall; external user32; function DrawMenuBar(hWnd: HWND): BOOL; stdcall; external user32; function EndPaint(hWnd: HWND; const lpPaint: TPaintStruct): BOOL; stdcall; external user32; function EmptyClipboard: BOOL; stdcall; external user32; //function EnumChildWindows(hWndParent: HWND; lpEnumFunc: TFNWndEnumProc; lParam: LPARAM): BOOL; stdcall; external user32; function FillRect(hDC: HDC; const lprc: TRect; hbr: HBRUSH): Integer; stdcall; external user32; //function FreeLibrary(hLibModule: HMODULE): BOOL; stdcall; external kernel32; //function GetAncestor(hwnd: HWND; gaFlags: UINT): HWND; stdcall; external user32; function GetAsyncKeyState(vKey: Integer): SHORT; stdcall; external user32; function GetClientRect(hWnd: HWND; var lpRect: TRect): BOOL; stdcall; external user32; function GetCursorPos(var lpPoint: TPoint): BOOL; stdcall; external user32; procedure mouse_event(dwFlags, dx, dy, dwData, dwExtraInfo: DWORD); stdcall; external user32; function GetDC(hWnd: HWND): HDC; stdcall; external user32; //function GetFileSize(hFile: THandle; lpFileSizeHigh: Pointer): DWORD; stdcall; external kernel32; function GetMenuItemCount(hMenu: HMENU): Integer; stdcall; external user32; function GetMenuItemID(hMenu: HMENU; nPos: Integer): UINT; stdcall; external user32; function GetMenuState(hMenu: HMENU; uId, uFlags: UINT): UINT; stdcall; external user32; function GetPixel(DC: HDC; X, Y: Integer): COLORREF; stdcall; external gdi32; //function GetProcAddress(hModule: HMODULE; lpProcName: LPCSTR): FARPROC; stdcall; external kernel32; function GetStockObject(Index: Integer): HGDIOBJ; stdcall; external gdi32; function GetSysColor(nIndex: Integer): DWORD; stdcall; external user32; function GetSystemMetrics(nIndex: Integer): Integer; stdcall; external user32; //function GetSystemMenu(hWnd: HWND; bRevert: BOOL): HMENU; stdcall; external user32; function GetTickCount: DWORD; stdcall; external kernel32; function GetWindowRect(hWnd: HWND; var lpRect: TRect): BOOL; stdcall; external user32; function GlobalAlloc(uFlags: UINT; dwBytes: DWORD): HGLOBAL; stdcall; external kernel32; function GlobalLock(hMem: HGLOBAL): Pointer; stdcall; external kernel32; function GlobalUnlock(hMem: HGLOBAL): BOOL; stdcall; external kernel32; function IntersectRect(var lprcDst: TRect; const lprcSrc1, lprcSrc2: TRect): BOOL; stdcall; external user32; function InvalidateRect(hWnd: HWND; lpRect: PRect; bErase: BOOL): BOOL; stdcall; external user32; //function IsWindowVisible(hWnd: HWND): BOOL; stdcall; external user32; function KillTimer(hWnd: HWND; uIDEvent: UINT): BOOL; stdcall; external user32; function LineTo(DC: HDC; X, Y: Integer): BOOL; stdcall; external gdi32; function LocalFree(hMem: HLOCAL): HLOCAL; stdcall; external kernel32; function MoveToEx(DC: HDC; p2, p3: Integer; p4: PPoint): BOOL; stdcall; external gdi32; function OffsetRgn(RGN: HRGN; XOffset, YOffset: Integer): Integer; stdcall; external gdi32; function OpenClipboard(hWndNewOwner: HWND): BOOL; stdcall; external user32; procedure PostQuitMessage(nExitCode: Integer); stdcall; external user32; function PtInRect(const lprc: TRect; pt: TPoint): BOOL; stdcall; external user32; function PtInRegion(RGN: HRGN; X, Y: Integer): BOOL; stdcall; external gdi32; function ReadFile(hFile: THandle; var Buffer; nNumberOfBytesToRead: DWORD; var lpNumberOfBytesRead: DWORD; lpOverlapped: POverlapped): BOOL; stdcall; external kernel32; function RectInRegion(RGN: HRGN; const Rect: TRect): BOOL; stdcall; external gdi32; function ReleaseCapture: BOOL; stdcall; external user32; function ReleaseDC(hWnd: HWND; hDC: HDC): Integer; stdcall; external user32; function ScreenToClient(hWnd: HWND; var lpPoint: TPoint): BOOL; stdcall; external user32; function SelectObject(DC: HDC; p2: HGDIOBJ): HGDIOBJ; stdcall; external gdi32; function SetBkColor(DC: HDC; Color: COLORREF): COLORREF; stdcall; external gdi32; function SetCapture(hWnd: HWND): HWND; stdcall; external user32; function SetClipboardData(uFormat: UINT; hMem: THandle): THandle; stdcall; external user32; function SetCursor(hCursor: HICON): HCURSOR; stdcall; external user32; function SetCursorPos(X, Y: Integer): BOOL; stdcall; external user32; function SetErrorMode(uMode: UINT): UINT; stdcall; external kernel32; function SetRect(var lprc: TRect; xLeft, yTop, xRight, yBottom: Integer): BOOL; stdcall; external user32; function SetROP2(DC: HDC; p2: Integer): Integer; stdcall; external gdi32; function SetTextColor(DC: HDC; Color: COLORREF): COLORREF; stdcall; external gdi32; function SetTimer(hWnd: HWND; nIDEvent, uElapse: UINT; lpTimerFunc: TFNTimerProc): UINT; stdcall; external user32; function SetWindowPos(hWnd: HWND; hWndInsertAfter: HWND; X, Y, cx, cy: Integer; uFlags: UINT): BOOL; stdcall; external user32; function StretchBlt(DestDC: HDC; X, Y, Width, Height: Integer; SrcDC: HDC; XSrc, YSrc, SrcWidth, SrcHeight: Integer; Rop: DWORD): BOOL; stdcall; external gdi32; function TrackPopupMenu(hMenu: HMENU; uFlags: UINT; x, y, nReserved: Integer; hWnd: HWND; prcRect: PRect): BOOL; stdcall; external user32; //function TranslateMessage(const lpMsg: TMsg): BOOL; stdcall; external user32; function UnionRect(var lprcDst: TRect; const lprcSrc1, lprcSrc2: TRect): BOOL; stdcall; external user32; //function WindowFromPoint(Point: TPoint): HWND; stdcall; external user32; function WriteFile(hFile: THandle; const Buffer; nNumberOfBytesToWrite: DWORD; var lpNumberOfBytesWritten: DWORD; lpOverlapped: POverlapped): BOOL; stdcall; external kernel32; //--- ShellAPI.pas ------------------------------------------------------------- const shell32 = 'shell32.dll'; //function CommandLineToArgvW(lpCmdLine: LPCWSTR; var pNumArgs: Integer): PPWideChar; stdcall; external shell32; function ShellExecuteA(hWnd: HWND; Operation, FileName, Parameters, Directory: PAnsiChar; ShowCmd: Integer): HINST; stdcall; external shell32; //--- Messages.pas ------------------------------------------------------------- type TMessage = packed record Msg: Cardinal; case Integer of 0: ( WParam: Longint; LParam: Longint; Result: Longint); 1: ( WParamLo: Word; WParamHi: Word; LParamLo: Word; LParamHi: Word; ResultLo: Word; ResultHi: Word); end; TWMMouse = packed record Msg: Cardinal; Keys: Longint; case Integer of 0: ( XPos: Smallint; YPos: Smallint); 1: ( Pos: TSmallPoint; Result: Longint); end; TWMMouseWheel = packed record Msg: Cardinal; Keys: SmallInt; WheelDelta: SmallInt; case Integer of 0: ( XPos: Smallint; YPos: Smallint); 1: ( Pos: TSmallPoint; Result: Longint); end; const WM_SYSCOMMAND = $0112; WM_PAINT = $000F; WM_ERASEBKGND = $0014; WM_LBUTTONDOWN = $0201; WM_LBUTTONUP = $0202; WM_MOUSEMOVE = $0200; WM_MOUSEWHEEL = $020A; WM_CONTEXTMENU = $007B; WM_COMMAND = $0111; WM_SIZE = $0005; WM_TIMER = $0113; WM_DESTROY = $0002; // WM_GETTEXT = $000D; // WM_GETTEXTLENGTH = $000E; // WM_SYSKEYDOWN = $0104; WM_KEYDOWN = $0100; WM_KEYUP = $0101; // WM_DISPLAYCHANGE = $007E; //--- MultiMon.pas ------------------------------------------------------------- type TMonitorInfoW = record cbSize : DWORD; rcMonitor : TRect; rcWork : TRect; dwFlags : DWORD; end; PMonitorInfoW = ^TMonitorInfoW; TMonitorEnumProc = function(hm: HMONITOR; dc: HDC; r: PRect; l: LPARAM): Boolean; stdcall; const SM_XVIRTUALSCREEN = 76; SM_YVIRTUALSCREEN = 77; SM_CXVIRTUALSCREEN = 78; SM_CYVIRTUALSCREEN = 79; const MONITOR_DEFAULTTONEAREST = $2; function GetMonitorInfoW(hMonitor: HMONITOR; lpMonitorInfo: PMonitorInfoW): Boolean; stdcall; external user32; function EnumDisplayMonitors(hdc: HDC; lprcIntersect: PRect; lpfnEnumProc: TMonitorEnumProc; lData: LPARAM): Boolean; stdcall; external user32; function MonitorFromRect(lprcScreenCoords: PRect; dwFlags: DWORD): HMONITOR; stdcall; external user32; //------------------------------------------------------------------------------ type TMyBounds = record Left, Top, Width, Height : Integer; end; function AllocMem(Size: Cardinal): Pointer; function gfnsIntTo10Str(iValue : Integer) : AnsiString; function gfnsIntTo16Str(iValue : Integer) : AnsiString; procedure gpcAddMenuRadio(hMenu: HMENU; sCaption: AnsiString; iItemID: UINT; bCheck: Boolean = False); function gfnbIsMenuChecked (hMenu : HMENU; iItemID : UINT) : Boolean; procedure gpcSetMenuCheck (hMenu : HMENU; iItemID : UINT ; bCheck : Boolean); procedure gpcSetMenuCheckInvert(hMenu : HMENU; iItemID : UINT); //myWindow.pas //function gfnbKeyState(iKey: Integer): Boolean; function gfnptMousePosGet: TPoint; function gfnbSetCursorPos(X, Y: Integer): Boolean; //myNum.pas function gfniRound(fNum: Extended): Int64; function gfniRoundUp(fNum: Extended): Int64; function gfniNumLimit(iNum: Integer; iMin, iMax: Integer): Integer; //最大値・最小値 //function gfniMax(iNum : array of Integer) : Integer; //function gfniMin(iNum : array of Integer) : Integer; //mySize.pas //function Bounds(iLeft, iTop, iWidth, iHeight : Integer) : TMyBounds; //function Rect(Left, Top, Right, Bottom: Integer): TRect; //function Point(X, Y: Integer): TPoint; function gfniRectWidth (rtRect: TRect): Integer; function gfniRectHeight(rtRect: TRect): Integer; //myFile.pas //function gfnhOpenFile(sFile : AnsiString; bWrite : Boolean) : THandle; //function gfnsFilePathGet(sFile: WideString): WideString; //function gfnsIniFileNameGet(sExt : AnsiString) : AnsiString; //myClipbrd.pas procedure gpcStrToClipboard(sStr: AnsiString); var G_hMainHandle : HWND; //============================================================================== implementation {$IFDEF _DEBUG} uses myDebug; {$ENDIF} function LoadLibraryA(lpLibFileName: PAnsiChar): HMODULE; stdcall; external kernel32; function GetProcAddress(hModule: HMODULE; lpProcName: LPCSTR): FARPROC; stdcall; external kernel32; function FreeLibrary(hLibModule: HMODULE): BOOL; stdcall; external kernel32; var F_hUser32Module : HMODULE; SetPhysicalCursorPos : function(X, Y: Integer): BOOL; stdcall; // F_hKernel32Module : HMODULE; GetPhysicalCursorPos : function(var lpPoint: TPoint): BOOL; stdcall; function AllocMem(Size: Cardinal): Pointer; begin GetMem(Result, Size); FillChar(Result^, Size, 0); end; function gfnsIntTo10Str(iValue : Integer) : AnsiString; const lcs_NUM = '0123456789'; lci_DIV = 10; var lb_Minus : Boolean; begin Result := ''; lb_Minus := (iValue < 0); iValue := Abs(iValue); repeat Result := lcs_NUM[(iValue mod lci_DIV) +1] + Result; iValue := iValue div lci_DIV; until (iValue = 0); if (lb_Minus) then begin Result := '-' + Result; end; end; function gfnsIntTo16Str(iValue : Integer) : AnsiString; const lcs_NUM = '0123456789abcdef'; lci_DIV = 16; lci_WIDTH = 6; var ls_Text : AnsiString; li_Len : Integer; begin repeat ls_Text := lcs_NUM[(iValue mod lci_DIV) +1] + ls_Text; iValue := iValue div lci_DIV; until (iValue = 0); li_Len := Length(ls_Text); if (li_Len < lci_WIDTH) then begin SetLength(Result, lci_WIDTH); FillChar(PAnsiChar(Result)[0], lci_WIDTH, '0'); lstrcpyA(@PAnsiChar(Result)[lci_WIDTH - li_Len], PAnsiChar(ls_Text)); end else begin Result := ls_Text; end; end; //my_menu.pas ------------------------------------------------------------------ procedure gpcInsMenuRadio(hMenu: HMENU; sCaption: AnsiString; iItemID: UINT; bCheck: Boolean = False; iIndex: UINT = 0); var l_Info: TMenuItemInfoA; begin FillChar(l_Info, SizeOf(l_Info), 0); l_Info.cbSize := SizeOf(l_Info); l_Info.fMask := MIIM_ID or MIIM_STATE or MIIM_FTYPE or MIIM_STRING; l_Info.fType := MFT_STRING or MFT_RADIOCHECK; if (bCheck) then begin l_Info.fState := MFS_CHECKED; end; l_Info.wID := iItemID; l_Info.dwTypeData := PAnsiChar(sCaption); l_Info.cch := Length(sCaption); InsertMenuItemA(hMenu, iIndex, True, l_Info); end; procedure gpcAddMenuRadio(hMenu: HMENU; sCaption: AnsiString; iItemID: UINT; bCheck: Boolean = False); {2011-01-01: } begin gpcInsMenuRadio(hMenu, sCaption, iItemID, bCheck, GetMenuItemCount(hMenu)); end; function gfnbIsMenuChecked(hMenu : HMENU; iItemID : UINT) : Boolean; begin Result := (GetMenuState(hMenu, iItemID, MF_BYCOMMAND) and MF_CHECKED) = MF_CHECKED; end; procedure gpcSetMenuCheck(hMenu: HMENU; iItemID: UINT; bCheck: Boolean); begin if (bCheck) then begin CheckMenuItem(hMenu, iItemID, MF_BYCOMMAND or MF_CHECKED); end else begin CheckMenuItem(hMenu, iItemID, MF_BYCOMMAND or MF_UNCHECKED); end; DrawMenuBar(hMenu); end; procedure gpcSetMenuCheckInvert(hMenu: HMENU; iItemID: UINT); begin gpcSetMenuCheck(hMenu, iItemID, not(gfnbIsMenuChecked(hMenu, iItemID))); end; //myWindow.pas ----------------------------------------------------------------- { function gfnbKeyState(iKey: Integer): Boolean; begin Result := BOOL(GetAsyncKeyState(iKey)); end; } function gfnptMousePosGet: TPoint; begin // mouse_event({MOUSEEVENTF_MOVE}$0001, 0, 0, 0, 0); //高DPI環境で物理座標を得るため // GetCursorPos(Result); if (@GetPhysicalCursorPos = nil) then begin GetCursorPos(Result); end else begin GetPhysicalCursorPos(Result); end; end; function gfnbSetCursorPos(X, Y: Integer): Boolean; begin if (@SetPhysicalCursorPos = nil) then begin Result := SetCursorPos(X, Y); end else begin Result := SetPhysicalCursorPos(X, Y); end; end; //myNum.pas -------------------------------------------------------------------- function gfniRound(fNum: Extended): Int64; {2007-06-09: fNumを四捨五入して返す Delphiのヘルプからコピー } begin if (fNum >= 0) then begin Result := Trunc(fNum + 0.5); end else begin Result := Trunc(fNum - 0.5); end; end; function gfniRoundUp(fNum: Extended): Int64; //fNumを切り上げて返す begin Result := Trunc(fNum); if Frac(fNum) > 0 then Inc(Result); end; function gfniNumLimit(iNum: Integer; iMin, iMax: Integer): Integer; begin if (iMin = iMax) then begin Result := iMin; end else begin if (iNum < iMin) then begin Result := iMin; end else if (iNum > iMax) then begin Result := iMax; end else begin Result := iNum; end; end; end; (* function gfniMax(iNum: array of Integer): Integer; {2007-08-27: 引数の中の最大値を返す } var i: Integer; begin Result := iNum[0]; for i := 1 to High(iNum) do begin if (iNum[i] > Result) then Result := iNum[i]; end; end; function gfniMin(iNum: array of Integer): Integer; {2007-12-16: 引数の中の最小値を返す } var i: Integer; begin Result := iNum[0]; for i := 1 to High(iNum) do begin if (iNum[i] < Result) then Result := iNum[i]; end; end; *) //mySize.pas ------------------------------------------------------------------- { function Bounds(iLeft, iTop, iWidth, iHeight : Integer) : TMyBounds; begin Result.Left := iLeft; Result.Top := iTop; Result.Width := iWidth; Result.Height := iHeight; end; } { function Rect(Left, Top, Right, Bottom: Integer): TRect; begin Result.Left := Left; Result.Top := Top; Result.Bottom := Bottom; Result.Right := Right; end; } { function Point(X, Y: Integer): TPoint; begin Result.X := X; Result.Y := Y; end; } function gfniRectWidth(rtRect: TRect): Integer; {2007-06-09: rtRectの幅を返す } begin with rtRect do begin Result := Right - Left; end; end; function gfniRectHeight(rtRect: TRect): Integer; {2007-06-09: rtRectの高さを返す } begin with rtRect do begin Result := Bottom - Top; end; end; //myFile.pas ------------------------------------------------------------------- (* function gfnhOpenFile(sFile : AnsiString; bWrite : Boolean) : THandle; var iAccessMode : DWORD; iShareMode : DWORD; //共有モード iCreate : DWORD; //作成方法 begin if (bWrite) then begin iAccessMode := GENERIC_WRITE; iShareMode := 0; iCreate := CREATE_ALWAYS; end else begin iAccessMode := GENERIC_READ; iShareMode := FILE_SHARE_READ or FILE_SHARE_WRITE; iCreate := OPEN_EXISTING; end; Result := CreateFileA( PAnsiChar(sFile), //ファイル名 iAccessMode, //アクセスモード iShareMode, //共有モード nil, //セキュリティ iCreate, //作成方法 FILE_ATTRIBUTE_NORMAL, //ファイル属性 0 //テンプレート ); end; *) (* function gfnsFilePathGet(sFile: WideString): WideString; {2007-07-27,10-26: Unicode対応ExtractFilePath。 ドライブ名も含む。 末尾の'\'はつく。 ドライブ名のみの場合も'\'はつく。 ただしパスが空文字の場合のみ'\'はつかない。 2007-10-26:パスが空文字の場合'\'をつけないことにした。 } var i: Integer; begin Result := ''; if (sFile <> '') then begin for i := Length(sFile) downto 1 do begin if (sFile[i] = '\') or (sFile[i] = '/') then begin Result := Copy(sFile, 1, i); Break; end else if (sFile[i] = ':') then begin Result := Copy(sFile, 1, i) + '\'; Break; end; end; end; end; *) //myClipbrd.pas ---------------------------------------------------------------- procedure gpcStrToClipboard(sStr: AnsiString); var lh_Mem : THandle; lp_Data : Pointer; begin if (sStr <> '') then begin if (OpenClipboard(G_hMainHandle)) then begin try EmptyClipboard; //CF_TEXT lh_Mem := GlobalAlloc(GHND or GMEM_SHARE, Length(sStr) +1); lp_Data := GlobalLock(lh_Mem); lstrcpyA(lp_Data, PAnsiChar(sStr)); GlobalUnlock(lh_Mem); SetClipboardData(CF_TEXT, lh_Mem); finally CloseClipboard; end; end; end; end; //------------------------------------------------------------------------------ initialization F_hUser32Module := LoadLibraryA(user32); if (F_hUser32Module <> 0) then begin // SetPhysicalCursorPos の関数ポインタを取得 @SetPhysicalCursorPos := GetProcAddress(F_hUser32Module, 'SetPhysicalCursorPos'); // GetPhysicalCursorPos の関数ポインタを取得 @GetPhysicalCursorPos := GetProcAddress(F_hUser32Module, 'GetPhysicalCursorPos'); end else begin SetPhysicalCursorPos := nil; GetPhysicalCursorPos := nil; end; finalization FreeLibrary(F_hUser32Module); end.