private void PositionButton(IntPtr hWnd, int right, int width) { hWnd.AssumeNonZero(); int id = hWnd.GetDlgCtrlID(); //hWnd.BringWindowToTop(); InteropUtil.WINDOWPLACEMENT buttonLoc = hWnd.GetWindowPlacement(); buttonLoc.Right = right; buttonLoc.Left = buttonLoc.Right - width; hWnd.SetWindowPlacement(ref buttonLoc); hWnd.InvalidateRect(IntPtr.Zero, true); }
private void ResizeCustomControl(IntPtr hWnd) { if (hWnd == m_hWnd) { IntPtr hSelectButton = hWnd.AssumeNonZero().GetDlgItem(InteropUtil.ID_SELECT).AssumeNonZero(); IntPtr hOkButton = hWnd.AssumeNonZero().GetDlgItem(InteropUtil.ID_CUSTOM_CANCEL).AssumeNonZero(); IntPtr hParent = hWnd.GetParent().AssumeNonZero(); IntPtr fileName = hParent.GetDlgItem(InteropUtil.ID_FileNameCombo).AssumeNonZero(); /*var right = fileName.GetWindowPlacement().Right; * var top = hSelectButton.GetWindowPlacement().Top;*/ InteropUtil.RECT rect = new InteropUtil.RECT(); InteropUtil.WINDOWPLACEMENT selectRect = hSelectButton.GetWindowPlacement(); rect.top = selectRect.Top; rect.bottom = selectRect.Bottom; rect.right = fileName.GetWindowPlacement().Right; rect.left = rect.right - (m_cancelWidth + m_buttonGap + m_selectWidth); ResizeCustomControl(hWnd, rect, hOkButton, hSelectButton); } }
private void ResizeCustomControl(IntPtr hWnd, InteropUtil.RECT rect, params IntPtr[] buttons) { DialogBrowsingUtilities.Assume(buttons != null && buttons.Length > 0); hWnd.AssumeNonZero(); InteropUtil.WINDOWPLACEMENT wndLoc = hWnd.GetWindowPlacement(); wndLoc.Right = rect.right; hWnd.SetWindowPlacement(ref wndLoc); foreach (IntPtr hBtn in buttons) { m_calcPosMap[hBtn.GetDlgCtrlID()](this, rect.right, out int btnRight, out int btnWidth); PositionButton(hBtn, btnRight, btnWidth); } IntPtr hRgn = InteropUtil.CreateRectRgnIndirect(ref rect); try { if (hWnd.SetWindowRgn(hRgn, true) == 0) { //setting the region failed, so we need to delete the region we created above. hRgn.DeleteObject(); } } catch { if (hRgn != IntPtr.Zero) { hRgn.DeleteObject(); } } }
private void InitDialog(IntPtr hWnd) { m_hWnd = hWnd; IntPtr hParent = hWnd.GetParent().AssumeNonZero(); hParent.SetWindowSubclass(m_openFileSubClassDelegate, 0, 0); //disable and hide the filter combo box IntPtr hFilterCombo = hParent.GetDlgItem(InteropUtil.ID_FilterCombo).AssumeNonZero(); hFilterCombo.EnableWindow(false); hParent.SendMessage(InteropUtil.CDM_HIDECONTROL, InteropUtil.ID_FilterCombo, 0); hParent.SendMessage(InteropUtil.CDM_HIDECONTROL, InteropUtil.ID_FilterLabel, 0); //update the file name label IntPtr hFileNameLabel = hParent.GetDlgItem(InteropUtil.ID_FileNameLabel).AssumeNonZero(); if (FileNameLabel != "") { hFileNameLabel.SendMessageString(InteropUtil.WM_SETTEXT, 0, FileNameLabel); } //find the button controls in the parent IntPtr hOkButton = hParent.GetDlgItem(InteropUtil.IDOK).AssumeNonZero(); IntPtr hCancelButton = hParent.GetDlgItem(InteropUtil.IDCANCEL).AssumeNonZero(); //We don't want the accelerator keys for the ok and cancel buttons to work, because //they are not shown on the dialog. However, we still want the buttons enabled //so that "esc" and "enter" have the behavior they used to. So, we just //clear out their text instead. hOkButton.SetWindowTextW(""); hCancelButton.SetWindowTextW(""); //find our button controls IntPtr hSelectButton = hWnd.GetDlgItem(InteropUtil.ID_SELECT).AssumeNonZero(); IntPtr hCustomCancelButton = hWnd.GetDlgItem(InteropUtil.ID_CUSTOM_CANCEL).AssumeNonZero(); //copy the font from the parent's buttons hSelectButton.LoadFontFrom(hOkButton); hCustomCancelButton.LoadFontFrom(hCancelButton); InteropUtil.WINDOWPLACEMENT cancelLoc = hCancelButton.GetWindowPlacement(); //hide the ok and cancel buttons hParent.SendMessage(InteropUtil.CDM_HIDECONTROL, InteropUtil.IDOK, 0); hParent.SendMessage(InteropUtil.CDM_HIDECONTROL, InteropUtil.IDCANCEL, 0); //expand the file name combo to take up the space left by the OK and cancel buttons. IntPtr hFileName = hParent.GetDlgItem(InteropUtil.ID_FileNameCombo).AssumeNonZero(); InteropUtil.WINDOWPLACEMENT fileNameLoc = hFileName.GetWindowPlacement(); fileNameLoc.Right = hOkButton.GetWindowPlacement().Right; hFileName.SetWindowPlacement(ref fileNameLoc); InteropUtil.WINDOWPLACEMENT parentLoc = hParent.GetWindowPlacement(); //subtract the height of the missing cancel button parentLoc.Bottom -= (cancelLoc.Bottom - cancelLoc.Top); hParent.SetWindowPlacement(ref parentLoc); //move the select and custom cancel buttons to the right hand side of the window: InteropUtil.WINDOWPLACEMENT selectLoc = hSelectButton.GetWindowPlacement(); InteropUtil.WINDOWPLACEMENT customCancelLoc = hCustomCancelButton.GetWindowPlacement(); m_cancelWidth = customCancelLoc.Right - customCancelLoc.Left; m_selectWidth = selectLoc.Right - selectLoc.Left; m_buttonGap = customCancelLoc.Left - selectLoc.Right; InteropUtil.WINDOWPLACEMENT ctrlLoc = hWnd.GetWindowPlacement(); ctrlLoc.Right = fileNameLoc.Right; //ResizeCustomControl(hWnd, fileNameLoc.Right, hCustomCancelButton, hSelectButton); ResizeCustomControl(hWnd); }