Click here to Skip to main content
15,560,218 members
Articles / Desktop Programming / Win32
Posted 15 Aug 2014


3 bookmarked

Closing Microsoft Dynamics GP Report Destination window (alternative)

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
15 Aug 2014CPOL1 min read
This is an alternative for "Closing Microsoft Dynamics GP Report Destination window"


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


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)


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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior) Cogsdale
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

-- There are no messages in this forum --