private void InitDialog(IntPtr hWnd) { m_hWnd = hWnd; IntPtr hParent = InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)); InteropUtil.SetWindowSubclass(hParent, m_openFileSubClassDelegate, 0, 0); //disable and hide the filter combo box IntPtr hFilterCombo = InteropUtil.AssumeNonZero(InteropUtil.GetDlgItem(hParent, InteropUtil.ID_FilterCombo)); InteropUtil.EnableWindow(hFilterCombo, false); InteropUtil.SendMessage(hParent, InteropUtil.CDM_HIDECONTROL, InteropUtil.ID_FilterCombo, 0); InteropUtil.SendMessage(hParent, InteropUtil.CDM_HIDECONTROL, InteropUtil.ID_FilterLabel, 0); //update the file name label IntPtr hFileNameLabel = InteropUtil.AssumeNonZero(InteropUtil.GetDlgItem(hParent, InteropUtil.ID_FileNameLabel)); if (FileNameLabel != String.Empty) { InteropUtil.SendMessageString(hFileNameLabel, InteropUtil.WM_SETTEXT, 0, FileNameLabel); } //find the button controls in the parent IntPtr hOkButton = InteropUtil.AssumeNonZero(InteropUtil.GetDlgItem(hParent, InteropUtil.IDOK)); IntPtr hCancelButton = InteropUtil.AssumeNonZero(InteropUtil.GetDlgItem(hParent, InteropUtil.IDCANCEL)); //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. InteropUtil.SetWindowTextW(hOkButton, String.Empty); InteropUtil.SetWindowTextW(hCancelButton, String.Empty); //find our button controls IntPtr hSelectButton = InteropUtil.AssumeNonZero(InteropUtil.GetDlgItem(hWnd, InteropUtil.ID_SELECT)); IntPtr hCustomCancelButton = InteropUtil.AssumeNonZero(InteropUtil.GetDlgItem(hWnd, InteropUtil.ID_CUSTOM_CANCEL)); if (!String.IsNullOrEmpty(SelectLabel)) { InteropUtil.SetWindowTextW(hSelectButton, SelectLabel); } if (!String.IsNullOrEmpty(CancelLabel)) { InteropUtil.SetWindowTextW(hCustomCancelButton, CancelLabel); } //copy the font from the parent's buttons InteropUtil.LoadFontFrom(hSelectButton, hOkButton); InteropUtil.LoadFontFrom(hCustomCancelButton, hCancelButton); InteropUtil.WINDOWPLACEMENT cancelLoc = InteropUtil.GetWindowPlacement(hCancelButton); //hide the ok and cancel buttons InteropUtil.SendMessage(hParent, InteropUtil.CDM_HIDECONTROL, InteropUtil.IDOK, 0); InteropUtil.SendMessage(hParent, 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 = InteropUtil.AssumeNonZero(InteropUtil.GetDlgItem(hParent, InteropUtil.ID_FileNameCombo)); InteropUtil.WINDOWPLACEMENT fileNameLoc = InteropUtil.GetWindowPlacement(hFileName); fileNameLoc.Right = InteropUtil.GetWindowPlacement(hOkButton).Right; InteropUtil.SetWindowPlacement(hFileName, ref fileNameLoc); InteropUtil.WINDOWPLACEMENT parentLoc = InteropUtil.GetWindowPlacement(hParent); //subtract the height of the missing cancel button parentLoc.Bottom -= (cancelLoc.Bottom - cancelLoc.Top); InteropUtil.SetWindowPlacement(hParent, ref parentLoc); //move the select and custom cancel buttons to the right hand side of the window: InteropUtil.WINDOWPLACEMENT selectLoc = InteropUtil.GetWindowPlacement(hSelectButton); InteropUtil.WINDOWPLACEMENT customCancelLoc = InteropUtil.GetWindowPlacement(hCustomCancelButton); m_cancelWidth = customCancelLoc.Right - customCancelLoc.Left; m_selectWidth = selectLoc.Right - selectLoc.Left; m_buttonGap = customCancelLoc.Left - selectLoc.Right; InteropUtil.WINDOWPLACEMENT ctrlLoc = InteropUtil.GetWindowPlacement(hWnd); ctrlLoc.Right = fileNameLoc.Right; //ResizeCustomControl(hWnd, fileNameLoc.Right, hCustomCancelButton, hSelectButton); ResizeCustomControl(hWnd); }