/// <summary> /// Callback method for the handling of messages to be sent to/from the folder browser dialog. /// </summary> /// <param name="hwnd"></param> /// <param name="msg"></param> /// <param name="lParam"></param> /// <param name="lpData"></param> /// <returns></returns> private int FolderBrowserDialog_BrowseCallbackProc(IntPtr hwnd, int msg, IntPtr lParam, IntPtr lpData) { switch (msg) { case NativeWindowCommon.BFFM_INITIALIZED: // We get in here when the dialog is first displayed. If an initial directory // has been specified we will make this the selection now, and also make sure // that directory is expanded. if (this.selectedPath.Length != 0) { NativeWindowCommon.SendMessage(hwnd, NativeWindowCommon.BFFM_SETSELECTIONW, 1, this.selectedPath); } break; case NativeWindowCommon.BFFM_SELCHANGED: { IntPtr pidl = lParam; if (pidl != IntPtr.Zero) { StringBuilder sb = new StringBuilder(MAX_PATH * Marshal.SystemDefaultCharSize); bool flag = NativeWindowCommon.SHGetPathFromIDList(pidl, sb); NativeWindowCommon.SendMessage(hwnd, NativeWindowCommon.BFFM_ENABLEOK, 0, flag ? 1 : 0); } if (!doneScrolling) { IntPtr hbrowse = NativeWindowCommon.FindWindowEx(hwnd, IntPtr.Zero, "SHBrowseForFolder ShellNameSpace Control", null); IntPtr htree = NativeWindowCommon.FindWindowEx(hbrowse, IntPtr.Zero, "SysTreeView32", null); IntPtr htis = NativeHeader.SendMessage(htree, NativeWindowCommon.TVM_GETNEXTITEM, NativeWindowCommon.TVGN_CARET, IntPtr.Zero); IntPtr htir = NativeHeader.SendMessage(htree, NativeWindowCommon.TVM_GETNEXTITEM, NativeWindowCommon.TVGN_ROOT, IntPtr.Zero); IntPtr htic = NativeHeader.SendMessage(htree, NativeWindowCommon.TVM_GETNEXTITEM, NativeWindowCommon.TVGN_CHILD, htir); //we actually go into the BFFM_SELCHANGED case three times when the dialog is first shown, and it's only on the third one that we actually scroll, //since before this htic is always zero, so you need to cope with this //- i.e. don't set 'doneScrolling' flag until htic has been non - zero(or until you've gone into the BFFM_SELCHANGED three times). if ((int)htic != 0) { doneScrolling = true; //The only solution I've found that works consistently is to send a TVM_ENSUREVISIBLE to the tree, using TVM_GETNEXTITEM/TVGN_CARET, from BFFM_SELCHANGED. //That works. Every time. NativeHeader.SendMessage(htree, NativeWindowCommon.TVM_ENSUREVISIBLE, 0, htis); //Active the tree view control window inside the folder browser dialog to set the focus on it. NativeWindowCommon.SendMessage(htree, NativeWindowCommon.WM_ACTIVATE, 1, 0); } } } break; } return(0); }
/// <summary> /// Update the control parameter's styles. /// </summary> private void UpdateControlStyles() { int fStyle = NativeHeader.GetWindowLong(Handle, NativeHeader.GWL_EXSTYLE); if (BorderStyle == BorderStyle.FixedSingle) { // remove the Fixed3D border style fStyle &= ~NativeWindowCommon.WS_EX_CLIENTEDGE; InvalidateNC(); } if (isTransparent) { fStyle |= NativeHeader.WS_EX_TRANSPARENT; } else { fStyle &= ~NativeHeader.WS_EX_TRANSPARENT; } NativeWindowCommon.SetWindowLong(Handle, NativeHeader.GWL_EXSTYLE, fStyle); fStyle = NativeHeader.GetWindowLong(Handle, NativeHeader.GWL_STYLE); if (base.RightToLeft == RightToLeft.Yes) { fStyle |= NativeHeader.WS_EX_LTRREADING; fStyle |= NativeHeader.WS_EX_RIGHT; fStyle |= NativeHeader.WS_EX_LEFTSCROLLBAR; } else if (base.RightToLeft == RightToLeft.No) { fStyle |= NativeHeader.WS_EX_RTLREADING; fStyle |= NativeHeader.WS_EX_LEFT; fStyle |= NativeHeader.WS_EX_RIGHTSCROLLBAR; } NativeWindowCommon.SetWindowLong(Handle, NativeHeader.GWL_STYLE, fStyle); }
protected int WndProc(ref Message m) #endif { MouseEventArgs mouseEvents; switch (m.Msg) { #if !PocketPC case NativeWindowCommon.CBN_DROPDOWN: { if (OriginalDropDownWindowProc == IntPtr.Zero) { NativeWindowCommon.COMBOBOXINFO comboBoxInfo = new NativeWindowCommon.COMBOBOXINFO(); // alloc ptrComboBoxInfo IntPtr ptrComboBoxInfo = Marshal.AllocHGlobal(Marshal.SizeOf(comboBoxInfo)); try { //get combo Box Info comboBoxInfo.cbSize = (IntPtr)Marshal.SizeOf(comboBoxInfo); Marshal.StructureToPtr(comboBoxInfo, ptrComboBoxInfo, true); IntPtr intptr = NativeHeader.SendMessage(this.Handle, NativeWindowCommon.CB_GETCOMBOBOXINFO, 0, ptrComboBoxInfo); //CB_GETCOMBOBOXINFO : If the send message succeeds, the return value is nonzero. int returnValue = intptr.ToInt32(); if (returnValue > 0) { // get the info from ptrComboBoxInfo to comboBoxInfo comboBoxInfo = (NativeWindowCommon.COMBOBOXINFO)Marshal.PtrToStructure(ptrComboBoxInfo, typeof(NativeWindowCommon.COMBOBOXINFO)); // save hwnd drop down list HwndDropDownList = comboBoxInfo.hwndList; //replace the window proc of the drop down list CustomDropDownWindowProc = new ControlWndProc(DropDownWindowProc); // save the original drop down list (most be member in the class so the garbig collection will not free it) OriginalDropDownWindowProc = (IntPtr)NativeWindowCommon.SetWindowLong(HwndDropDownList, NativeWindowCommon.GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(CustomDropDownWindowProc).ToInt32()); } else { Debug.Assert(false); } } finally { // free the ptrComboBoxInfo Marshal.FreeHGlobal(ptrComboBoxInfo); } } } break; #endif case NativeWindowCommon.WM_LBUTTONDOWN: case NativeWindowCommon.WM_LBUTTONDBLCLK: if (!this.DroppedDown) { // prevent drop down on combo - to prevent combo openning on non parkable controls // - it must be handled manually mouseEvents = new MouseEventArgs(MouseButtons.Left, 0, NativeWindowCommon.LoWord((int)m.LParam), NativeWindowCommon.HiWord((int)m.LParam), 0); this.OnMouseDown(mouseEvents); // provide doubleclick event #if !PocketPC if (m.Msg == NativeWindowCommon.WM_LBUTTONDBLCLK) { this.OnMouseDoubleClick(mouseEvents); } return; #else return(0); #endif } break; } #if !PocketPC base.WndProc(ref m); #else return(NativeWindowCommon.CallWindowProc(OrigWndProc, m.HWnd, (uint)m.Msg, (uint)m.WParam.ToInt32(), m.LParam.ToInt32())); #endif }