Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Windows.Forms;
- using System.Threading;
- // ...
- [DllImport( "user32.dll" )]
- public static extern IntPtr GetForegroundWindow();
- class Win32Window:IWin32Window
- { public IntPtr Handle
- { get
- { return handle; }
- }
- private IntPtr handle;
- public Win32Window(IntPtr wndHandle)
- { handle = wndHandle; }
- }
- private string fullFileName = "";
- private void showDialog()
- { IntPtr b1WindowHandle = GetForegroundWindow();
- Win32Window b1Window = new Win32Window(b1WindowHandle);
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Title = "Test";
- ofd.InitialDirectory = "";
- ofd.Filter = "Any file|*.*";
- if ( ofd.ShowDialog( b1Window ) == DialogResult.OK ) // Returns immediately
- //if ( ofd.ShowDialog() == DialogResult.OK ) // Works
- { fullFileName = ofd.FileName; }
- }
- private bool OnMenu(MenuEvent me) // Call this in a menu event handler
- { string msg;
- Thread dlgThread = new Thread(showDialog);
- dlgThread.SetApartmentState(ApartmentState.STA);
- dlgThread.Start();
- dlgThread.Join();
- // Ui.App below is a SAPbouiCOM.Application:
- if (fullFileName == "")
- { msg = "No file has been selected."; }
- else
- { msg = "Selected file is: " + fullFileName; }
- Ui.App.MessageBox(msg, 1, "", "", "");
- return false; // this is for BubbleEvent;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement