Merhaba ; Öncelikle herkese kolay gelsin..
TPanel componentini ele alalım. Forma bir adet panel yerleştirdim ve visible özelliğini false yaptım buttona tıklayınca visible true olmadını sağladım. İsteğim şu ki panel harici herhangi bir yeri tıklayınca bu form üzerindede olabilir ekranın herhangi bir yeride olabilir visiblesinin false olmasını istiorum. Tıpkı popup gibi popup açıldıktan sonra nasıl ki başka bir yer tıklarsak popup kapanıyor o misal.
Konu hakkında bilgiye sahip olan arkadaşların konuya müdahil olmasını bekliyorum
İyi çalışmalar
Component aktif değilse visible false olsun (popup gibi)
Forum kuralları
Forum kurallarını okuyup, uyunuz!
Forum kurallarını okuyup, uyunuz!
- fatihtolgaata
- Üye
- Mesajlar: 382
- Kayıt: 04 Mar 2004 09:46
- Konum: K.çekmece / İstanbul
- İletişim:
Eğer gerçekten popup menu gibi davranmasını istiyorsan MessageHook ile yapmalısın. Bunun dışında yaptığın şeyler(OnDeactive, OnExit, vs..) genelde sorun çıkartıyor. Sdk Yardım dosyasından WH_GETMESSAGE mesajına ve SetWindowsHookEx fonksiyonuna bir göz at. Aşağıdaki kod newsgrouptan bulmuştum. Umarım işini görür.
vesselam.
vesselam.
Kod: Tümünü seç
function GetMessageHook(Code, wParam, lParam: Integer): Integer; stdcall;
implementation
function GetMessageHook(Code, wParam, lParam: Integer): Integer; stdcall;
var
M: TMsg;
Msg: Integer;
begin
Result:= 0;
if (Code >= 0)
// and for active application
and Assigned(Application)
and Application.Active
and (not IsIconic(GetActiveWindow))
then begin
// because actial message is packed into the TMsg structure, we should
unpack it
M:= PMsg(lParam)^;
Msg:= PMsg(lParam)^.Message;
// check for mouse messages
if ((Msg >= wm_LButtonDblClk) and (Msg <= wm_MButtonDblClk))
or ((Msg >= wm_NCRButtonDblClk) and (Msg <= wm_NCMButtonDblClk))
or (Msg = wm_LButtonDown)
or (Msg = wm_NCLButtonDown)
or (Msg = wm_NCRButtonDown)
then begin
// here you should check for clicks outside of active form
// and take an appropriate action
Exit;
end;
end;
// in Win32 api stated that this call is optional but I think this
statement
// should be always included
Result:= CallNextHookEx(HGetMessageHook, Code, wParam, lParam);
end;
Hook'u kurmak için:
if HGetMessageHook = 0
then HGetMessageHook:= SetWindowsHookEx(wh_GetMessage, @GetMessageHook, 0,
GetCurrentThreadID);
Hook'u kaldırmak için:
if HGetMessageHook <> 0
then UnhookWindowsHookEx(HGetMessageHook);
HGetMessageHook:= 0;
Tamamdır teşekkür ederim yardımcı oldu gerçekten. Var kısmında bir eksiklik vardı
Bi siteden eksikliği buldum. Siteden aynısını pasteliyorum
İlginize teşekkürler
Bi siteden eksikliği buldum. Siteden aynısını pasteliyorum
Kod: Tümünü seç
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
HGetMessageHook : THandle = 0;
implementation
{$R *.DFM}
function GetMessageHook(Code, wParam, lParam: Integer): Integer; stdcall; var
M: TMsg;
Msg: Integer;
begin
Result:= 0;
if (Code >= 0)
and Assigned(Application)
and Application.Active
and (not IsIconic(GetActiveWindow))
then begin
M:= PMsg(lParam)^;
Msg:= PMsg(lParam)^.Message;
if ((Msg >= wm_LButtonDblClk) and (Msg <= wm_MButtonDblClk))
or ((Msg >= wm_NCRButtonDblClk) and (Msg <= wm_NCMButtonDblClk))
or (Msg = wm_LButtonDown)
or (Msg = wm_NCLButtonDown)
or (Msg = wm_NCRButtonDown)
then begin
Form1.label1.caption := 'hello';
//dont do showmessage cause you wont be able to close the
//message the dialog :-)
Exit;
end;
end;
Result:= CallNextHookEx(HGetMessageHook, Code, wParam, lParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
if HGetMessageHook = 0
then HGetMessageHook:= SetWindowsHookEx(wh_GetMessage, @GetMessageHook, 0, GetCurrentThreadID);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if HGetMessageHook <> 0
then UnhookWindowsHookEx(HGetMessageHook);
HGetMessageHook:= 0;
end;
end.
Enteresan bir konu mevcut.
Konu şu : bi main formum var bide 2. formum
2. Form 20 saniyede bir create ediliyor
FRM2 := TForm2.Create(Application);
Bu şekilde create ediliyor..
fORM2 ye hook kodunu koyduğum zaman
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at adress 004E91EC in module Project1.exe Read of adress 00000344'. Process stopped.Use step or run to continue.
Hatası ile kaşılaşıyorum ve OK butonuna bastıktan sonra hata satırına geçiyor.. Hata veren satır ise şu
or (Msg = wm_NCLButtonDown)
or (Msg = wm_NCRButtonDown)
then begin
FRM2.edit2.text:='s';
//dont do showmessage cause you wont be able to close the
//message the dialog
Exit;
end;
end;
Kodun devamı zaten yukarıda o yüzden bi kısmını pasteledim sadece
Acaba problem ney .. Kolay gelsin
Konu şu : bi main formum var bide 2. formum
2. Form 20 saniyede bir create ediliyor
FRM2 := TForm2.Create(Application);
Bu şekilde create ediliyor..
fORM2 ye hook kodunu koyduğum zaman
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at adress 004E91EC in module Project1.exe Read of adress 00000344'. Process stopped.Use step or run to continue.
Hatası ile kaşılaşıyorum ve OK butonuna bastıktan sonra hata satırına geçiyor.. Hata veren satır ise şu
or (Msg = wm_NCLButtonDown)
or (Msg = wm_NCRButtonDown)
then begin
FRM2.edit2.text:='s';
//dont do showmessage cause you wont be able to close the
//message the dialog

Exit;
end;
end;
Kodun devamı zaten yukarıda o yüzden bi kısmını pasteledim sadece
Acaba problem ney .. Kolay gelsin
- fatihtolgaata
- Üye
- Mesajlar: 382
- Kayıt: 04 Mar 2004 09:46
- Konum: K.çekmece / İstanbul
- İletişim:
Form2 oluşturulmadan ya da edit oluşturulmadan önce onun özelliklerine erişmeye çalışıyorsunuz. Hook'un install hadisesini herhalde form2'nin oluşturulmasından önce gerçekleştiriyorsunuz. Her neyse, hata veren satırda şu şekilde dener misiniz.
vesselam.
Kod: Tümünü seç
.....
if Assigned(FRM2) then
if Assigned(FRM2.edit2) then
FRM2.edit2.text:='s';
....