|
|
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Menus,
ImgList, frmInsert_P, CoolTrayIcon;
type
TfrmMain = class(TForm)
TrayIcon: TCoolTrayIcon;
pmTray: TPopupMenu;
pmExit: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
pmRunStop: TMenuItem;
pmAbout: TMenuItem;
pmHelp: TMenuItem;
imgTemplet: TImage;
imgPokeBmp: TImage;
tmrCheckGameWin: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure TrayIconStartup(Sender: TObject; var ShowMainForm: Boolean);
procedure pmExitClick(Sender: TObject);
procedure tmrCheckGameWinTimer(Sender: TObject);
private
{ Private declarations }
procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
public
procedure InsertPanel;
{ Public declarations }
end;
PokeInfoType = record
PokeSymbol: string;
PokeColor: TColor;
PokeMarks: (King, Spades, Hearts, Clubs, Diamonds);
end;
AllPokeInfoType = array[0..53] of PokeInfoType;
const
AllPokeInfo: AllPokeInfoType = (
(PokeSymbol: '王'; PokeColor: clRed; PokeMarks: King),
(PokeSymbol: '王'; PokeColor: clBlack; PokeMarks: King),
(PokeSymbol: '2'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: '2'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: '2'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: '2'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: 'A'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: 'A'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: 'A'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: 'A'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: 'K'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: 'K'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: 'K'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: 'K'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: 'Q'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: 'Q'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: 'Q'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: 'Q'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: 'J'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: 'J'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: 'J'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: 'J'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: '10'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: '10'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: '10'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: '10'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: '9'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: '9'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: '9'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: '9'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: '8'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: '8'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: '8'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: '8'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: '7'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: '7'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: '7'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: '7'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: '6'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: '6'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: '6'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: '6'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: '5'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: '5'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: '5'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: '5'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: '4'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: '4'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: '4'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: '4'; PokeColor: clRed; PokeMarks: Diamonds),
(PokeSymbol: '3'; PokeColor: clBlack; PokeMarks: Spades),
(PokeSymbol: '3'; PokeColor: clRed; PokeMarks: Hearts),
(PokeSymbol: '3'; PokeColor: clBlack; PokeMarks: Clubs),
(PokeSymbol: '3'; PokeColor: clRed; PokeMarks: Diamonds)
);
var
frmMain: TfrmMain;
frmInsert: TfrmInsertType;
HotKeyID: Integer;
PokeTemplet: array[0..53] of Cardinal;
AlreadyRun: Boolean;
hwndDest: HWND;
RectDest: TRect;
hdcDest: HDC;
BmpCapture: TBitmap;
CanvasCource: TCanvas;
implementation
{$R *.dfm}
procedure TfrmMain.WMHotKey(var Msg: TWMHotKey);
var
pt: TPoint;
begin
if Msg.HotKey = HotKeyID then
begin
GetCursorPos(pt);
hwndDest := WindowFromPoint(pt);
AlreadyRun := True;
InsertPanel;
end;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
var
TempBmp: TBitmap;
I: Integer;
CRC32: Cardinal;
CRCerror: Word;
TotalBytes: TInteger8;
begin
HotKeyID := GlobalAddAtom(PChar('UserDefineHotKey')) - $C000;
RegisterHotKey(Handle, HotKeyID, 0, VK_F2);
TempBmp := TBitmap.Create;
TempBmp.Width := LittlePokeWidth;
TempBmp.Height := LittlePokeHeight;
for I := 0 to 53 do
begin
TempBmp.Canvas.CopyRect(TempBmp.Canvas.ClipRect, imgTemplet.Canvas, Rect(I * 15, 0, I * 15 + 15, 30));
TempBmp.Monochrome := True;
CalcStreamCRC32(TempBmp, CRC32, TotalBytes, CRCerror);
PokeTemplet[I] := CRC32;
end;
end;
procedure TfrmMain.InsertPanel;
begin
hdcDest := GetWindowDC(hwndDest);
BmpCapture := TBitmap.Create;
CanvasCource := TCanvas.Create;
CanvasCource.Handle := hdcDest;
if frmInsert <> nil then
frmInsert.Destroy;
frmInsert := TfrmInsertType.CreateParented(hwndDest);
frmInsert.Left := 0;
frmInsert.Top := 125;
GetWindowRect(hwndDest, RectDest);
frmInsert.Width := RectDest.Right - RectDest.Left;
frmInsert.Height := 137;
frmInsert.Show;
end;
procedure TfrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
UnregisterHotKey(Handle, HotKeyID);
DeleteAtom(HotKeyID);
if frmInsert <> nil then
frmInsert.Destroy;
CanvasCource.Handle := 0;
CanvasCource.Free;
BmpCapture.Free;
ReleaseDC(hwndDest, hdcDest)
end;
procedure TfrmMain.TrayIconStartup(Sender: TObject; var ShowMainForm: Boolean);
begin
ShowMainForm := False;
end;
procedure TfrmMain.pmExitClick(Sender: TObject);
begin
Self.Close;
end;
procedure TfrmMain.tmrCheckGameWinTimer(Sender: TObject);
var
HWndDDZ: HWND;
pt: TPoint;
begin
HWndDDZ := FindWindow(nil, '斗地主');
if (HWndDDZ <> 0) then
begin
if not AlreadyRun then
begin
ShowWindow(HWndDDZ, SW_SHOWMAXIMIZED);
RedrawWindow(0, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_ALLCHILDREN);
pt.X := 10;
pt.Y := 100;
hwndDest := WindowFromPoint(pt);
AlreadyRun := True;
InsertPanel;
end;
end
else
begin
if AlreadyRun then
begin
frmInsert.tmrWatchUpdate.Enabled := False;
frmInsert.tmrWatchCard.Enabled := False;
frmInsert.Close;
end;
AlreadyRun := False;
end;
end;
end.
http://yunpan.cn/QXNGkLPEEXqdt |
|