12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.Windows.Forms;
- namespace Cbdx.Tests.Services
- {
- internal class WindowControlService : IWindowControlService
- {
- private readonly TestForm _form;
- public WindowControlService(TestForm form)
- {
- _form = form;
- }
- WindowState IWindowControlService.GetWindowState()
- {
- return (WindowState)_form.WindowState;
- }
- void IWindowControlService.SetWindowState(WindowState windowState)
- {
- if (_form.InvokeRequired) _form.Invoke(new Action(() => _form.WindowState = (FormWindowState)windowState));
- else _form.WindowState = (FormWindowState)windowState;
- }
- void IWindowControlService.SetWindowTitle(string title)
- {
- if (_form.InvokeRequired) _form.Invoke(new Action(() => _form.Text = title));
- else _form.Text = title;
- }
- void IWindowControlService.CloseWindow()
- {
- if (_form.InvokeRequired) _form.Invoke(new Action(() => _form.Close()));
- else _form.Close();
- }
- void IWindowControlService.Reload()
- {
- if (_form.InvokeRequired) _form.Invoke(new Action(() => _form.CreateOrReloadCefBrowserControl()));
- else _form.CreateOrReloadCefBrowserControl();
- }
- void IWindowControlService.DragMove()
- {
- if (_form.InvokeRequired)
- {
- _form.Invoke(new Action(() =>
- {
- ReleaseCapture();
- SendMessage(_form.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
- }));
- }
- else
- {
- ReleaseCapture();
- SendMessage(_form.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
- }
- }
- public const int WM_NCLBUTTONDOWN = 0xA1;
- public const int HT_CAPTION = 0x2;
- [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
- public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
- [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
- public static extern bool ReleaseCapture();
- }
- }
|