如何在picturebox控件中显示其他句柄的图像
知道另外的一个程序控件的句柄 怎么在程序中显示这个句柄中的图像呢?!
[解决办法]
你将一个程序的图像传给另一个程序?先将另一个程序中的图像保存为图片文件,由第一个程序读取.另一个程序是别人的就不行了,这就要从内存中直接拷贝过来
[解决办法]
知道它的句柄这样办:
1、根据句柄取得该设备的DC,lhDc=GetDC(hWnd);
2、用BitBlt复制该设备位图到picturebox,picHDC上是其设备DC,w和h分别是其宽和高
BitBlt picHDC,0,0,w,h,lhDc,0,0,SRCCOPY
[解决办法]
picturebox的AutoRedraw设为True
[解决办法]
呵呵,回答问题的时候还是要具体的看下对方的问题吧,不然有时候会弄笑话的。
用bitblt被遮住的部分肯定得不到图像,要解决这个问题,可以考虑使用XP系统提供的API函数PrintWindow,对于XP以下 的系统,也许可以发送WM_PRINT,但是我在XP下这个句柄只能是本进程的。
Private Declare Function PrintWindow Lib "user32" (ByVal Hwnd As Long, ByVal hdcBlt As Long, ByVal nFlags As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" (ByVal Hwnd As Long) As Long
Private Declare Sub SetWindowPos Lib "user32" (ByVal Hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function IsWindow Lib "user32" (ByVal Hwnd As Long) As Long
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOACTIVATE = &H10
Private Function GetPictureFormHwnd(Hwnd As Long, Pic As PictureBox)
Dim Visible As Boolean
If IsWindow(Hwnd) = False Then
MsgBox "所提供的不是一个有效句柄.", vbCritical + vbOKOnly
Exit Function
Else
Pic.ScaleMode = 3
Pic.AutoRedraw = True
Visible = IsWindowVisible(Hwnd) '控件是否可见
If Visible = False Then '使控件暂时可见
SetWindowPos mWnd, 0, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End If
PrintWindow Hwnd, Pic.hDC, 0 'PrintWindow 需要控件可见
If Visible = False Then '恢复控件状态
SetWindowPos mWnd, 0, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_HIDEWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End If
End If
End Function