?? myfun.pas
字號:
Result := GetWindow(Result, GW_CHILD);
SetLength(S, 40);
GetClassName(Result, PChar(S), 39);
if PChar(S) <> 'SysListView32' then Result := 0;
end;
//______________________________________________________________________________
{----------------TIconHintX------------------}
{ 重載ActivateHint,調整輸出字符長度 }
{--------------------------------------------}
procedure TIconHintX.ActivateHint(Rect: TRect; const AHint: string);
type
TAnimationStyle = (atSlideNeg, atSlidePos, atBlend);
const
AnimationStyle: array[TAnimationStyle] of Integer = (AW_VER_NEGATIVE,
AW_VER_POSITIVE, AW_BLEND);
var
Animate: BOOL;
Style: TAnimationStyle;
pos:Tpoint;
begin
GetCursorPos(Pos);
FActivating := True;
try
Caption :=' '+AHint; (*前面價2個空格讓圖標可以正常顯示*)
Inc(Rect.right,12);
Inc(Rect.Bottom,4);
UpdateBoundsRect(Rect);
if Rect.Top + Height > Screen.DesktopHeight then
Rect.Top := Screen.DesktopHeight - Height;
if Rect.Left + Width > Screen.DesktopWidth then
Rect.Left := Screen.DesktopWidth - Width;
if Rect.Left < Screen.DesktopLeft then Rect.Left := Screen.DesktopLeft;
if Rect.Bottom < Screen.DesktopTop then Rect.Bottom := Screen.DesktopTop;
SetWindowPos(Handle, HWND_TOPMOST, Rect.Left, Rect.Top, Width, Height,SWP_NOACTIVATE);
if (GetTickCount - FLastActive > 250) and (Length(AHint) < 100) and
Assigned(AnimateWindowProc) then
begin
SystemParametersInfo(SPI_GETTOOLTIPANIMATION, 0, @Animate, 0);
if Animate then
begin
SystemParametersInfo(SPI_GETTOOLTIPFADE, 0, @Animate, 0);
if Animate then
Style := atBlend
else
if Pos.Y > Rect.Top then
Style := atSlideNeg
else
Style := atSlidePos;
AnimateWindowProc(Handle, 100, AnimationStyle[Style] or AW_SLIDE);
end;
end;
ParentWindow := Application.Handle;
ShowWindow(Handle, SW_SHOWNOACTIVATE);
Invalidate;
finally
FLastActive := GetTickCount;
FActivating := False;
end;
end;
//______________________________________________________________________________
{function TIconHintX.CalcHintRect(MaxWidth: Integer; const AHint: string;
AData: Pointer): TRect;
var
Hicon:TBitmap;
begin
Hicon:=TBitmap.Create;
Hicon.LoadFromResourceName(Hinstance,'HICON');
//-----
Result := inherited CalcHintRect(MaxWidth,AHint, AData);
Result.Right := (Length(AHint) * 5) + Hicon.Width*4;
Result.Bottom := (Hicon.Height)+4;
Hicon.Free;
end; }
//______________________________________________________________________________
procedure TIconHintX.Paint;
var
Hicon:TBitmap;
R: TRect;
begin
inherited;
R := ClientRect;
Inc(R.Left, 20);
Inc(R.Top, 2);
//-------
Hicon:=TBitmap.Create;
Hicon.LoadFromResourceName(Hinstance,'HICON');
color:=$00EEFDF2;
Canvas.Draw(1,1,Hicon);
SendMessage(Handle, WM_NCPAINT, 0, 0); //畫提示欄邊框
Hicon.Free;
end;
//______________________________________________________________________________
{-------------------------------}
{ 設置parent窗體的字體 }
{-------------------------------}
procedure TFun.SetParentWinDefFont(Sender:TObject;const defFont: Tfont);
begin
if defFont=nil then
begin;
{設置默認}
TForm(Sender as TComponent).Font.Name:='宋體';
TForm(Sender as TComponent).Font.Size:=9;
TForm(Sender as TComponent).Font.Height:=-12;
TForm(Sender as TComponent).Font.Color:=clblack;
TForm(Sender as TComponent).Font.Charset:=GB2312_CHARSET
end else
(*用戶定義*)
TForm(Sender as TComponent).Font:=defFont
end;
//______________________________________________________________________________
{---------------------------}
{ 計算x的Y次方 }
{---------------------------}
function TFun.Squ(X, Y: integer): integer;
var
i,sum:integer;
begin
sum:=1;
for i:=1 to Y do sum:=sum*X;
result:=sum
end;
{浮點型}
function TFun.Squ(X: Double; Y: integer): Double;
var
i:integer;
dsum:double;
begin
dsum:=1;
for i:=1 to Y do dsum:=dsum*X;
result:=dsum
end;
//______________________________________________________________________________
{-------------------------------------------------------}
{在指定的chart控件上畫1條數直線,并返回mouse所在的index }
{處理鼠標在Chart里移動的過程,在最近的數據點上畫一直線,}
{X表示是鼠標的X坐標位置,iValueIdx是回傳的數據點索引號 }
{chart的index 從0開始的。。要注意 }
{-------------------------------------------------------}
Function TFun.ChartMoveLine(Chart:Tobject;MousePos_X:Integer;LineColor:TColor):integer;
Var
i,x:Integer;
iXPosition,iValueIdx,iValueCount:Integer;
dXValue : Double;
begin
x:=MousePos_X;
iValueIdx:=-1;
iValueCount:=TChart(Chart as TComponent).Series[0].count;
if iValueCount<>0 then
begin
dXValue := TChart(Chart as TComponent).Series[0].XScreenToValue(X);
if dXValue <= TChart(Chart as TComponent).Series[0].XValue[0] then
iValueIdx := 0
else if dXValue >= TChart(Chart as TComponent).Series[0].XValue[iValueCount-1] then
iValueIdx := iValueCount-1
else
for i:=1 to iValueCount-1 do
if (dXValue >= TChart(Chart as TComponent).Series[0].XValue[i-1]) and (dXValue <= TChart(Chart as TComponent).Series[0].XValue[i]) then
begin
if (dXValue-TChart(Chart as TComponent).Series[0].XValue[i-1])<(TChart(Chart as TComponent).Series[0].XValue[i]-dXValue) then
iValueIdx := i-1
else
iValueIdx := i;
break;
end;
dXValue := TChart(Chart as TComponent).Series[0].XValue[iValueIdx];
iXPosition := TChart(Chart as TComponent).BottomAxis.CalcXPosValue(dXValue);
TChart(Chart as TComponent).Repaint;
With TChart(Chart as TComponent).Canvas do
begin
Pen.Width:=1;
Pen.Style:=psSolid;
Pen.Color:=LineColor;
with TChart(Chart as TComponent) do
begin
MoveTo(iXposition,ChartRect.Top);
LineTo(iXPosition,ChartRect.Bottom );
end;//with TChart(Chart as TComponent) do
end;
end;// if iValueCount<>0 then
result:=iValueIdx;//返回mouse所在的chart上的index
end;
//_______________________________________________________________________________
{-------------------------}
{讓程序開機時自動運行 }
{寫注冊表的run }
{-------------------------}
procedure TFun.AutoRunByReg(FileName:string);
var
reg:Tregistry;
fP:string;
begin
if FileName='' then fp:=application.Title;
reg:=TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
if reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',true) then
begin
reg.WriteString(fp,application.exeName);
end;
reg.CloseKey;
reg.Free;
end;
//-------------------------------------------------------------------------------
//刪除regKey===>Autorun
procedure TFun.DelAutoRunByReg(KeyName: string);
var
reg:Tregistry;
sKey:string;
begin
if KeyName='' then sKey:=application.Title;
reg:=TRegistry.Create;
reg.RootKey:=HKEY_LOCAL_MACHINE;
if reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',false) then
begin
reg.DeleteValue(sKey)
end;
reg.CloseKey;
reg.Free;
end;
//______________________________________________________________________________
{------------------------}
{最小化系統所有的窗體 }
{------------------------}
procedure TFun.MinWinAll;
var
h:HWnd;
begin
h:=application.Handle;
while h > 0 do
begin
if isWindowVisible(h) then
postmessage(h,WM_SYSCOMMAND,SC_MINIMIZE,0);
h:=getnextwindow(h,GW_HWNDNEXT);
end;
end;
//______________________________________________________________________________
{---------------------}
{ 關閉所有窗體 }
{---------------------}
procedure TFun.CloseWinAll;
var
h:HWnd;
begin
h:=application.Handle;
while h > 0 do
begin
if isWindowVisible(h) and (H<>application.Handle)
and (H<>FindWindow('Progman', nil))
then postmessage(h,WM_Close,0,0);
h:=getnextwindow(h,GW_HWNDNEXT);
end;
end;
//_______________________________________________________________________________
{----------------------}
{給窗體加個邊框 }
{----------------------}
procedure TFun.DrawWindowRect(handle: Thandle;wColor:Tcolor;PenWidth:integer);
var
dc : hDc;
Pen : hPen;
OldPen : hPen;
OldBrush : hBrush;
WinR:TwinRect;
begin
GetWinRect(handle,WinR);
dc := GetWindowDC(Handle);
Pen := CreatePen(PS_SOLID,PenWidth,wColor);
OldPen := SelectObject(dc,Pen);
OldBrush := SelectObject(dc, GetStockObject(NULL_BRUSH));
Rectangle(dc, 0,0, WinR.Width, WinR.Height);
SelectObject(dc, OldBrush);
SelectObject(dc, OldPen);
DeleteObject(Pen);
ReleaseDC(Handle,0);
end;
//_______________________________________________________________________________
{----------------------------------------------------}
{ InI文件操作函數集 }
{可利用fun1.GetAppPath('mytest.ini')得到完整的ini目錄}
{----------------------------------------------------}
{------------read Integer------------}
function TFun.ReadIniFile(const FileName, Section, Ident: string;
Default: integer): integer;
begin
myIniFile:=TiniFile.Create(FileName);
result:=myIniFile.ReadInteger(Section,Ident,Default);
myIniFile.FreeInstance;
end;
{------------read string------------}
function TFun.ReadIniFile(const FileName, Section, Ident: string;
Default: string): string;
begin
myIniFile:=TiniFile.Create(FileName);
result:=myIniFile.ReadString(Section,Ident,Default);
myIniFile.FreeInstance;
end;
{------------read Boolean------------}
function TFun.ReadIniFile(const FileName, Section, Ident: string;
Default: Boolean): Boolean;
begin
myIniFile:=TiniFile.Create(FileName);
result:=myIniFile.ReadBool(Section,Ident,Default);
myIniFile.FreeInstance;
end;
{------------read Double------------}
function TFun.ReadIniFile(const FileName, Section, Ident: string;
Default: Double): Double;
begin
myIniFile:=TiniFile.Create(FileName);
result:=myIniFile.ReadFloat(Section,Ident,Default);
myIniFile.FreeInstance;
end;
{------------read DateTime-----------}
function TFun.ReadIniFile(const FileName, Section, Ident: string;
Default: TdateTime): TdateTime;
begin
myIniFile:=TiniFile.Create(FileName);
result:=myIniFile.ReadDateTime(Section,Ident,Default);
myIniFile.FreeInstance;
end;
//_________________________________________________________________________________
{------------Write Integer------------}
procedure TFun.WriteIniFile(const FileName, Section, Ident: string;
Value: integer);
begin
myIniFile:=TiniFile.Create(FileName);
myIniFile.WriteInteger(Section,Ident,Value);
myIniFile.FreeInstance;
end;
{------------Write String------------}
procedure TFun.WriteIniFile(const FileName, Section, Ident: string;
Value: string);
begin
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -