HelperTypes.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. using SmartCoalApplication.SystemLayer.FileDlgExtenders.Win32Types;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Runtime.InteropServices;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace SmartCoalApplication.SystemLayer.FileDlgExtenders
  13. {
  14. public partial class FileDialogControlBase
  15. {
  16. #region Helper Classes
  17. private class MSFileDialogWrapper : NativeWindow, IDisposable
  18. {
  19. public const SetWindowPosFlags UFLAGSSIZE =
  20. SetWindowPosFlags.SWP_NOACTIVATE |
  21. SetWindowPosFlags.SWP_NOOWNERZORDER |
  22. SetWindowPosFlags.SWP_NOMOVE;
  23. #region Delegates
  24. #endregion
  25. #region Events
  26. #endregion
  27. #region Variables Declaration
  28. private int _filterIndex;
  29. private FileDialogControlBase _CustomCtrl;
  30. #endregion
  31. #region Constructors
  32. public MSFileDialogWrapper(FileDialogControlBase fd)
  33. {
  34. _CustomCtrl = fd;
  35. if (_CustomCtrl != null)
  36. fd.MSDialog.Disposed += new EventHandler(NativeDialogWrapper_Disposed);
  37. }
  38. void NativeDialogWrapper_Disposed(object sender, EventArgs e)
  39. {
  40. Dispose();
  41. }
  42. #endregion
  43. #region Methods
  44. public void Dispose()
  45. {
  46. if (_CustomCtrl != null)
  47. {
  48. if (_CustomCtrl.MSDialog != null)
  49. {
  50. _CustomCtrl.MSDialog.Disposed -= new EventHandler(NativeDialogWrapper_Disposed);
  51. _CustomCtrl.MSDialog.Dispose();
  52. if (_CustomCtrl != null)
  53. _CustomCtrl.MSDialog = null;
  54. }
  55. if (_CustomCtrl != null)
  56. {
  57. if (!_CustomCtrl.IsDisposed)
  58. _CustomCtrl.Dispose();
  59. _CustomCtrl = null;
  60. }
  61. }
  62. DestroyHandle();
  63. }
  64. #endregion
  65. #region Overrides
  66. protected override void WndProc(ref Message m)
  67. {
  68. switch ((Msg)m.Msg)
  69. {
  70. case Msg.WM_NOTIFY:
  71. OFNOTIFY ofNotify = (OFNOTIFY)Marshal.PtrToStructure(m.LParam, typeof(OFNOTIFY));
  72. switch (ofNotify.hdr.code)
  73. {
  74. case (uint)DialogChangeStatus.CDN_SELCHANGE:
  75. {
  76. StringBuilder filePath = new StringBuilder(256);
  77. Win32Types.NativeMethods.SendMessage(new HandleRef(this, Win32Types.NativeMethods.GetParent(Handle)), (uint)DialogChangeProperties.CDM_GETFILEPATH, (IntPtr)256, filePath);
  78. if (_CustomCtrl != null)
  79. {
  80. _CustomCtrl.OnFileNameChanged(this, filePath.ToString());
  81. }
  82. }
  83. break;
  84. case (uint)DialogChangeStatus.CDN_FOLDERCHANGE:
  85. {
  86. StringBuilder folderPath = new StringBuilder(256);
  87. Win32Types.NativeMethods.SendMessage(new HandleRef(this, Win32Types.NativeMethods.GetParent(Handle)), (int)DialogChangeProperties.CDM_GETFOLDERPATH, (IntPtr)256, folderPath);
  88. if (_CustomCtrl != null)
  89. _CustomCtrl.OnFolderNameChanged(this, folderPath.ToString());
  90. }
  91. break;
  92. case (uint)DialogChangeStatus.CDN_TYPECHANGE:
  93. {
  94. OPENFILENAME ofn = (OPENFILENAME)Marshal.PtrToStructure(ofNotify.OpenFileName, typeof(OPENFILENAME));
  95. int i = ofn.nFilterIndex;
  96. if (_CustomCtrl != null && _filterIndex != i)
  97. {
  98. _filterIndex = i;
  99. _CustomCtrl.OnFilterChanged(this as IWin32Window, i);
  100. }
  101. }
  102. break;
  103. case (uint)DialogChangeStatus.CDN_INITDONE:
  104. break;
  105. case (uint)DialogChangeStatus.CDN_SHAREVIOLATION:
  106. break;
  107. case (uint)DialogChangeStatus.CDN_HELP:
  108. break;
  109. case (uint)DialogChangeStatus.CDN_INCLUDEITEM:
  110. break;
  111. case (uint)DialogChangeStatus.CDN_FILEOK://0xfffffda2:
  112. #pragma warning disable 1690, 0414
  113. //NativeMethods.SetWindowPos(_CustomCtrl._hFileDialogHandle, IntPtr.Zero,
  114. //(int)_CustomCtrl._OpenDialogWindowRect.left,
  115. //(int)_CustomCtrl._OpenDialogWindowRect.top,
  116. //(int)_CustomCtrl._OpenDialogWindowRect.Width,
  117. //(int)_CustomCtrl._OpenDialogWindowRect.Height,
  118. //FileDialogControlBase.MSFileDialogWrapper.UFLAGSSIZE);
  119. break;
  120. #pragma warning restore 1690, 0414
  121. default:
  122. break;
  123. }
  124. break;
  125. case Msg.WM_COMMAND:
  126. switch (Win32Types.NativeMethods.GetDlgCtrlID(m.LParam))//switch (m.WParam & 0x0000ffff)
  127. {
  128. case (int)ControlsId.ButtonOk://OK
  129. break;
  130. case (int)ControlsId.ButtonCancel://Cancel
  131. break;
  132. case (int)ControlsId.ButtonHelp: //0x0000040e://help
  133. break;
  134. }
  135. break;
  136. default:
  137. break;
  138. }
  139. base.WndProc(ref m);
  140. }
  141. #endregion
  142. }
  143. private class WholeDialogWrapper : NativeWindow, IDisposable
  144. {
  145. #region Constants Declaration
  146. private const SetWindowPosFlags UFLAGSSIZEEX =
  147. SetWindowPosFlags.SWP_NOACTIVATE |
  148. SetWindowPosFlags.SWP_NOOWNERZORDER |
  149. SetWindowPosFlags.SWP_NOMOVE |
  150. SetWindowPosFlags.SWP_ASYNCWINDOWPOS |
  151. SetWindowPosFlags.SWP_DEFERERASE;
  152. private const SetWindowPosFlags UFLAGSHIDE =
  153. SetWindowPosFlags.SWP_NOACTIVATE |
  154. SetWindowPosFlags.SWP_NOOWNERZORDER |
  155. SetWindowPosFlags.SWP_NOMOVE |
  156. SetWindowPosFlags.SWP_NOSIZE |
  157. SetWindowPosFlags.SWP_HIDEWINDOW;
  158. private const SetWindowPosFlags UFLAGSZORDER =
  159. SetWindowPosFlags.SWP_NOACTIVATE |
  160. SetWindowPosFlags.SWP_NOMOVE |
  161. SetWindowPosFlags.SWP_NOSIZE;
  162. const uint WS_VISIBLE = 0x10000000;
  163. static readonly IntPtr HWND_MESSAGE = new IntPtr(-3);
  164. static readonly IntPtr NULL = IntPtr.Zero;
  165. #endregion
  166. #region Variables Declaration
  167. IntPtr _hDummyWnd = NULL;
  168. bool mResized;
  169. private FileDialogControlBase _CustomControl = null;
  170. private bool _WatchForActivate = false;
  171. private Size mOriginalSize;
  172. private IntPtr _hFileDialogHandle;
  173. private WINDOWINFO _ListViewInfo;
  174. private MSFileDialogWrapper _BaseDialogNative;
  175. private IntPtr _ComboFolders;
  176. private WINDOWINFO _ComboFoldersInfo;
  177. private IntPtr _hGroupButtons;
  178. private WINDOWINFO _GroupButtonsInfo;
  179. private IntPtr _hComboFileName;
  180. private WINDOWINFO _ComboFileNameInfo;
  181. private IntPtr _hComboExtensions;
  182. private WINDOWINFO _ComboExtensionsInfo;
  183. IntPtr _hOKButton;
  184. WINDOWINFO _OKButtonInfo;
  185. private IntPtr _hCancelButton;
  186. private WINDOWINFO _CancelButtonInfo;
  187. private IntPtr _hHelpButton;
  188. private WINDOWINFO _HelpButtonInfo;
  189. private IntPtr _hToolBarFolders;
  190. private WINDOWINFO _ToolBarFoldersInfo;
  191. private IntPtr _hLabelFileName;
  192. private WINDOWINFO _LabelFileNameInfo;
  193. private IntPtr _hLabelFileType;
  194. private WINDOWINFO _LabelFileTypeInfo;
  195. private IntPtr _hChkReadOnly;
  196. private WINDOWINFO _ChkReadOnlyInfo;
  197. private bool mIsClosing = false;
  198. private bool mInitializated = false;
  199. private RECT _DialogWindowRect = new RECT();
  200. private RECT _DialogClientRect = new RECT();
  201. #endregion
  202. #region Constructors
  203. public WholeDialogWrapper(FileDialogControlBase fileDialogEx)
  204. {
  205. //create the FileDialog & custom control without UI yet
  206. _CustomControl = fileDialogEx;
  207. //_CustomControl.MSDialog = new FDLG();
  208. AssignDummyWindow();
  209. _WatchForActivate = true;
  210. }
  211. #endregion
  212. #region Events
  213. #endregion
  214. #region Methods
  215. private void AssignDummyWindow()
  216. {
  217. //_hDummyWnd = Win32.CreateWindowEx(0x00050100, "Message", null, 0x16C80000, -10000, -10000, 0, 0,
  218. //parent.Handle, NULL, NULL, NULL);
  219. _hDummyWnd = Win32Types.NativeMethods.CreateWindowEx(0, "Message", null, WS_VISIBLE, 0, 0, 0, 0,
  220. HWND_MESSAGE, NULL, NULL, NULL);
  221. if (_hDummyWnd == NULL || !Win32Types.NativeMethods.IsWindow(_hDummyWnd))
  222. throw new ApplicationException("Unable to create a dummy window");
  223. AssignHandle(_hDummyWnd);
  224. }
  225. public void Dispose()
  226. {
  227. if (_CustomControl != null)
  228. {
  229. if (!_CustomControl.IsDisposed)
  230. {
  231. if (_CustomControl.MSDialog != null)
  232. {
  233. _CustomControl.MSDialog.Disposed -= new EventHandler(DialogWrappper_Disposed);
  234. _CustomControl.MSDialog.Dispose();
  235. }
  236. //might have been nulled by MSDialog.Dispose()
  237. if (_CustomControl != null)
  238. {
  239. _CustomControl.MSDialog = null;
  240. _CustomControl.Dispose();
  241. }
  242. _CustomControl = null;
  243. }
  244. }
  245. if (_BaseDialogNative != null)
  246. {
  247. _BaseDialogNative.Dispose();
  248. _BaseDialogNative = null;
  249. }
  250. if (_hDummyWnd != IntPtr.Zero)
  251. {
  252. Win32Types.NativeMethods.DestroyWindow(_hDummyWnd);
  253. DestroyHandle();
  254. _hDummyWnd = IntPtr.Zero;
  255. }
  256. }
  257. #endregion
  258. #region Private Methods
  259. private void PopulateWindowsHandlers()
  260. {
  261. Win32Types.NativeMethods.EnumChildWindows(new HandleRef(this, _hFileDialogHandle), new Win32Types.NativeMethods.EnumWindowsCallBack(FileDialogEnumWindowCallBack), 0);
  262. }
  263. private bool FileDialogEnumWindowCallBack(IntPtr hwnd, int lParam)
  264. {
  265. StringBuilder className = new StringBuilder(256);
  266. Win32Types.NativeMethods.GetClassName(new HandleRef(this, hwnd), className, className.Capacity);
  267. int controlID = Win32Types.NativeMethods.GetDlgCtrlID(hwnd);
  268. WINDOWINFO windowInfo;
  269. Win32Types.NativeMethods.GetWindowInfo(new HandleRef(this, hwnd), out windowInfo);
  270. // Dialog Window
  271. if (className.ToString().StartsWith("#32770"))
  272. {
  273. _BaseDialogNative = new MSFileDialogWrapper(_CustomControl);
  274. _BaseDialogNative.AssignHandle(hwnd);
  275. return true;
  276. }
  277. switch ((ControlsId)controlID)
  278. {
  279. case ControlsId.DefaultView:
  280. _CustomControl._hListViewPtr = hwnd;
  281. Win32Types.NativeMethods.GetWindowInfo(new HandleRef(this, hwnd), out _ListViewInfo);
  282. _CustomControl.UpdateListView();
  283. break;
  284. case ControlsId.ComboFolder:
  285. _ComboFolders = hwnd;
  286. _ComboFoldersInfo = windowInfo;
  287. break;
  288. case ControlsId.ComboFileType:
  289. _hComboExtensions = hwnd;
  290. _ComboExtensionsInfo = windowInfo;
  291. break;
  292. case ControlsId.ComboFileName:
  293. if (className.ToString().ToLower() == "comboboxex32")
  294. {
  295. _hComboFileName = hwnd;
  296. _ComboFileNameInfo = windowInfo;
  297. }
  298. break;
  299. case ControlsId.GroupFolder:
  300. _hGroupButtons = hwnd;
  301. _GroupButtonsInfo = windowInfo;
  302. break;
  303. case ControlsId.LeftToolBar:
  304. _hToolBarFolders = hwnd;
  305. _ToolBarFoldersInfo = windowInfo;
  306. break;
  307. case ControlsId.ButtonOk:
  308. _hOKButton = hwnd;
  309. _OKButtonInfo = windowInfo;
  310. _CustomControl._hOKButton = hwnd;
  311. //Win32Types.NativeMethods.EnableWindow(_hOKButton, false);
  312. break;
  313. case ControlsId.ButtonCancel:
  314. _hCancelButton = hwnd;
  315. _CancelButtonInfo = windowInfo;
  316. break;
  317. case ControlsId.ButtonHelp:
  318. _hHelpButton = hwnd;
  319. _HelpButtonInfo = windowInfo;
  320. break;
  321. case ControlsId.CheckBoxReadOnly:
  322. _hChkReadOnly = hwnd;
  323. _ChkReadOnlyInfo = windowInfo;
  324. break;
  325. case ControlsId.LabelFileName:
  326. _hLabelFileName = hwnd;
  327. _LabelFileNameInfo = windowInfo;
  328. break;
  329. case ControlsId.LabelFileType:
  330. _hLabelFileType = hwnd;
  331. _LabelFileTypeInfo = windowInfo;
  332. break;
  333. }
  334. return true;
  335. }
  336. private void InitControls(int heightChanged)
  337. {
  338. mInitializated = true;
  339. // Lets get information about the current open dialog
  340. Win32Types.NativeMethods.GetClientRect(new HandleRef(this, _hFileDialogHandle), ref _DialogClientRect);
  341. Win32Types.NativeMethods.GetWindowRect(new HandleRef(this, _hFileDialogHandle), ref _DialogWindowRect);
  342. // Lets borrow the Handles from the open dialog control
  343. PopulateWindowsHandlers();
  344. switch (_CustomControl.FileDlgStartLocation)
  345. {
  346. case AddonWindowLocation.Right:
  347. // Now we transfer the control to the open dialog
  348. _CustomControl.Location = new Point((int)(_DialogClientRect.Width - _CustomControl.Width), 0);
  349. break;
  350. case AddonWindowLocation.Bottom:
  351. // Now we transfer the control to the open dialog
  352. _CustomControl.Location = new Point(0, (int)(_DialogClientRect.Height - _CustomControl.Height + heightChanged));
  353. break;
  354. case AddonWindowLocation.BottomRight:
  355. // We don't have to do too much in this case, just the default thing
  356. _CustomControl.Location = new Point((int)(_DialogClientRect.Width - _CustomControl.Width), (int)(_DialogClientRect.Height - _CustomControl.Height));
  357. break;
  358. }
  359. // Everything is ready, now lets change the parent
  360. Win32Types.NativeMethods.SetParent(new HandleRef(_CustomControl, _CustomControl.Handle), new HandleRef(this, _hFileDialogHandle));
  361. // Send the control to the back
  362. // Win32Types.NativeMethods.SetWindowPos(_CustomControl.Handle, (IntPtr)ZOrderPos.HWND_BOTTOM, 0, 0, 0, 0, UFLAGSZORDER);
  363. _CustomControl.MSDialog.Disposed += new EventHandler(DialogWrappper_Disposed);
  364. }
  365. void DialogWrappper_Disposed(object sender, EventArgs e)
  366. {
  367. Dispose();
  368. }
  369. #endregion
  370. #region Overrides
  371. //this is a child window for the whole Dialog
  372. protected override void WndProc(ref Message m)
  373. {
  374. if (m.Msg == 0xa3 && (int)m.WParam == 0x0002)//winform窗体取消最大化双击标题最大化
  375. return;
  376. RECT currentSize = new RECT();
  377. const SetWindowPosFlags flags = SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOMOVE;//| SetWindowPosFlags.SWP_NOREPOSITION | SetWindowPosFlags.SWP_ASYNCWINDOWPOS | SetWindowPosFlags.SWP_SHOWWINDOW | SetWindowPosFlags.SWP_DRAWFRAME;
  378. switch ((Msg)m.Msg)
  379. {
  380. case Msg.WM_SHOWWINDOW:
  381. InitControls(0);
  382. Win32Types.NativeMethods.GetWindowRect(new HandleRef(this, _hFileDialogHandle), ref currentSize);
  383. //restore original sizes
  384. int top = (_CustomControl.Parent == null) ? currentSize.top : _CustomControl.Parent.Top;
  385. int right = (_CustomControl.Parent == null) ? currentSize.right : _CustomControl.Parent.Right;
  386. RECT currentClientSize = new RECT();
  387. Win32Types.NativeMethods.GetClientRect(new HandleRef(this, _hFileDialogHandle), ref currentClientSize);
  388. int dy = (int)(currentSize.Height - currentClientSize.Height);
  389. int dx = (int)(currentSize.Width - currentClientSize.Width);
  390. int Height = 0;
  391. int Width = 0;
  392. switch (_CustomControl.FileDlgStartLocation)
  393. {
  394. case AddonWindowLocation.Bottom:
  395. Width = Math.Max(_CustomControl.OriginalCtrlSize.Width + dx, (int)FileDialogControlBase.OriginalDlgWidth);
  396. Win32Types.NativeMethods.SetWindowPos(_hFileDialogHandle, (IntPtr)ZOrderPos.HWND_BOTTOM, right, top, Width, (int)currentSize.Height, flags);
  397. break;
  398. case AddonWindowLocation.Right:
  399. Height = Math.Max(_CustomControl.OriginalCtrlSize.Height + dy, (int)FileDialogControlBase.OriginalDlgHeight);
  400. Win32Types.NativeMethods.SetWindowPos(_hFileDialogHandle, (IntPtr)ZOrderPos.HWND_BOTTOM, right, top, (int)currentSize.Width, Height, flags);
  401. break;
  402. }
  403. break;
  404. case Msg.WM_SIZE:
  405. {
  406. Win32Types.NativeMethods.GetClientRect(new HandleRef(this, _hFileDialogHandle), ref currentSize);
  407. switch (_CustomControl.FileDlgStartLocation)
  408. {
  409. case AddonWindowLocation.Bottom:
  410. if (!mInitializated && FileDialogControlBase.OriginalDlgWidth == 0)
  411. FileDialogControlBase.OriginalDlgWidth = currentSize.Width;
  412. if (currentSize.Width != _CustomControl.Width)
  413. _CustomControl.Width = (int)currentSize.Width;
  414. break;
  415. case AddonWindowLocation.Right:
  416. if (!mInitializated && FileDialogControlBase.OriginalDlgHeight == 0)
  417. FileDialogControlBase.OriginalDlgHeight = currentSize.Height;
  418. if (currentSize.Height != _CustomControl.Height)
  419. _CustomControl.Height = (int)currentSize.Height;
  420. break;
  421. }
  422. }
  423. break;
  424. case Msg.WM_SIZING:
  425. Win32Types.NativeMethods.GetClientRect(new HandleRef(this, _hFileDialogHandle), ref currentSize);
  426. switch (_CustomControl.FileDlgStartLocation)
  427. {
  428. case AddonWindowLocation.Right:
  429. if (currentSize.Height != _CustomControl.Height)
  430. Win32Types.NativeMethods.SetWindowPos(_CustomControl.Handle, (IntPtr)ZOrderPos.HWND_BOTTOM, 0, 0, (int)_CustomControl.Width, (int)currentSize.Height, UFLAGSSIZEEX);
  431. break;
  432. case AddonWindowLocation.Bottom:
  433. if (currentSize.Height != _CustomControl.Height)
  434. Win32Types.NativeMethods.SetWindowPos(_CustomControl.Handle, (IntPtr)ZOrderPos.HWND_BOTTOM, 0, 0, (int)currentSize.Width, (int)_CustomControl.Height, UFLAGSSIZEEX);
  435. break;
  436. case AddonWindowLocation.BottomRight:
  437. if (currentSize.Width != _CustomControl.Width || currentSize.Height != _CustomControl.Height)
  438. Win32Types.NativeMethods.SetWindowPos(_CustomControl.Handle, (IntPtr)ZOrderPos.HWND_BOTTOM, (int)currentSize.Width, (int)currentSize.Height, (int)currentSize.Width, (int)currentSize.Height, UFLAGSSIZEEX);
  439. break;
  440. }
  441. break;
  442. case Msg.WM_WINDOWPOSCHANGING:
  443. if (!mIsClosing)
  444. {
  445. if (!mInitializated && !mResized)
  446. {
  447. // Resize OpenDialog to make fit our extra form
  448. WINDOWPOS pos = (WINDOWPOS)Marshal.PtrToStructure(m.LParam, typeof(WINDOWPOS));
  449. if (pos.flags != 0 && ((pos.flags & (int)SWP_Flags.SWP_NOSIZE) != (int)SWP_Flags.SWP_NOSIZE))
  450. {
  451. switch (_CustomControl.FileDlgStartLocation)
  452. {
  453. case AddonWindowLocation.Right:
  454. mOriginalSize = new Size(pos.cx, pos.cy);
  455. pos.cx += _CustomControl.Width;
  456. Marshal.StructureToPtr(pos, m.LParam, true);
  457. currentSize = new RECT();
  458. Win32Types.NativeMethods.GetClientRect(new HandleRef(this, _hFileDialogHandle), ref currentSize);
  459. if (_CustomControl.Height < (int)currentSize.Height)
  460. _CustomControl.Height = (int)currentSize.Height;
  461. break;
  462. case AddonWindowLocation.Bottom:
  463. InitControls(100);
  464. mOriginalSize = new Size(pos.cx, pos.cy);
  465. pos.cy += _CustomControl.Height;
  466. Marshal.StructureToPtr(pos, m.LParam, true);
  467. currentSize = new RECT();
  468. Win32Types.NativeMethods.GetClientRect(new HandleRef(this, _hFileDialogHandle), ref currentSize);
  469. if (_CustomControl.Width < (int)currentSize.Width)
  470. _CustomControl.Width = (int)currentSize.Width;
  471. break;
  472. case AddonWindowLocation.BottomRight:
  473. mOriginalSize = new Size(pos.cx, pos.cy);
  474. pos.cy += _CustomControl.Height;
  475. pos.cx += _CustomControl.Width;
  476. Marshal.StructureToPtr(pos, m.LParam, true);
  477. break;
  478. }
  479. mResized = true; // Don't resize again
  480. }
  481. }
  482. }
  483. break;
  484. case Msg.WM_IME_NOTIFY:
  485. if (m.WParam == (IntPtr)ImeNotify.IMN_CLOSESTATUSWINDOW)
  486. {
  487. mIsClosing = true;
  488. Win32Types.NativeMethods.SetWindowPos(_hFileDialogHandle, IntPtr.Zero, 0, 0, 0, 0, UFLAGSHIDE);
  489. Win32Types.NativeMethods.GetWindowRect(new HandleRef(this, _hFileDialogHandle), ref _DialogWindowRect);
  490. Win32Types.NativeMethods.SetWindowPos(_hFileDialogHandle, IntPtr.Zero,
  491. (int)(_DialogWindowRect.left),
  492. (int)(_DialogWindowRect.top),
  493. (int)(mOriginalSize.Width),
  494. (int)(mOriginalSize.Height),
  495. FileDialogControlBase.MSFileDialogWrapper.UFLAGSSIZE);
  496. }
  497. break;
  498. case Msg.WM_PAINT:
  499. break;
  500. case Msg.WM_NCCREATE:
  501. break;
  502. case Msg.WM_CREATE:
  503. break;
  504. case Msg.WM_ACTIVATE:
  505. if (_WatchForActivate && !mIsClosing)//WM_NCACTIVATE works too
  506. { //Now the Open/Save Dialog is visible and about to enter the modal loop
  507. _WatchForActivate = false;
  508. //Now we save the real dialog window handle
  509. _hFileDialogHandle = m.LParam;
  510. ReleaseHandle();//release the dummy window
  511. AssignHandle(_hFileDialogHandle);//assign the native open file handle to grab the messages
  512. #pragma warning disable 0197, 0414
  513. Win32Types.NativeMethods.GetWindowRect(new HandleRef(this, _hFileDialogHandle), ref _CustomControl._OpenDialogWindowRect);
  514. #pragma warning restore 0197, 0414
  515. _CustomControl._hFileDialogHandle = _hFileDialogHandle;
  516. }
  517. break;
  518. case Msg.WM_COMMAND:
  519. switch (Win32Types.NativeMethods.GetDlgCtrlID(m.LParam))
  520. {
  521. case (int)ControlsId.ButtonOk://OK
  522. break;
  523. case (int)ControlsId.ButtonCancel://Cancel
  524. break;
  525. case (int)ControlsId.ButtonHelp://help
  526. break;
  527. case 0:
  528. break;
  529. default:
  530. break;
  531. }//switch(Win32Types.NativeMethods.GetDlgCtrlID(m.LParam)) ends
  532. break;
  533. default:
  534. break;
  535. }//switch ((Msg)m.Msg) ends
  536. base.WndProc(ref m);
  537. }
  538. #endregion
  539. #region Properties
  540. #endregion
  541. }
  542. #endregion
  543. }
  544. #region Enums
  545. public enum AddonWindowLocation
  546. {
  547. BottomRight = 0,
  548. Right = 1,
  549. Bottom = 2
  550. }
  551. internal enum ControlsId : int
  552. {
  553. ButtonOk = 0x1,
  554. ButtonCancel = 0x2,
  555. ButtonHelp = 0x40E,//0x0000040e
  556. GroupFolder = 0x440,
  557. LabelFileType = 0x441,
  558. LabelFileName = 0x442,
  559. LabelLookIn = 0x443,
  560. DefaultView = 0x461,
  561. LeftToolBar = 0x4A0,
  562. ComboFileName = 0x47c,
  563. ComboFileType = 0x470,
  564. ComboFolder = 0x471,
  565. CheckBoxReadOnly = 0x410
  566. }
  567. #endregion
  568. }