So, my aim is when I open an exe file like Word, a button is created automatically
and then when I close the Word app, the button will be removed.
Each app will have its own button when it is launched.
I tried to do it but I have some issues with the closing of the app.
Here is what I did:
- var applicationWord = new Microsoft.Office.Interop.Word.Application();
- applicationWord.Visible = true;
- applicationWord.DocumentBeforeClose += DocumentBeforeClose;
- if (applicationWord.Visible == true)
- {
- button = new Button();
- button.Image = Properties.Resources.word_80;
- PIC_Barre.Controls.Add(button);
- button.AutoSize = true;
- // button.Tag = proc.Id;
- PIC_Barre.Controls.Add(button);
- foreach (Process proc in Process.GetProcessesByName("WINWORD"))
- {
- if (proc.ProcessName.Contains("WINWORD"))
- {
- proc.WaitForInputIdle();
- {
- Thread.Sleep(500);
- SetWindowPos(proc.MainWindowHandle.ToInt32(),
- (int)SetWinPos_ZOrderOpt.HWND_TOPMOST,
- 0, 0, 0, 0,
- (int)(SetWinPosFlags.SWP_NOSIZE |
- SetWinPosFlags.SWP_NOMOVE));
- }
- button.Click += (s, e) => { ShowWindowAsync(proc.MainWindowHandle, (int)ShowWindowCommands.Normal); };
- proc.Exited += (s, e) =>
- {
- var method = (Action)(() => PIC_Barre.Controls.Remove(button));
- // button.Visible = false;
- if (button.InvokeRequired)
- {
- button.Invoke(method);
- }
- };
- }
- }
- }
Esakki MuthuPosted Sep 20, 2016, 2:39 AM
Jim TatPosted Sep 14, 2016, 9:00 AM
Esakki MuthuPosted Sep 14, 2016, 6:56 AM
Jim TatPosted Sep 14, 2016, 6:44 AM
Esakki MuthuPosted Sep 14, 2016, 6:40 AM