getFolder(string Caption = "") { string returnValue = ""; BrowseInfo structBrowseInfo = new BrowseInfo(); string FolderName = ""; int ID = 0; int Res = 0; structBrowseInfo.hOwner = 0; structBrowseInfo.pidlRoot = 0; structBrowseInfo.pszDisplayName = new string(Convert.ToChar(0x0), MAX_PATH); structBrowseInfo.lpszINSTRUCTIONS = Caption; structBrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS; structBrowseInfo.lpfn = 0; FolderName = new string(Convert.ToChar(0x0), MAX_PATH); ID = System.Convert.ToInt32(SHBrowseForFolderA(structBrowseInfo)); if (ID != 0) { Res = System.Convert.ToInt32(SHGetPathFromIDListA(ID, FolderName)); if (Res != 0) { returnValue = FolderName.Substring(0, FolderName.IndexOf(Convert.ToChar(0x0)) + 0); } } return(returnValue); }
public bool ShowDialog(IWin32Window owner) { _path = string.Empty; IntPtr handle; IntPtr zero = IntPtr.Zero; if (owner != null) { handle = owner.Handle; } else { handle = UnmanagedMethods.GetActiveWindow(); } UnmanagedMethods.SHGetSpecialFolderLocation(handle, (int)_startLocation, ref zero); if (zero == IntPtr.Zero) { return(false); } int num = (int)_options; if ((num & 0x40) != 0) { Application.OleRequired(); } IntPtr pidl = IntPtr.Zero; try { BrowseInfo lpbi = new BrowseInfo(); //IntPtr pszPath = Marshal.AllocHGlobal(MAX_PATH); lpbi.pidlRoot = zero; lpbi.hwndOwner = handle; lpbi.displayName = new string('\0', MAX_PATH); lpbi.title = _title; lpbi.flags = num; lpbi.callback = null; lpbi.lparam = IntPtr.Zero; pidl = UnmanagedMethods.SHBrowseForFolder(ref lpbi); if (pidl == IntPtr.Zero) { return(false); } _displayName = lpbi.displayName; StringBuilder pathReturned = new StringBuilder(MAX_PATH); UnmanagedMethods.SHGetPathFromIDList(pidl, pathReturned); _path = pathReturned.ToString(); UnmanagedMethods.SHMemFree(pidl); } finally { UnmanagedMethods.SHMemFree(zero); } return(true); }
/// <summary> /// Displays the "open folder" dialog and returns the selected path name. /// </summary> /// <param name="title">Title of dialog.</param> /// <returns>The path of selected folder.</returns> public static string OpenFolderDialog(string title) { var lpbi = new BrowseInfo { lpszTitle = title, ulFlags = BIFlags.BIF_RETURNONLYFSDIRS }; var pidl = Shell32.SHBrowseForFolder(lpbi); var pszPath = new char[256]; if (Shell32.SHGetPathFromIDList(pidl, pszPath)) { var fdrPath = new string(pszPath); return(fdrPath.Substring(0, fdrPath.IndexOf('\0'))); } return(string.Empty); }
//만약 탐지 가능한 객체(EqualTimeLayer == true)가 있으면 !null 요소가 만약 객체가 없으면 null public BrowseInfo[] Browse(float rayLen) { gBrowseHits = new RaycastHit[browseDensity][]; BrowseInfo[] bInfos = new BrowseInfo[0]; maxX = GetComponent <Collider>().bounds.max.x; maxY = GetComponent <Collider>().bounds.max.y; minX = GetComponent <Collider>().bounds.min.x; minY = GetComponent <Collider>().bounds.min.y; for (int i = 0; i < browseDensity; i++) { if (transform.localScale.x > 0) { gBrowseHits[i] = Physics.RaycastAll( new Vector3(minX - 0.1f, maxY - colYLen * (i / (browseDensity - 1)), transform.position.z), Vector3.right, rayLen + colXLen, browseMask); } else { gBrowseHits[i] = Physics.RaycastAll( new Vector3(maxX + 0.1f, maxY - colYLen * (i / (browseDensity - 1)), transform.position.z), Vector3.left, rayLen + colXLen, browseMask); } bInfos = new BrowseInfo[gBrowseHits[i].Length]; for (int j = 0; j < gBrowseHits[i].Length; j++) { if (gBrowseHits[i][j].collider != null) { if (TimeLayer.EqualTimeLayer(pTimeLayer, gBrowseHits[i][j].transform.GetComponentInParent <TimeLayer>())) { bInfos[j].InitBrowseInfo(gBrowseHits[i][j].collider.gameObject, gBrowseHits[i][j].distance, gBrowseHits[i][j].normal, gBrowseHits[i][j].point, gBrowseHits[i][j].transform.tag, gBrowseHits[i][j].transform.gameObject.layer); } } } } return(bInfos); }
public BoolWithPrimaryKeyView AddBrowse(string publishID) { string BrowserID; string BrowserName; //将当前用户的浏览记录计入数据库 if (!string.IsNullOrEmpty(UserID)) { BrowserID = UserID; BrowserName = UserName; } else { //如果当前没有人登录,则按照匿名用户浏览 BrowserID = anonymousUserConfigSection.UserID; BrowserName = anonymousUserConfigSection.UserName; } //获得浏览存储的信息 //线上活动ID、浏览人的ID与名称、浏览时间、是否失效 BrowseInfo browseInfo = new BrowseInfo() { ID = Guid.NewGuid().ToString(), PublishID = publishID, BrowserID = BrowserID, BrowserName = BrowserName, BrowseTime = DateTime.Now, BrowserIP = HttpContext.Current.Request.UserHostAddress, IsHinted = ((int)MiicYesNoSetting.Yes).ToString() }; bool browseResult = IbrowseInfo.Insert(browseInfo); BoolWithPrimaryKeyView result = new BoolWithPrimaryKeyView() { PrimaryID = browseResult == true ? browseInfo.ID : string.Empty, result = browseResult }; return(result); }
private bool RecordBrowseInfo(string token, decimal lng, decimal lat, string api) { try { BrowseInfo browseInfo = new BrowseInfo(); browseInfo.Id = Guid.NewGuid(); if (!string.IsNullOrWhiteSpace(token)) { browseInfo.LoginId = new Guid(token); } browseInfo.Lng = lng; browseInfo.lat = lat; browseInfo.BrowseUrl = api; browseInfo.BrowseTime = DateTime.Now; context.CloseLog(); context.Insert <BrowseInfo>(browseInfo); context.OpenLog(); return(true); } catch { throw; } }
public static extern IntPtr SHBrowseForFolder(ref BrowseInfo lpbi);
/// <summary> /// Displays the folder browser dialog. /// </summary> /// <param name="hwndOwner">Handle to the window that owns the dialog box.</param> /// <returns> /// If the user clicks the OK button of the dialog that is displayed, true is returned; otherwise, false. /// </returns> protected override bool RunDialog(IntPtr hwndOwner) { var result = false; IntPtr pidlRoot = IntPtr.Zero, pszPath = IntPtr.Zero, pidlSelected = IntPtr.Zero; SelectedPath = string.Empty; try { if (UseSpecialFolderRoot) { Shell32.SHGetFolderLocation(hwndOwner, (int)RootSpecialFolder, IntPtr.Zero, 0, out pidlRoot); } else // RootType == Path { uint iAttribute; Shell32.SHParseDisplayName(RootPath, IntPtr.Zero, out pidlRoot, 0, out iAttribute); } var browseInfo = new BrowseInfo { HwndOwner = hwndOwner, Root = pidlRoot, DisplayName = new string(' ', 256), Title = Title, Flags = _dialogOptions, LParam = 0, Callback = HookProc }; // Show dialog pidlSelected = Shell32.SHBrowseForFolder(ref browseInfo); if (pidlSelected != IntPtr.Zero) { result = true; pszPath = Marshal.AllocHGlobal(260 * Marshal.SystemDefaultCharSize); Shell32.SHGetPathFromIDList(pidlSelected, pszPath); SelectedPath = Marshal.PtrToStringAuto(pszPath); } } finally // release all unmanaged resources { var malloc = GetSHMalloc(); if (pidlRoot != IntPtr.Zero) { malloc.Free(pidlRoot); } if (pidlSelected != IntPtr.Zero) { malloc.Free(pidlSelected); } if (pszPath != IntPtr.Zero) { Marshal.FreeHGlobal(pszPath); } Marshal.ReleaseComObject(malloc); } return(result); }
private static extern int SHBrowseForFolder(ref BrowseInfo lpbi);
internal static extern IntPtr ShellBrowseForFolder(ref BrowseInfo lbpi);
public static extern int SHBrowseForFolderA(BrowseInfo lpBrowseInfo);