• 全部
  • C#综合技术
  • C#互联网桌面应用
  • AppLauncher
  • WinForm&WPF
  • C#开发新技术
  • 问答

谁能提供c#中获取系统桌面所在路经的api函数的调用方法么?谢谢!

mickey_7 2004-10-28 04:14:09
谁能提供c#中获取系统桌面所在路经的api函数的调用方法么?谢谢!

函数是SHGetPathFromIDList和SHGetSpecialFolderLocation
vb中的原型是
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long

Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long

我在c#中用,就是参数对部起来,谁能帮帮我,参数类型可能和vb有点不同
...全文
163 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
mickey_7 2005-08-20
up
回复
chinawn 2004-11-02
mark
回复
BearRui 2004-11-01
[DllImport("shell32.dll")]
private static extern void SHGetSpecialFolderLocation (int hwnd, int csidl, ref ITEMIDLIST ppidl);
[DllImport("shell32.dll")]
private static extern int SHGetPathFromIDList (ref CITEMIDLIST pidl, string pszPath);

获取系统桌面所在路经干吗一定要用API这么麻烦了,用NET自带的Environment类不就行啦!!!
回复
回复
xiaohutushen 2004-10-29
up
回复
cs920 2004-10-29
楼上的贴答错地方了吧?
回复
zwayn1 2004-10-29
using System.Runtime.InteropServices ;
using System.Text ;
[ DllImport("kernel32") ]
public static extern void GetWindowsDirectory(StringBuilder WinDir,int count) ;
[ DllImport("kernel32") ]
public static extern void GetSystemDirectory(StringBuilder SysDir,int count) ;
[ DllImport("kernel32") ]
public static extern void GetSystemInfo(ref CPU_INFO cpuinfo) ;
[ DllImport("kernel32") ]
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo) ;
[ DllImport("kernel32") ]
public static extern void GetSystemTime(ref SYSTEMTIME_INFO stinfo) ;
/定义CPU的信息结构
[StructLayout(LayoutKind.Sequential) ]
public struct CPU_INFO
{
public uint dwOemId ;
public uint dwPageSize ;
public uint lpMinimumApplicationAddress ;
public uint lpMaximumApplicationAddress ;
public uint dwActiveProcessorMask ;
public uint dwNumberOfProcessors ;
public uint dwProcessorType ;
public uint dwAllocationGranularity ;
public uint dwProcessorLevel ;
public uint dwProcessorRevision ;
}

file://定义内存的信息结构
[StructLayout(LayoutKind.Sequential) ]
public struct MEMORY_INFO
{
public uint dwLength ;
public uint dwMemoryLoad ;
public uint dwTotalPhys ;
public uint dwAvailPhys ;
public uint dwTotalPageFile ;
public uint dwAvailPageFile ;
public uint dwTotalVirtual ;
public uint dwAvailVirtual ;
}

file://定义系统时间的信息结构
[StructLayout(LayoutKind.Sequential) ]
public struct SYSTEMTIME_INFO
{
public ushort wYear ;
public ushort wMonth ;
public ushort wDayOfWeek ;
public ushort wDay ;
public ushort wHour ;
public ushort wMinute ;
public ushort wSecond ;
public ushort wMilliseconds ;
}

  5. 编写窗体类的方法

private void button1_Click(object sender, System.EventArgs e )
{
file://调用GetWindowsDirectory和GetSystemDirectory函数分别取得Windows路径和系统路径
const int nChars = 128 ;
StringBuilder Buff = new StringBuilder(nChars) ;
GetWindowsDirectory(Buff,nChars) ;
WindowsDirectory.Text = "Windows路径:"+Buff.ToString( ) ;
GetSystemDirectory(Buff,nChars) ;
SystemDirectory.Text = " 系统路径:"+Buff.ToString( ) ;

file://调用GetSystemInfo函数获取CPU的相关信息
CPU_INFO CpuInfo ;
CpuInfo = new CPU_INFO( ) ;
GetSystemInfo(ref CpuInfo) ;
NumberOfProcessors.Text = "本计算机中有"+CpuInfo.dwNumberOfProcessors.ToString( ) +"个CPU";
ProcessorType.Text = "CPU的类型为"+CpuInfo.dwProcessorType.ToString( ) ;
ProcessorLevel.Text = "CPU等级为"+CpuInfo.dwProcessorLevel.ToString( ) ;
OemId.Text = "CPU的OEM ID为"+CpuInfo.dwOemId.ToString( ) ;
PageSize.Text = "CPU中的页面大小为"+CpuInfo.dwPageSize.ToString( ) ;

file://调用GlobalMemoryStatus函数获取内存的相关信息
MEMORY_INFO MemInfo ;
MemInfo = new MEMORY_INFO( ) ;
GlobalMemoryStatus(ref MemInfo) ;
MemoryLoad.Text = MemInfo.dwMemoryLoad.ToString( ) +"%的内存正在使用" ;
TotalPhys.Text = "物理内存共有"+MemInfo.dwTotalPhys.ToString( ) +"字节" ;
AvailPhys.Text = "可使用的物理内存有"+MemInfo.dwAvailPhys.ToString( ) +"字节" ;
TotalPageFile.Text = "交换文件总大小为"+MemInfo.dwTotalPageFile.ToString( ) +"字节" ;
AvailPageFile.Text = "尚可交换文件大小为"+MemInfo.dwAvailPageFile.ToString( ) +"字节" ;
TotalVirtual.Text = "总虚拟内存有"+MemInfo.dwTotalVirtual.ToString( ) +"字节" ;
AvailVirtual.Text = "未用虚拟内存有"+MemInfo.dwAvailVirtual.ToString( ) +"字节" ;

file://调用GetSystemTime函数获取系统时间信息
SYSTEMTIME_INFO StInfo ;
StInfo = new SYSTEMTIME_INFO( ) ;
GetSystemTime(ref StInfo) ;
Date.Text = StInfo.wYear.ToString( ) +"年"+StInfo.wMonth.ToString( ) +"月"+StInfo.wDay.ToString( ) +"日" ;
Time.Text = (StInfo.wHour+8).ToString( ) +"点"+StInfo.wMinute.ToString( ) +"分"+StInfo.wSecond.ToString( ) +"秒" ;
}
回复
xiaoslong 2004-10-29
帮顶
回复
生活真美好 2004-10-29
给你个例子

using System;
using System.Runtime.InteropServices; //允许调用windows api等

namespace xxxx
{
/// <summary>
/// PubClass_Func 的摘要说明。
/// </summary>
public class PubClass_Func
{
[DllImport("Kernel32.dll")] //windows api调用时用的哪个文件
public static extern int Beep(uint dwFreq,uint dwDuration); //windows api的beep,此法须自设置频率和时长

public PubClass_Func()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

//发声报警
public static void MyBeep()
{
Beep(2500,500);
}
}
}
回复
hanbinghai 2004-10-28
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop)
System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
括号忘了^_^
Desktop 逻辑桌面,而不是物理文件系统位置。
DesktopDirectory 用于物理上存储桌面上的文件对象的目录。
不应将此目录与桌面文件夹本身混淆,后者是虚拟文件夹。


回复
hanbinghai 2004-10-28
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop
System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory
回复
xiaohutushen 2004-10-28
NO.2

up
回复
520NET 2004-10-28
NO.1
回复
相关推荐
发帖
C#
创建于2007-09-28

10.5w+

社区成员

.NET技术 C#
申请成为版主
帖子事件
创建了帖子
2004-10-28 04:14
社区公告

让您成为最强悍的C#开发者