Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repaint issues when switching between programs

Tags:

c++

c#

.net

repaint

MyApp (.NET c#) is triggered by OtherApp (c++).

When triggered my app takes over the whole screen and gives the user two options. One option quits MyApp and returns to the OtherApp home screen. The 2nd option exits the intial screen and shows another screen for user input - after input it exits and returns to the OtherApp.

On occasion the OtherApp screen does not repaint(can only see the background, not buttons) - I can not easily replicate this (when I do it seems like a fluke), but I have seen it on a number of applications.

Is there a way that MyApp can force a screen repaint of OtherApp?

What could be causing this?

CLARIFICATION - OTHER APP IS NOT OURS. Our client uses OtherApp. MyApp is triggered by a filewatcher event. When we see a file, we process it. If this is the file we are looking for we give the user two options. OtherApp does not know MyApp exists.

like image 726
Scottf007 Avatar asked Jul 05 '11 05:07

Scottf007


1 Answers

Try and get the hwnd of OtherApp's main window and invalidate the whole thing:

[DllImport("user32.dll")]
static extern bool InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

static void InvalidateOtherApp()
{
  IntPtr hWnd = FindWindow(null, "OtherApp's Main Window's Title");
  if (hWnd != IntPtr.Zero)
    InvalidateRect(hWnd, IntPtr.Zero, true);
}
like image 128
dkackman Avatar answered Oct 03 '22 18:10

dkackman