WindowsAPI查找flash句柄问题

rcom10002 2012-07-18 08:08:09

我用下面的代码获取WebBrowser中的flash句柄,如果访问地址是“http://v.youku.com/v_show/id_XNDI4NjE4Mzk2.html”的话,代码工作正常,可以正确地返回宽和高。但如果是访问QQ游戏“http://user.qzone.qq.com/25907516/infocenter#!app=607”,获取的flash句柄对应的宽和高就是“1*1”,不是真实的宽和高。这两个地址的差别在于,优酷flash插件是直接写在HTML里的,而QQ游戏是通过HTML中的iframe嵌套进来。



private static string IES_CLASS_NAME = "Internet Explorer_Server";
private static IntPtr IES_CLASS_NAME_HWND = IntPtr.Zero;
private static string MMFPAX_CLASS_NAME = "MacromediaFlashPlayerActiveX";
private static IntPtr MMFPAX_CLASS_NAME_HWND = IntPtr.Zero;


private void btnInjectPlugin_Click(object sender, EventArgs e)
{
User32.EnumChildWindows(this.browserClient.Handle, EnumChildWindowsCallBack, IntPtr.Zero);
if (!IntPtr.Zero.Equals(IES_CLASS_NAME_HWND))
{
this.log("IES_CLASS_NAME_HWND is not null!");
//User32.EnumChildWindows(IES_CLASS_NAME_HWND, EnumChildWindowsCallBack, IntPtr.Zero);
MMFPAX_CLASS_NAME_HWND = User32.FindWindowEx(IES_CLASS_NAME_HWND, IntPtr.Zero, MMFPAX_CLASS_NAME, null);


while (!IntPtr.Zero.Equals(MMFPAX_CLASS_NAME_HWND))
{
StringBuilder className = new StringBuilder(100);
StringBuilder windowsName = new StringBuilder(100);
User32.GetClassName(MMFPAX_CLASS_NAME_HWND, className, className.Capacity);
User32.GetWindowText(MMFPAX_CLASS_NAME_HWND, windowsName, windowsName.Capacity);
RECT winRect = new RECT();
User32.GetWindowRect(MMFPAX_CLASS_NAME_HWND, ref winRect);
RECT cltRect = new RECT();
User32.GetClientRect(MMFPAX_CLASS_NAME_HWND, out cltRect);

INSTANCE.log("Handle:" + MMFPAX_CLASS_NAME_HWND + "|windowsname:" + windowsName + "|classname:" + className + "|width:" + (winRect.right - winRect.left) + "/" + (cltRect.right - cltRect.left) + "|height:" + (winRect.bottom - winRect.top) + "/" + (cltRect.bottom - cltRect.top));
if (winRect.right - winRect.left > 400)
{
break;
}
MMFPAX_CLASS_NAME_HWND = User32.FindWindowEx(IES_CLASS_NAME_HWND, MMFPAX_CLASS_NAME_HWND, MMFPAX_CLASS_NAME, null);
}
}
User32.PostMessage(MMFPAX_CLASS_NAME_HWND, (uint)MouseMessages.WM_RBUTTONDOWN, IntPtr.Zero, (IntPtr)((0 << 16) | (0 & 0xffff)));
User32.PostMessage(MMFPAX_CLASS_NAME_HWND, (uint)MouseMessages.WM_RBUTTONUP, IntPtr.Zero, (IntPtr)((0 << 16) | (0 & 0xffff)));
}



日志输出内容为:
2012-07-18 8:01:47 :: Handle:330018|windowsname:|classname:MacromediaFlashPlayerActiveX|width:1/1|height:1/1
2012-07-18 8:01:47 :: IES_CLASS_NAME_HWND is not null!
2012-07-18 8:01:47 :: Handle:330018|windowsname:|classname:MacromediaFlashPlayerActiveX|width:1|height:1
2012-07-18 8:01:47 :: Handle:461064|windowsname:|classname:Internet Explorer_Server|width:1680|height:838
2012-07-18 8:01:47 :: Handle:1050662|windowsname:|classname:Shell DocObject View|width:1680|height:838

...全文
314 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
rcom10002 2012-07-22
  • 打赏
  • 举报
回复
UP一下,继续等
rcom10002 2012-07-18
  • 打赏
  • 举报
回复
PS:WebBrowser里的HTML元素能用API枚举,EnumChildWindows不好用?我现在只是用WebBrowser里的Document操作。
rcom10002 2012-07-18
  • 打赏
  • 举报
回复
代码结果和Spy++里显示的完全一样,里面只有一个MacromediaFlashPlayerActiveX句柄,宽高一个像素。
bdmh 2012-07-18
  • 打赏
  • 举报
回复
如果是iframe嵌套,你是不是需要对 iframe中的组件继续枚举
遍历并搜索枚举当前Windows Mobile系统中可用SD卡的源代码,更多资源请访问http://www.59186618.com 在WM中SD卡是重要的存储设备相当于PC系统的硬盘。用户有大量数据和程序保存在其中。SD卡一般以目录形式出现在根目录下,用户可以方便的访问比如模拟器上一般为\Storage Card目录。但是在真实系统中SD卡对应的目录名不是固定的。比如我见过\SDMMC或者\存储卡等等。 甚至在模拟器上如果在设置SD卡共享目录前已经存在\Storage Card目录则系统会将SD卡目录自动设置为\Storage Card2。因此我们的程序不能固定使用\Storage Card作为SD卡的目录名。WM中有一组特殊的API可以解决这个问题。 头文件:projects.h Lib库: note_prj.lib FindFirstFlashCard():获取第一个可用的SD卡信息,使用WIN32_FIND_DATA结构体保存这些信息。 返回查找句柄。 FindNextFlashCard():使用查找句柄和WIN32_FIND_DATA查找下一个可用的SD卡信息,返回BOOL类型的查找结果。 FindClose():关闭查找句柄。 示例程序枚举所有可用SD卡信息,并用弹出对话框显示SD卡目录名。 BOOL bContinue = TRUE; // If TRUE, continue // searching // If FALSE, stop searching. HANDLE hFlashCard; // Search handle for storage // cards WIN32_FIND_DATA *lpwfdFlashCard; // Structure for storing // card information. lpwfdFlashCard = (WIN32_FIND_DATA *) LocalAlloc (LPTR, 10 * sizeof (WIN32_FIND_DATA)); if (lpwfdFlashCard != NULL) // Failed allocate memory return; { hFlashCard = FindFirstFile(TEXT("\\*"), lpwfdFlashCard); //hFlashCard = FindFirstFlashCard (lpwfdFlashCard); } if (hFlashCard == INVALID_HANDLE_VALUE) { LocalFree (lpwfdFlashCard); // Free the memory. return; } while (bContinue) { //判断代码 if ((lpwfdFlashCard->dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_TEMPORARY)) == (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_TEMPORARY)) { csPath = lpwfdFlashCard->cFileName; // This Folder is an mounted device (e.g. flash card) } // Search for the next storage card. bContinue = FindNextFile(hFlashCard, lpwfdFlashCard); //bContinue = FindNextFlashCard (hFlashCard, lpwfdFlashCard); } FindClose (hFlashCard); // Close the search handle. LocalFree (lpwfdFlashCard); // Free the memory. 遍历并搜索枚举当前Windows Mobile系统中可用SD卡的源代码,更多资源请访问http://www.59186618.com

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

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

试试用AI创作助手写篇文章吧