AutoIt with wpf - wpf

I have below sample code for my wpf app.
I need to fill in text fields of form with strings.
Run('AutoItWpfTesting.exe')
WinWaitActive("Window1", "")
$hHwnd = WinGetHandle("Window1")
MsgBox(0, "Message", $hHwnd)
$returnVal1=ControlGetHandle ( "$hHwnd", "", "[NAME:txtVersion]")
$returnVal2=ControlSend($hHwnd,"","[NAME:txtVersion]","blahblah")
MsgBox(0, "Message", $returnVal2)
it returns 0 for $returnVal2 and Empty string for $returnValue1.
However this works fine for my sample winform application.
Any clues why this behaviour is..and Any tweaks available to get exact text-box to auto fill data for wpfa app.

WPF applications do not use Windows' controls and handles for the controls. You can see that by using Spy++. WPF Alternatives for Spy++
If you want to automate WPF applications you will need another tool or use the UI Automation API to build one.

Related

Refresh the UI of Windows Form

I'm working on an old project that supports Windows Forms.
This project contains some ResourceManager for the support of a few localizations. The idea is that you call ResourceManager["SomeResource"] instead of Resource.SomeResource and it returns you a localized string.
And these localized strings are used in the code of the initialization of the form. For example, you have Form1, and in Form1.Design.cs there is some code like this:
Label label1 = new Label();
label1.Text = ResourceManager["SomeResource"];
So the label will be created with an already localized string in the Text.
And we need to add the functionality of changing the UI language without reloading the Form.
We can just set the every Text property of every controls again. But it's a lot of code, the form contains a lot of controls.
We can call the Form.InitializeComponents(), this method will recreate all controls with new localized strings, but in some cases, it works slowly because it reloads some big data again.
Is there some other way to refresh all UI controls and get the new localized strings? Do Windows Forms support some mechanism like Binding in the WPF to create the "connection" between the Text properties and localized resources?
I think that you can achieve this by use of Invalidate() either on the form itself or on a container control that your other controls may be encompassed by.

vb.net - Can I load a wpf form into a canvas/grid control?

I trying to see if its possible to load a form into a canvas or grid control in wpf with vb.net.
I'm not very familiar with WPF at all, usually working with Winforms more than anything else, however I need to take advantage of the far superior transparancy options offered by WPF for this current project, so need to see if I can crack this.
In Winforms, I'd normally have a panel (call it contentpanel or mainpanel etc) and then whenever I needed to I could easily load another form into that panel dynamically and keep everything neat and tidy in one form when presented to the user, so something like...
dim newforminstance as form1
newforminstance.toplevel = true
newforminstance.topmost = false
contentpanel.controls.add(newforminstance)
newforminstance.show
That works a treat in Winforms; Is there a similar way to achieve this functionality in WPF?
Thanks in advance.

Print MigraDoc document from WPF app

I use PdfSharp/MigraDoc to create and view documents in an application.
I use the WPF version since I need the WPF documentviewer. Now I'd like to print the documents (which works from the DocumentViewer), but for some reason I only get empty pages when I try printing myself.
I use this code to print:
MigraDocPrintDocument printDocument = new MigraDocPrintDocument();
printDocument.Renderer = new DocumentRenderer(druck.GetDruck());
printDocument.Renderer.PrepareDocument();
printDocument.Print();
What do I need to do to print from WPF (from WinForms this worked nicely, but I need WPF for the DocumentViewer).
This is a known bug of MigraDoc 1.31: printing only works if you use the GDI+ build.
As a workaround you can try to use both versions - WPF build for the preview, GDI+ build for direct printing.

Generating output in a Windows Form App

I am working on a windows form app like most development it is usually useful to see output. I am wondering what methods you use to see output in a windows form app.
PS. I am new to visual studio in general.
You can set some Labels around and display text on them:
Label.Text = "Some Text";
And DataGridView controls for information from tables, and for a better insight, you can set breakpoints in your code by clicking the far-left part of your code editing area. When the program reaches to that point it'll stop and you can hover your variables and objects for a better view of their insides...
Oh, and also VS has a "Locals" window when you run your project, that shows all the objects and variables being used and some information about them.
the user interface (a grid or other
controls on a form)
a report (like Crystal)
a file (.txt)
a database table updated

Key strokes in wpf window hosted in MFC ActiveX running in Internet Explorer

We have an MFC ActiveX control created in Visual Studio 2008 with CLR support which creates a WPF grid and shows a WPF window within that grid.
This ActiveX is hosted within Internet Explorer and it shows up and works nicely except that the tab key, backspace, function keys etc. does not work since they are handeled by IE instead of the WPF window. Regular characters works nicely. This is a known feature and previously when we used to have MFC based dialogs within this ActiveX we used this: http://support.microsoft.com/kb/187988. By just using this code directly the
AfxGetApp()->PreTranslateMessage((LPMSG)lParam)
statement will return FALSE, so I'm not able to get the key stroke to be handled by the WPF window. I beleive I need to ask the WPF application this instead of the CWinApp, but I'm not sure how and if this can be done. Does anyone have enough understanding of what's going on here to get this to work?
Using XBAP instead of ActiveX is not an option as this is run in an intranet application which needs more access than the sandbox can give us.
I hope this is enough information.
With best regards
Svein Dybvik
We have hosted a WPF user control inside an MFC modeless dialog. In order to get some keyboard stuff working correctly, we had to modify the dialogs PreTranslateMessage() function.
Basically, what we did was to check to see if the message was for the WPF window. If it was, we immediately call TranslateMessage/DispatchMessage and then return TRUE from PreTranslateMessage.
Our WPF control fills the entire dialog, so you'd have to have your own conditional check where we have the IsChild test.
BOOL CHostDlg::PreTranslateMessage(MSG* pMsg)
{
// normal PreTranslateMessage() causes the edit fields not to work
if (::IsChild(GetSafeHwnd(), pMsg->hwnd))
{
TranslateMessage(pMsg);
DispatchMessage(pMsg);
return TRUE;
}
return baseclass::PreTranslateMessage(pMsg);
}
Some edit:
BOOL CHostDlg::PreTranslateMessage(MSG* pMsg)
{
// normal PreTranslateMessage() causes the edit fields not to work
if (::IsChild(GetSafeHwnd(), pMsg->hwnd))
{
TranslateMessage(pMsg);
DispatchMessage(pMsg);
pMsg->hwnd = GetSafeHwnd(); // redirect to parent
}
return baseclass::PreTranslateMessage(pMsg);
}

Resources