vc++ MFC Project - visual-c++

In Vc++ 6.0 mscomm control,please any body explain this function How it works ,what it does
if (m_comm.GetCommEvent()==2 )
{
VARIANT in_dat;
in_dat = m_comm.GetInput();
CString strInput(in_dat.bstrVal);
m_input = m_input + strInput;
UpdateData(FALSE);
}

The code checks whether a comm event occured. If it did, then the input data is obtained from the control and appended to m_input. Afterwards, the data is updated.
The code does not offer much more insight.

Just in case you don't know, "the data is updated" in HS' post means 'the dialog box fields are updated to show the new data'

Related

Parsing Formula in Report Mail Settings

I'm trying to show an email pop up window with an attached report. I want the email fields in the popup window to be populated with the attached report's mail settings - similar to what happens when you click the "Send" button when running the report directly. I'm trying to do this in a PXAction method.
I've got it mostly done but, I'm having a problem if the Mail Settings have a formula in them. For instance if the Subject is set to "=[table].[field]" I get "=[table].[field]" in the Subject box for my email popup window instead of the value of table.field.
Any ideas on how to get the values of the Mail Settings fields in the report instead of the verbatim text?
TIA!
Here's what worked for me. I'm sure there's a way to dispense with the code that removes the "=" but, this got what I needed.
protected string GleanMailSetting(Report report, ReportNode reportNode, string settingText)
{
if ((string.IsNullOrEmpty(settingText)) || (!settingText.StartsWith("=")))
return settingText;
string trimmedText = settingText.TrimStart(new char[] { '=' });
PX.Common.Parser.ExpressionNode node = Reports.Parser.ReportExprParser.Parse(trimmedText, report);
node.Bind(report.DataSource);
return (string)node.Eval(reportNode.DataItem);
}

Why DoModal() on object of CFileDialog crashes on second call?

happens only if I have filter whose string is loaded from an resource ID.
e.g.
CString szFilter;
szFilter.LoadString(IDC_ALLFILES);
where IDC_ALLFILES = "All files (*.*)|*.*||"
when I try to do DoModal() on same instance of CFileDialaog, it crashes on second time.
I have created a small sample project to simulate the exact behavior.
First thing I have done is declared a CFileDialog pointer as follows:
class CFeatureDialogFileDlg : public CDialog
{
private:
CFileDialog* m_pFileDialog;
}
I have two buttons 'Set Flags' and 'Open features' as follows:
void CFeatureDialogFileDlg::OnBnClickedButtonSetFlags()
{
static CString szFilter;
szFilter.LoadStringW(IDC_ALLFILES);
m_pFileDialog = new CFileDialog(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR,szFilter);
}
void CFeatureDialogFileDlg::OnBnClickedButtonOpenFeatures()
{
if(m_pFileDialog->DoModal() == IDOK){}
}
Now,
I just click 'Set Flags' to create a new object on heap.
then I click on 'Open Features' to call DoModal().
First time it gets called properly.
But second time when I click 'Open Features' without clicking on 'Set Flags', I get an error dialog "Debug Assertion Failed in file C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc\dlgfile.cpp"
if I click 'ignore' I get "Encountered an improper argument" dialog.
Thank you all for your replies.
I have recognized the cause of the problem.
In mfc 9, two extra parameters were introduced i.e. dwSize and bVistaStyle for CFileDialog.
Because of bVistaStyle = TRUE, we call new Vista style dialog box and multiple calls to CFileDialog::DoModal for the same instance of a CFileDialog generates ASSERT.
Below line gives E_UNEXPECTED on second time call to DoModal()
HRESULT hr;
hr = (static_cast(m_pIFileDialog))->SetFileTypes(nFilterCount, pFilter);
from file dlgfile.cpp which is at location C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc
Explanation can be found on https://msdn.microsoft.com/da-dk/library/dk77e5e7(v=vs.90).aspx in Note section.
Possible solutions are:
Use Old style dialog box by changing the default parameter bVistaStyle = FALSE
Create a new dialog each time and delete it.
We can not call DoModal() multile times if bVistaStyle = TRUE

Testing excel with Winappdriver

Where can i find a good example of testing an excel addin project with custom ribbon elements, using winappdriver.
What i have so far throws an exception:
System.InvalidOperationException
An element could not be located on the page using the given search parameters.
I am using latest winappdriver
Code:
private const string ExcelAppId = #"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.EXE";
private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", ExcelAppId);
appCapabilities.SetCapability("deviceName", "WindowsPC");
appCapabilities.SetCapability("platformName", "Windows");
session = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appCapabilities);
session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
session.FindElementByName("Blank workbook").Click();
I'm working on automated testing of an Excel add-in with WinAppDriver.
In my case I started Excel without the splash screen. Supply /e as app parameter to achieve it.
session.SetCapability("appArguments", "/e");
From this point onward, you'll be able to find the "File" menu and "New" menu by name and click them.
Add a few seconds of explicit wait and proceed to finding "Blank Workbook" WindowsElement the same way.
I hope this answers your question, post here if more help is needed.
I've been experimenting with WinAppDriver for a few months now, also preparing a Udemy course on the subject which is almost ready to publish. It's an interesting toolkit.
You need to install Appium.WebDriver, Selenium.support, Selenium.webDriver from "Manage Nuget packages"
you can use appium code like:
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
class Excel
{
public void ExcelCase() {
WindowsDriver<WindowsElement> driver;
AppiumOptions desiredcap = new AppiumOptions();
desiredcap.AddAdditionalCapability("app", #"C:\Program Files\Microsoft Office\Office16\EXCEL.EXE");
driver = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), desiredcap);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
if (driver == null)
{
Console.WriteLine("App not running");
return;
}
}}
Try this code and comment if you face any issue.
I prefer to use: session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); instead of Thread.sleep(5).
Does it even open the excel when you start the test?
If by Name is not working, it doens't work to me sometimes either, you can use the accessibilityId
session.FindElementByAccessibilityId("AIOStartDocument").Click();
or use the keyboard shorcut to open the blank workbook, like this:
session.Keyboard.SendKeys(Keys.Alt + "f" + "l" + Keys.Alt);

Microsoft Outlook Address book's title is not displayed properly

I'm developing an application from which I want to send EMail. When I click button/menu Outlook Sendmail window displays properly.
When I open Address Book, the dialog displays properly but the title of the dialog dispalys only "S".
Actually that title has to be displayed as " Selected Names: ... ".
Code:
HWND hWnd = this->GetSafeHwnd();
MAPIINIT_0 tMapInit = { 0, MAPI_MULTITHREAD_NOTIFICATIONS };
HRESULT hResult = MAPIInitialize( &tMapInit );
HMODULE hMapiMod = LoadLibrary(_T("mapi32.dll"));
ProcMapiLogon = (LPMAPILOGON)GetProcAddress( hMapiMod, "MAPILogon" );
(ProcMapiLogon)( (ULONG)hWnd, NULL, NULL, MAPI_LOGON_UI | MAPI_NEW_SESSION, 0, &hCurrentSession );
LPMAPISENDMAIL ProcMapiSendMail = NULL;
ProcMapiSendMail = (LPMAPISENDMAIL)GetProcAddress(hMapiMod, "MAPISendMail");
(ProcMapiSendMail)(hCurrentSession, (ULONG)hWnd, &myMsg, MAPI_DIALOG | MAPI_LOGON_UI, 0);
Note: This applicaion is build in command prompt with unicode flag _UNICODE set and the compiler is Visual Studio 2008.
Kindly help me to fix the problem.
Thanks in Advance.
Simple MAPI functions only work with ANSI strings. Also keep in mind that it is never a good idea to rely on conditional compile when interfacing with Simple or Extended MAPI. Always specify the string flavor (ANSI vs wide string) explicitly in your code.

Adding content control throws an exception dynamically

I am fairly new to Word Addin development. Fortunately I was able to do almost everything but stuck at some simple issue I belive.
I want to insert plain text controls dynamically at the selected range. For this I am using the following:
currentDocument = application.ActiveDocument;
foreach(var field in myFieldsList)
{
Microsoft.Office.Interop.Word.Range rng = currentDocument.ActiveWindow.Selection.Range;
object oRng = rng;
var contentControlPlain = application.ActiveDocument.ContentControls.Add(Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlText, ref oRng);
contentControlPlain.Tag = formField.FormFieldId.ToString();
contentControlPlain.SetPlaceholderText(null, null, " <" + formField.FormFieldName + "> ");
contentControlPlain.LockContentControl = (formField.TypeName.Trim() == "Blank");
}
Code seems to be working fine but when I try to insert the second field it complains saying:
This method or property is not available because the current selection partially covers a plain text content control.
I understand that addin is trying to insert next content control into the previously inserted plain text control. But I tried giving some other range and could not fix it.
Any help is greatly appreciated.
Thanks.
After adding every content control use
Application.Selection.Start = lastControl.Range.End+1

Resources