Extact the cursor position and how to set the cursorpos

1 Juli, 2007

Title: Extact the cursor position and how to set the cursorpos
Author: DAMIAN CIPOLAT
E-mail: Damian_Cipolat@hotmail.com

//extract the cursor position.

procedure TForm1.Button1Click(Sender: TObject);
var
pt:tpoint;
begin
getcursorpos(pt);
showmessage(‘The cursor pos. is: x=’+inttostr(pt.x)+’ y=’+inttostr(pt.y);
end;

//SET the cursor position.
// with this code you can move the windows mouse cursor with code to  x,y position.

procedure TForm1.Button1Click(Sender: TObject);
var
pt:tpoint;
begin
pt.x:=15;
pt.y:=98;
setcursorpos(pt.x,pt.y);
showmessage(‘The cursor pos. is: x=’+inttostr(pt.x)+’ y=’+inttostr(pt.y);
end;

sumber : http://www.delphitricks.com/


Membuka Internet Explorer dengan OLE

1 Juli, 2007

uses comobj;

procedure OpenIE(aURL: string);
var
IE:        Variant;
WinHanlde: HWnd;
begin
if (VarIsEmpty(IE)) then
begin
IE         := CreateOleObject(‘InternetExplorer.Application’);
IE.Visible := True;
IE.Navigate(aURL);
end
else
begin
WinHanlde := FindWindow(‘IEFrame’, nil);
if (0 <> WinHanlde) then
begin
IE.Navigate(aURL);
SetForegroundWindow(WinHanlde);
end
else
ShowMessage(‘Can”t open IE !’);
end;
end;

sumber : http://www.delphitricks.com/


Check if Word, Excel, Access, Outlook, Powerpoint is running

1 Juli, 2007

uses
ComObj, ActiveX;

function IsObjectActive(ClassName: string): Boolean;
var
ClassID: TCLSID;
Unknown: IUnknown;
begin
try
ClassID := ProgIDToClassID(ClassName);
Result  := GetActiveObject(ClassID, nil, Unknown) = S_OK;
except
Result := False;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if IsObjectActive(‘Word.Application’) then ShowMessage(‘Word is running !’);
if IsObjectActive(‘Excel.Application’) then ShowMessage(‘Excel is running !’);
if IsObjectActive(‘Outlook.Application’) then ShowMessage(‘Outlook is running !’);
if IsObjectActive(‘Access.Application’) then ShowMessage(‘Access is running !’);
if IsObjectActive(‘Powerpoint.Application’) then ShowMessage(‘Powerpoint is running !’);
end;

sumber : http://www.delphitricks.com/


Send an e-mail through Outlook

1 Juli, 2007

uses
ComObj;

procedure TForm1.Button16Click(Sender: TObject);
const
olMailItem = 0;
olByValue = 1;
var
OutlookApp, MailItem, MyAttachments: OLEVariant;
begin
try
OutlookApp := GetActiveOleObject(‘Outlook.Application’);
except
OutlookApp := CreateOleObject(‘Outlook.Application’);
end;
try
MailItem := OutlookApp.CreateItem(olMailItem);
MailItem.Recipients.Add(‘YourMailAddress@something.com’);
MailItem.Subject := ‘Your Subject’;
MailItem.Body := ‘Your Message’;
myAttachments := MailItem.Attachments;
myAttachments.Add(‘C:\text.txt’, olByValue, 1, ‘Name of Attachment’);
MailItem.Send;
finally
myAttachments := VarNull;
OutlookApp := VarNull;
end;
end;

sumber : http://www.delphitricks.com/


Register a OCX File

1 Juli, 2007

uses
OLECtl;
var
OCXHandle: THandle;
RegFunc: TDllRegisterServer;
begin
OCXHandle := LoadLibrary (‘C:\Windows\System\custom.ocx’);
RegFunc := GetProcAddress (OCXHandle, ‘DllRegisterServer’);
if RegFunc <> 0 then
ShowMessage(‘Error!’);
FreeLibrary (OCXHandle);
end;

sumber : http://www.delphitricks.com/


Kontrol mIRC dengan DDE

1 Juli, 2007

uses
DdeMan;

procedure mIRCDDE(Service, Topic, Cmd: string);
var
DDE: TDDEClientConv;
begin
try
DDE := TDDEClientConv.Create(nil);
DDE.SetLink(Service, Topic);
DDE.OpenLink;
DDE.PokeData(Topic, PChar(Cmd));
finally
DDE.Free;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
mIRCDDE(‘mIRC’, ‘COMMAND’, ‘/msg #DelphiTricks Hello programmers!’);
end;

Sumber : http://www.delphitricks.com/