I need to know how can I write a Code to Select B_Form from My Current
application by FindWindow() and FindWindowEx()
:-) Thx , please guide me
I realy approciate @};-
To reliably be able to locate the window, you need to name the
main form class something unique, like TCompanyNameProgramName
instead of TForm1 (or B_Form).
Or, you need to make sure that the Application::Title is
unique. However, if it's an MDI application, the Application
Title will change if there is an open MDIChild form so I never
use this method unless I have no choice.
Once you find a HANDLE to the application, you need to
enumerate the child windows to get HANDLE(s) to the other
controls in the window (form) to interact with them.
HANDLE hTheHandleOfTheAppYouWant = NULL;
// define other HANDLE(s) that you want.
//-------------------------------------------------------------
BOOL CALLBACK EnumWindowsCallBack( HWND hWnd, LPARAM lParam )
{
char WindowClassName[256] = {0};
if( ::GetClassName(hWnd, WindowClassName, 255) )
{
if( stricmp(WindowClassName, (char*)lParam) == 0)
{
hTheHandleOfTheAppYouWant = hWnd;
// stop enuming
return FALSE;
}
}
return TRUE;
}
//-------------------------------------------------------------
BOOL CALLBACK EnumChildCallBack( HWND hWnd, LPARAM lParam )
{
// we're looking for the second instance of "Static"
char WindowClassName[256] = {0};
if( ::GetClassName(hWnd, WindowClassName, 255) )
{
if( stricmp(WindowClassName, (char*)lParam) == 0 )
{
++DlgCtrlCounter;
if( DlgCtrlCounter == 2 )
{
DlgCtrlHWND = hWnd;
// stop Enuming
return FALSE;
}
}
}
return TRUE;
}
//-------------------------------------------------------------
AnsiString WindowClassName = "TCompanyNameProgramName";
::EnumWindows( (WNDENUMPROC)EnumWindowsCallBack, (LPARAM)WindowClassName.c_str() );
if( hTheHandleOfTheAppYouWant )
{
WindowClassName = "Static";
::EnumChildWindows( hWnd, (WNDENUMPROC)EnumChildCallBack, (LPARAM)WindowClassName.c_str() );
}
Now that you have the handles to the controls, what are you
going to do with them? If it's your application, I would
suggest that you just use custom messages that can be sent to
the Application Handle and let it do the work.
~ JD
Assume a TForm named B_Form with a TMainMenu
There is Choice1 and Chioce2 in TMainMenu Items
Also there is a TEdit , TMemo and TButton...
This Project is Compiled , executed and Launched !
I need to know how can I write a Code to Select B_Form from My Current
application by FindWindow() and FindWindowEx()
:-) Thx , please guide me
I realy approciate @};-
there is also a post in attachments with the same subject name , my C++
project that I need help in.