請問如何取得目前focus元件的名稱? |
尚未結案
|
skurama
中階會員 ![]() ![]() ![]() 發表:88 回覆:127 積分:73 註冊:2002-07-22 發送簡訊給我 |
|||
jieshu
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:42 回覆:894 積分:745 註冊:2002-04-15 發送簡訊給我 |
引言: 請問能不能捉到目前Focus的元件名稱 現在面對的問題是我要判斷兩個gird內某一欄位的值 但我必需要知道使用者目前Focus在哪一個Gird 請問有辦法嗎???不曉得BCB有沒有ActiveControl這個公用變數。
------
人生有夢,逐夢而行 人若為善,福雖未至,禍已遠離 人若為惡,禍雖未至,福已遠離 http://www.taconet.com.tw/jieshu/ |
||
Cooky Kid
初階會員 ![]() ![]() 發表:5 回覆:68 積分:44 註冊:2002-07-11 發送簡訊給我 |
若在Form1之中,依照滑鼠移動即取得元件資訊,
那...下面實例應可達成要求。
enjoy it!!! Unit1.h
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ToolWin.hpp>
//---------------------------------------------------------------------------
#include <stdio.h>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TToolBar *ToolBar1;
TButton *Button1;
TStaticText *StaticText1;
TStaticText *StaticText2;
TButton *Button2;
void __fastcall FormShow(TObject *Sender);
void __fastcall FormMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y);
void __fastcall FormDestroy(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif Unit1.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//確定Form1為一般型態
FormStyle = fsNormal;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
//動態創造5個彩色背景的視窗
for(int i=0;i<5;i )
{
TForm *form = new TForm(Form1);
form->Parent = Form1;
form->FormStyle = fsNormal;
form->Name = "form" AnsiString(i 1);
form->Width = 150; form->Height = 40;
form->Top = ToolBar1->Height 40*i;
form->Left = 40*i;
form->Color = (TColor)RGB(255-i*50,i*50,255);
//若在新視窗上移動滑鼠,引發Form1的OnMouseMove事件
form->OnMouseMove = FormMouseMove;
form->Show();
}
//若在其他元件上移動滑鼠,引發Form1的OnMouseMove事件
StaticText1->OnMouseMove = FormMouseMove;
ToolBar1->OnMouseMove = FormMouseMove;
Button1->OnMouseMove = FormMouseMove;
Button2->OnMouseMove = FormMouseMove;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
char name[6];
//刪除程式開始時創造的5個彩色視窗
for(int num=0;num<ComponentCount;num )
{
sprintf(name,"form%i",(num 1));//#include <stdio.h>
for(int i=0;i<ComponentCount;i )
if(Components[i]->Name == name)
{
delete (TForm *)Components[i];
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
//取得滑鼠位置
POINT pd;
GetCursorPos(&pd);
pd = ScreenToClient(pd);
char name[256], text[256];
//由滑鼠位置而取得Form1上物件handle
HWND h = ::ChildWindowFromPoint(Handle, pd);
//由物件handle取得物件相關資訊
::GetClassName(h,name,256);
::GetWindowText(h,text,256);
//即時顯示物件資訊
StaticText2->Caption = "類別:" AnsiString(name)
",內含文字:" AnsiString(text);
}
//---------------------------------------------------------------------------
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |