Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Closing Microsoft Dynamics GP Report Destination window (alternative)

0.00/5 (No votes)
15 Aug 2014 7  
This is an alternative for Closing Microsoft Dynamics GP Report Destination window

Introduction

In this alternative to closing the Report Destination window, we are using polling instead of event notification.

Note

I will only be presenting the deviations from the original. To use the alternative, replace the Closer (file and class) in the original posting with the included Closer2.

Step1: Detecting the Report Destination window

Instead of registering a Windows event hook and wait to be notified when the foreground window has changed, we are running a timer, continuously looking for our Report Destination dialog:

void closerTimer_Elapsed(object sender, ElapsedEventArgs e)
{
    closerTimer.Enabled = false;
    hWndDlg = FindWindow(null, REPORT_DESTINATION_CAPTION);
    if ((int)hWndDlg != 0)
    {
        [...]
    }
    closerTimer.Enabled = true;
}

We identify the dialog based on its caption using the Win32 API FindWindow() function. The Report Destination window does not have to be the topmost window on our screen.

Step2: Closing the report destination window

We must ensure the keyboard input is directed to our dialog when we are sending the keystrokes to close it. As such, before issuing the keystrokes we are always checking if the Report Destination window is the topmost window on our screen. For this purpose we use the Win32 API GetForegroundWindow() function:

if (GetForegroundWindow() == hWndDlg)
{
    System.Windows.Forms.SendKeys.SendWait("{TAB}");
    System.Windows.Forms.SendKeys.SendWait("{ESC}");
}

Conclusion

I do not think that the alternative presented here is any more suitable than the original for our 32-bit Microsoft Dynamics GP Add-in integration library. It may be perhaps a better fit for an out-of-process integration as it alleviates the reentrancy issue of the original. However only the code in the original article was properly tested.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here