vc代码
/* 取桌面 ListView 的句柄 */
HWND hDeskTop;
hDeskTop = FindWindow("progman", NULL);
hDeskTop = FindWindowEx(hDeskTop, 0, "shelldll_defview", NULL);
hDeskTop = FindWindowEx(hDeskTop, 0, "syslistview32", NULL);
/* 取 explorer.exe 句柄. 注意 OpenProcess 的参数 */
DWORD dwProcessId;
GetWindowThreadProcessId(hDeskTop, &dwProcessId);
HANDLE hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_OPERATION, FALSE, dw
ProcessId);
/* 在 explorer.exe 空间内分配内存 */
PVOID pv = VirtualAllocEx(hProcess, NULL, sizeof(POINT), MEM_COMMIT, PAGE_READW
RITE);
/* 给桌面 ListView 窗口发一 LVM_GETITEMPOSITION 取 "我的电脑" 坐标 */
ListView_GetItemPosition(hDeskTop, 1, pv);
/* 把由 LVM_GETITEMPOSITION 获得的坐标数据复制到 pt 结构 */
POINT pt;
ReadProcessMemory(hProcess, pv, &pt, sizeof(POINT), NULL);
/* 释放内存, 句柄 */
VirtualFreeEx(hProcess, pv, 0, MEM_RELEASE);
CloseHandle(hProcess);
想把上面的转为C#代码.
前面几句 这样转不知是否正确
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName); [DllImport("user32.dll", EntryPoint = "FindWindowExA")]
public static extern IntPtr FindWindowExA(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, int lpszWindow);/* 取桌面 ListView 的句柄 */
HWND hDeskTop;
hDeskTop = FindWindow("Progman", "Program Manager");
hDeskTop = FindWindowExA(hWindow, (IntPtr)0, "SHELLDLL_DefView", 0);
hDeskTop = FindWindowExA(hSHELLDLL_DefView, (IntPtr)0, "SysListView32", 0);
/* 取桌面 ListView 的句柄 */
HWND hDeskTop;
hDeskTop = FindWindow("progman", NULL);
hDeskTop = FindWindowEx(hDeskTop, 0, "shelldll_defview", NULL);
hDeskTop = FindWindowEx(hDeskTop, 0, "syslistview32", NULL);
/* 取 explorer.exe 句柄. 注意 OpenProcess 的参数 */
DWORD dwProcessId;
GetWindowThreadProcessId(hDeskTop, &dwProcessId);
HANDLE hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_OPERATION, FALSE, dw
ProcessId);
/* 在 explorer.exe 空间内分配内存 */
PVOID pv = VirtualAllocEx(hProcess, NULL, sizeof(POINT), MEM_COMMIT, PAGE_READW
RITE);
/* 给桌面 ListView 窗口发一 LVM_GETITEMPOSITION 取 "我的电脑" 坐标 */
ListView_GetItemPosition(hDeskTop, 1, pv);
/* 把由 LVM_GETITEMPOSITION 获得的坐标数据复制到 pt 结构 */
POINT pt;
ReadProcessMemory(hProcess, pv, &pt, sizeof(POINT), NULL);
/* 释放内存, 句柄 */
VirtualFreeEx(hProcess, pv, 0, MEM_RELEASE);
CloseHandle(hProcess);
想把上面的转为C#代码.
前面几句 这样转不知是否正确
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName); [DllImport("user32.dll", EntryPoint = "FindWindowExA")]
public static extern IntPtr FindWindowExA(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, int lpszWindow);/* 取桌面 ListView 的句柄 */
HWND hDeskTop;
hDeskTop = FindWindow("Progman", "Program Manager");
hDeskTop = FindWindowExA(hWindow, (IntPtr)0, "SHELLDLL_DefView", 0);
hDeskTop = FindWindowExA(hSHELLDLL_DefView, (IntPtr)0, "SysListView32", 0);
解决方案 »
- 在c#中如何实现do while????
- WMI如何处理软件分发??给些资料吧!
- 浮动窗体???
- c# OPC AddItem ClientHandle问题
- ********!sqlBinary怎么转换成byte[]!********
- 放分,太开心了。串口读gps程序,用到多线程,刚做好。开心放分,进者有分~~
- MS推出C#到底是个什么东西,感觉上和vb.net没有两样(除了语法外)什么时候才能跨到别的平台下去,还有像java大规模的应用在手机上面?MS推
- C#串口通讯问题!
- 怎么这么多人在叫没分,我来送点分。前5名1-3个三角的有效,5000分陆续有来。以后不能常来回答问题了,留个好尾!
- 一个网页抓取碰到的难题,无法获取淘宝产品列表
- C#小写转大写源代码
- C#程序集基础问题 请高手进来看看
常量我会查.问题是那些指针程序
==========
这代码是网上的文章里贴出来的.. 不知怎么在VC里编译....
============
问题是我不会VC... 新那家一个DLL程序后.一大堆文件...不知在哪里搞. 自己试着把extern "C" _declspec(dllexport) int GetDeskTop()
{
HWND hDeskTop;
hDeskTop = FindWindow("progman", NULL);
hDeskTop = FindWindowEx(hDeskTop, 0, "shelldll_defview", NULL);
hDeskTop = FindWindowEx(hDeskTop, 0, "syslistview32", NULL);
return hDeskTop;
}这样就是错的.. 不知怎么 HWND 转int