Component aktif değilse visible false olsun (popup gibi)

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
trolojik
Üye
Mesajlar: 78
Kayıt: 01 Nis 2007 02:46

Component aktif değilse visible false olsun (popup gibi)

Mesaj gönderen trolojik »

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
Kullanıcı avatarı
aslangeri
Moderator
Mesajlar: 4322
Kayıt: 26 Ara 2003 04:19
Konum: Ankara
İletişim:

Mesaj gönderen aslangeri »

s.a.
panelin onexit eventini kullanabilirsiniz sanırım.
klolay gelsin.
Duyduğun Şeylerin Söylediklerim Olduğuna Eminim Ama
Anladığın Şeylerin Anlatmak İstediklerim Olduğuna Emin Değilim
Kullanıcı avatarı
fatihtolgaata
Üye
Mesajlar: 382
Kayıt: 04 Mar 2004 09:46
Konum: K.çekmece / İstanbul
İletişim:

Mesaj gönderen fatihtolgaata »

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.

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; 
trolojik
Üye
Mesajlar: 78
Kayıt: 01 Nis 2007 02:46

Mesaj gönderen trolojik »

[Error] Unit1.pas(71): Undeclared identifier: 'HGetMessageHook'


Aklıma takılan 2. bir soru var BU tpanel popup gibi olacak yani içinde buttonlar olacak. Şimdi ben mouse left buttonunu baz alırsam left mouse tıkladığımda panel kapanacak yani visible false olacak . E bu vakit butonu nasıl tıklayacak :)
trolojik
Üye
Mesajlar: 78
Kayıt: 01 Nis 2007 02:46

Mesaj gönderen trolojik »

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

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.

İlginize teşekkürler
trolojik
Üye
Mesajlar: 78
Kayıt: 01 Nis 2007 02:46

Mesaj gönderen trolojik »

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
Kullanıcı avatarı
fatihtolgaata
Üye
Mesajlar: 382
Kayıt: 04 Mar 2004 09:46
Konum: K.çekmece / İstanbul
İletişim:

Mesaj gönderen fatihtolgaata »

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.

Kod: Tümünü seç

.....
if Assigned(FRM2) then
  if Assigned(FRM2.edit2) then
    FRM2.edit2.text:='s';
....
vesselam.
Cevapla