internal class NativeMethods
{
     [DllImport("user32.dll", CharSet = CharSet.Auto)]
     internal static extern int MessageBox(
         IntPtr windowHandle,
         [param: MarshalAs(UnmanagedType.LPWStr)]
         string message,
         [param: MarshalAs(UnmanagedType.LPWStr)]
         string title,
         uint type);
}
messageBoxResult = NativeMethods.MessageBox(
    (IntPtr)0, 
    text, 
    "Title", 
    (int)(NativeMethods.MB_OK | NativeMethods.MB_ICONINFORMATION | NativeMethods.MB_TOPMOST));
I call the MessageBox twice, the first one does not show up TOPMOST, the second one does show up TOPMOST (after I clicked on the first one). I already tried to set the windowHandle to NULL and add the MB_SETFOREGROUND flag. My application does not have a separate window.
It is always the same window which is in front of the first MessageBox. It is a c# client which communicates with my application. If e.g. Visual Studio is visible the first MessageBox works like intended. My assumption is that the client application somehow has a higher priority than my first MessageBox. Do I need to set the MessageBox to foreground with SetForegroundWindow after showing it?
Any idea why my first MessageBox is hidden behind the application but the second one isn't?