I developed 2 MFC/SDI programs using VC++6.0.
One program is a graphics editor and the other
program is a text editor (the graphics editor launches
the text editor). I would like to close the text editor
when I close the graphics editor.
CWnd* pWnd = FindWindow(NULL,_T("Text Editor"));
if (pWnd== NULL)
AfxMessageBox("Program NOT FOUND!!");
else
pWnd->PostMessage(WM_USER_ON_CLOSE_TEDITOR,0,0l);
The problem is the window title of the text editor is always different
ie. "Text Editor - MyFile.txt", "Text Editor - Letter1.doc",....As such,
the text editor program is never "found", because the window title is not
an exact match.
Is there away to specify, in the FindWindow() function, to use partial
matching
(I know "Text Editor" will always be in the title)?
TIA,
Jacques
Regards,
Nish [Visual C++ MVP]
"Jacques Cooper" <jco...@jcsoftware.net> wrote in message
news:On$p0wucCHA.2324@tkmsftngp08...
You can avoid this problem entirely by using the first parameter instead
of the second parameter in FindWindow. Each window has a windows class
name, which is a string (unrelated to C++ class names). You would need
to customize the winclass name of the target program's main window. To
do that register a unique name (make one up) in InitInstance by calling
AfxRegisterClass, then in PrecreateWindow of the mainframe feed your
winclass name to the cs.lpszClass parameter.
--
Scott McPhillips [VC++ MVP]
Best regards,
yhhuang
VS.NET, Visual C++
Microsoft
This posting is provided "AS IS" with no warranties, and confers no rights.
Got .Net? http://www.gotdotnet.com
Tanks again,
Jacques
///////////////////////////
//PROGRAM 1:
BOOL CMyApp::InitInstance()
{
// Register your unique class name that you wish to use
WNDCLASS wndcls;
memset(&wndcls, NULL, sizeof(WNDCLASS)); // start with NULL
// Specify your own class name for using FindWindow later
wndcls.lpszClassName = _T("MyTextEditorClass");
// Register the new class and exit if it fails
if(!AfxRegisterClass(&wndcls))
{
TRACE("Class Registration Failed\n");
return FALSE;
}
[...]
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.lpszClass = _T("MyTextEditorClass");
[...]
return true;
}
//////////////////////////////////////////////////////////////
//PROGRAM 2:
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
CWnd* pWnd = FindWindow( _T("MyTextEditorClass"), NULL);
if (pWnd != NULL) pWnd->PostMessage(WM_CLOSE);
[...]
CFrameWnd::OnClose();
}
Regards,
Nish [Visual C++ MVP]
"Jacques Cooper" <jco...@jcsoftware.net> wrote in message
news:O9Ly0dycCHA.1992@tkmsftngp11...