|
Hi,
I want to get handle of an already opened window.
For this
I can not use FindWindow() API as Window's title is not known.
And also, I can not use Class name as it is not a registered class.
Can anybody tell me how to solve this issue?
Thanks in advance.
Regards
MSR
|
|
|
|
|
As far as I know, every window must belong to a registered class.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi, thanks for the reply.
But here we are not regidtering class explicitly. This is the code
CDlg* pDlg = new CDlg;
DialogBoxParam(hInt, MAKEINTRESOURCE(IDD_DLG),
hWnd, (DLGPROC)(*pDlg ).WindowMapProc, (LPARAM)pDlg);
I have tried using
FindWindow("CDlg", NULL); But it is not working.
Now , how to go forward to find IDD_DLG.
Regards
MSR
|
|
|
|
|
Your windows is child of the hWnd one and as such must be searched for.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Use
EnumWindows
EnumChildWindows
and look for #32778 class name
use the SPY++ to test it
Mithrill
|
|
|
|
|
CDlg is the class which creates the dialog window and must use some Windows classname, either one of the predefined classes, or a new one registered before creation. What is the base of CDlg ?
[edit]It is also likely that the dialog will contain a title that you can search for.[/edit]
|
|
|
|
|
The DialogBoxParam function automatically assigns the predefined class name "#32770" (i.e. dialog box, see here[^]) to the newly created dialog.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I think the OP would like to know this.
|
|
|
|
|
So let he/she know.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi, CDlg is derived from CDlgSlct.
I have tried using the base class also.
But of no use.
Regards
MSR
|
|
|
|
|
And what is CDlgSlct derived from? You should know and understand your inheritance tree. In either case see the message from CPallini which tells you what identifier to use for the Dialog windows class.
|
|
|
|
|
Just to be clear, a C++ class should not be confused with a windows class.
Use Spy++, it will tell you the (windows) class name of any window you care to query. Do this to a dialog, and you'll see the name that cPallini provided - the same class-name that you should use with FindWindow.
To that end, which C++ class you inherit from is somewhat irrelevant. You just need the windows class name for a dialog box.
|
|
|
|
|
Use WindowFromPoint Api if you know approx location in x,y cords
this returns handle
e.g.
[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(POINT Point);
The trick is making sure unknown application starts in a known place.
Regards
David Rathbone
|
|
|
|
|
Not to mention it musn't be covered by any other window...i doubt this method would be reliable.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Hello,
I have a (maybe small) problem that is driving me mad.
I am using a CHtmlView derived class to display a html file that is stored locally on the PC. I'm using Navigate2() for that. On Windows XP machines everything works fine but Windows 7 always opens a new IExplorer window instead of displaying the file in my view. I tried to override OnNewWindow2() but the according event does not occur.
I use the following code in the OnInitialUpdate() function of the view:
CString fileName = theApp.m_sSettingsPath + CString("Certificate\\certificate.htm");
Navigate2(fileName);
I've also tried the "file://" syntax, but same behaviour.
Thank's for your help,
Ralf
|
|
|
|
|
You need to use the extra options (dwFlags and lpszTargetFrameName ) in the Navigate2() [^] call, as described here[^].
|
|
|
|
|
Thanks for your suggestions but I don't get it working.
I've tried with all of the TargetFrameNames ("_self", "_top", "_parent") - no effect.
For the BrowserNavConstants therer are several flags to open the file in a new window, tab ... but no one that prevents a new window explicitly.
Another strange observation: when trying to open a URL (http://www.google.de/) it wont't show the rendered site but the source of the site in notepad.
|
|
|
|
|
Sorry but I cannot suggest anything further if the Microsoft code does not work. Unfortunately I don't have MFC so can't try reproducing the problem.
|
|
|
|
|
Member 8109560 wrote: I've tried with all of the TargetFrameNames ("_self", "_top", "_parent") - no effect
Also tried with your window name, or only the cited predefined strings ?
|
|
|
|
|
How do I get my window name? Is it the one in the title bar?
|
|
|
|
|
Member 8109560 wrote: Is it the one in the title bar
Not necessarily; you can find it out using Spy++, or programmatically with, for instance:Get a handle on your window and use GetWindowText().
|
|
|
|
|
Same behavior when specifying my window as target.
|
|
|
|
|
1) how about Navigate2("http://www.xxx.com"...)?
2) try OnNewWindow3 please.
|
|
|
|
|
Thanks for your help, but still no luck.
Implemented a handler for the NewWindow3 event but it seems that the event is not fired.
Tried with Navigate2("http://www.codeproject.com") but same behaviour (source code shown in notepad).
When trying to open local file it is downloaded to temporary internet files and then opened in IE.
|
|
|
|
|
The behavior sounds like that the Win7 default shell operation not correctly set.
Can you check the registry for the default value of HKEY_CLASSES_ROOT\htmlfile\shell
[HKEY_CLASSES_ROOT\htmlfile\shell]
@="opennew"
or you can try on another Win7 machine?
|
|
|
|