I've successfully created a WPF window with the new Microsoft WebView2 (Edge Chromium based) runtime component on it. This allows me to show me an e-mail without script errors as on the old IE based HTML viewer. However, when I open the window, focus returns to the VO window from where I opened that e-mail.
oDotNet:= OLEAutoObject{"DotNetLibForVO.VoDotNetClass"}
IF !oDotNet:Finit
// .....
ENDIF
IF !oDotNet:ShowEmailInWebView2(cHTML,cCaption)
....
ENDIF
ShowEmailInWebView2 is an X# method which eventually leads to opening a WPF window, from within my DotNet DLL.
I tried adding this code in VO:
hWindow:=FindWindow(NULL_PSZ, String2Psz(cCaption))
SetForegroundWindow(hWindow)
but this leaves me with 1 question: How can I identify the window? In the above code I tried the caption (=the subject of a mail) I pass to the
.Net library and which is displayed in the WPF window, but the window does not get focus when I add these 2 lines.
Dick
How to get focus on WPFwindow started in .Net DLL via VO?
How to get focus on WPFwindow started in .Net DLL via VO?
Dick,
in Xaml you would use
Topmost="True"
in the <Window....> Tag. In code behind this shoul be:
this.Topmost = true
Regards
Meinhard
in Xaml you would use
Topmost="True"
in the <Window....> Tag. In code behind this shoul be:
this.Topmost = true
Regards
Meinhard
How to get focus on WPFwindow started in .Net DLL via VO?
Hi Dick
The simple answer is “I don’t know” but at the risk of again misunderstanding what you’re trying to do this may be worth some thought.
I assume you’ve used an instance of WebView2.
Could you derive a control say WebView2Derived adding in return window identifier and interrogating that?
Terry
The simple answer is “I don’t know” but at the risk of again misunderstanding what you’re trying to do this may be worth some thought.
I assume you’ve used an instance of WebView2.
Could you derive a control say WebView2Derived adding in return window identifier and interrogating that?
Terry
-
- Posts: 248
- Joined: Fri Oct 14, 2016 7:09 am
How to get focus on WPFwindow started in .Net DLL via VO?
Hi Dick,
You can use WindowInteropHelper to set the VO window as the owner of the WPF window, then if you call wpfwindow.Activate() it will bring it to the top.
I expose a method in my WPF COM client class to do this, so it can be called from VO any time you want to bring the WPF window to the top.
Just about to go into a video conference so can't go into more detail at this moment, but we have this working fine.
HTH
Nick
You can use WindowInteropHelper to set the VO window as the owner of the WPF window, then if you call wpfwindow.Activate() it will bring it to the top.
I expose a method in my WPF COM client class to do this, so it can be called from VO any time you want to bring the WPF window to the top.
Just about to go into a video conference so can't go into more detail at this moment, but we have this working fine.
HTH
Nick
How to get focus on WPFwindow started in .Net DLL via VO?
Something like the following:
public class WebViewDerived : WebView2
{
string ReturnWindowIdent;
public WebViewDerived() : base()
{
//Add ReturnWindowIdent ...
}
public string GetWindowIdent()
{
return ReturnWindowIdent;
}
}
Terry
public class WebViewDerived : WebView2
{
string ReturnWindowIdent;
public WebViewDerived() : base()
{
//Add ReturnWindowIdent ...
}
public string GetWindowIdent()
{
return ReturnWindowIdent;
}
}
Terry
How to get focus on WPFwindow started in .Net DLL via VO?
Thanks Meinhard, Terry & Nick for the quick response.
I started "top down" and adding Topmost="True" in the XAML already did what I what wanted, great!
The solutions of Nick & Terry may come in handy in other situations.
Dick
I started "top down" and adding Topmost="True" in the XAML already did what I what wanted, great!
The solutions of Nick & Terry may come in handy in other situations.
Dick
How to get focus on WPFwindow started in .Net DLL via VO?
So, topmost equals hasFocus ? Godness...
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
How to get focus on WPFwindow started in .Net DLL via VO?
One addition: Topmost is called Topmost because it doesn't only get focus but it is also impossible to move another window in front of it, when it's open.
This works to get focus too:
SELF:hHandleToWebView2Win:=FindWindow(NULL_PSZ, String2Psz("WebWindow")) // Use this handle after expose
(where WebWindow it the original name/caption of the WPF window (which I overwrite after creation with the subject of the e-mail). In the Expose of the window, after all other potential "focus takers" came along, I program:
IF SELF:hHandleToWebView2Win<>NULL_PTR
SetForegroundWindow(SELF:hHandleToWebView2Win)
SELF:hHandleToWebView2Win:=NULL_PTR
ENDIF
This works to have this window get focus.
Dick
This works to get focus too:
SELF:hHandleToWebView2Win:=FindWindow(NULL_PSZ, String2Psz("WebWindow")) // Use this handle after expose
(where WebWindow it the original name/caption of the WPF window (which I overwrite after creation with the subject of the e-mail). In the Expose of the window, after all other potential "focus takers" came along, I program:
IF SELF:hHandleToWebView2Win<>NULL_PTR
SetForegroundWindow(SELF:hHandleToWebView2Win)
SELF:hHandleToWebView2Win:=NULL_PTR
ENDIF
This works to have this window get focus.
Dick