
我觉得应该是这样的:你的对话框一直存在,但是状态可能是隐藏的,那么在创建这个对话框的时候,你会保存这个对话框的指针。至于保存在哪里,是由你决定的。然后要在其他类中获取到这个指针的话,那么你就可以将这个类和保存对话框指针的类或者地方建立一个关系,然后就可以获取到了。
c++通过枚举获取csgo句柄和pid。
1、通过EnumWindows枚举所有窗口,使用GetWindowThreadProcessID。
2、通过窗口句柄获取进程ID,比便获取的进程ID与当前已知的进程即可。
你获取句柄的方法好像没什么问题,关键看你取到句柄后具体要做什么 *** 作?
我在MFC 中试了一下,没有问题 ,把桌面关闭掉
HWND desktopHwnd = ::FindWindowEx( ::FindWindowEx( ::FindWindow(L"Progman", L"Program Manager"), NULL, L"SHELLDLL_DefView", NULL), NULL, L"SysListView32", L"FolderView" );::SendMessage( desktopHwnd,WM_CLOSE,0,0 );
'添加如下声明
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
'添加这个函数
Private Sub GetWndPic(Wnd As Long, Pic As PictureBox)
Dim R As RECT, DC As Long
GetWindowRect Wnd, R '获取指定窗口的左上角、右下角位置(以便获取其大小)
DC = GetWindowDC(Wnd) '得到dc
With Pic
AutoRedraw = True: BorderStyle = 0
ParentScaleMode = vbPixels
Move Left, Top, RRight - RLeft, RBottom - RTop '使PictureBox适合大小
BringWindowToTop Wnd '目标窗口提到前面(非置顶)
BitBlt hdc, 0, 0, Width, Height, DC, 0, 0, vbSrcCopy '复制绘图
End With
ReleaseDC Wnd, DC '释放
End Sub
'调用示例(把句柄131454的程序窗口截图放到Picture1中)
GetWndPic 131454, Picture1
首先你要确定打印机在任务管理器中的进程名 好比是"printexe"
/// <summary>/// 根据进程名获取句柄
/// </summary>
/// <param name="exe">进程名</param>
/// <returns>(Intptr)句柄</returns>
private static IntPtr CloseMethod(string exe)
{
if (exeSubstring(exeLength - 4) == "exe")
exe = exeSubstring(0, exeLength - 4);//去掉exe
IntPtr ihand = new IntPtr();
SystemDiagnosticsProcess[] myPs;
myPs = SystemDiagnosticsProcessGetProcesses();
foreach (SystemDiagnosticsProcess p in myPs)
{
if (pProcessNameToLower() == exeToLower())
{
try
{
ihand = pHandle;//句柄
}
catch (Exception eKillProcess)
{
}
}
}
return ihand;
}
调用:
MessageBoxShow(CloseMethod("printexe")ToString());
以上就是关于mfc如何在其他类中获取和传递指定对话框的指针或句柄全部的内容,包括:mfc如何在其他类中获取和传递指定对话框的指针或句柄、c++怎么获取csgo句柄和pid、win10如何获取桌面的句柄等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)