Redraw problems when switching between programs

MyApp (.NET C #) is launched using OtherApp (C ++).

When launched, my application captures the entire screen and gives the user two options. One option exits MyApp and returns to the OtherApp main screen. The second option exits the screen and displays another screen for user input - after entering it exits and returns to OtherApp.

In some cases, the OtherApp screen does not redraw (it can only see the background, not the buttons). I cannot easily reproduce this (when I do this, it seems like an accident), but I have seen it in a number of applications.

Is there any way MyApp can force a screen to be redrawn in OtherApp?

What could be the reason for this?

CONFIRMATION - OTHER APPLICATIONS ARE NOT OUR. Our client uses OtherApp. MyApp is triggered by the 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 that MyApp exists.

+7
source share
3 answers

Try to get the hwnd of the OtherApp main window and undo it all:

[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 Main Window Title"); if (hWnd != IntPtr.Zero) InvalidateRect(hWnd, IntPtr.Zero, true); } 
+3
source

In OtherApp, add the equivalent of C ++ Application.DoEvents (). It does not seem to be processing Windows messages. You can do it like this, taken from a sample Microsoft Vterm program:

 void CMainFrame::DoEvents() { MSG msg; // Process existing messages in the application message queue. // When the queue is empty, do clean up and return. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE) && !m_bCancel) { if (!AfxGetThread()->PumpMessage()) return; } } 
+3
source

Since the OtherApp application is not your application, you can modify MyApp and send the message to OtherApp using the Win32 SendMessage function . To do this in C # check out C # Win32 messaging with SendMessage . The message you want to send is WM_PAINT . The site uses a different message, but the idea is the same. Your code will be something like this:

 [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] private static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam); int WM_PAINT = 0xF; SendMessage(hWnd, WM_PAINT, IntPtr.Zero, IntPtr.Zero); 

This will send your message about renaming to the application. You need to put hWnd using the window handle of OtherApp. To get the window handle, you need to call the System.Diagnostics.Process class to find your application and call the MainWindowHandle property to get the handle.

+1
source

All Articles