Click here to Skip to main content
Click here to Skip to main content
Alternative Article

Closing Microsoft Dynamics GP Report Destination window (alternative)

, 15 Aug 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Paul Maxan
Software Developer (Senior) Cogsdale
Canada Canada
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 15 Aug 2014
Article Copyright 2014 by Paul Maxan
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid