getdesktopwindow(getdesktopwindow 虚拟桌面)
C++中,截图屏幕的几行代码看不懂,求解释啊
HDC hDc,memDc;
hDc = GetDC(GetDesktopWindow()); //取桌面的设备 hdc
memDc = CreateCompatibleDC(hDc); //创建与hdc(即桌面)兼容的设备memDc
HBITMAP hBitMap;
hBitMap = CreateCompatibleBitmap(hDc,with,hight); //创建与桌面兼容的画布
SelectObject(memDc,hBitMap); //关联 设备 和 画布
BitBlt(memDc,0,0,with,hight,hDc,0,0,SRCCOPY); //把桌面往兼容设备里复制
一个设备(笔,画刷....) ,再准备一张画布(一个内存空间), 就可以作画了. 要真正的得到一个图, 总要有东西把原图放进去吧. 所以有了, 兼容的设备和画布.
vb中 如何获得窗体中所有控件的句柄
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Sub Command1_Click()
Call List1_Click
End Sub
Private Sub Command2_Click()
Dim hwnd As Long
Dim s As String, t As String
List1.Clear
hwnd = GetDesktopWindow()
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
List1.AddItem "桌面:" hwnd " 类名:" s " 标题:" t vbCrLf
hwnd = GetWindow(hwnd, GW_CHILD Or GW_HWNDFIRST)
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
List1.AddItem "窗口:" hwnd " 类名:" s " 标题:" t vbCrLf
While hwnd 0
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
s = String(256, Chr(0))
GetClassName hwnd, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hwnd, t, 255
t = Replace(t, Chr(0), "")
List1.AddItem "窗口:" hwnd " 类名:" s "标题:" t vbCrLf
Wend
End Sub
Private Sub Form_Load()
Command1.Caption = "获取所有控件"
Command2.Caption = "遍历所有窗体"
End Sub
Private Sub EnumAllHandles(ByVal hwnd As Long)
Dim hn As Long
Dim firsthd As Long
Dim s As String, t As String
firsthd = GetWindow(hwnd, GW_CHILD)
firsthd = GetWindow(firsthd, GW_HWNDFIRST)
hn = firsthd
Do While hn 0
s = String(256, Chr(0))
GetClassName hn, s, 255
s = Replace(s, Chr(0), "")
t = String(256, Chr(0))
GetWindowText hn, t, 255
t = Replace(t, Chr(0), "")
Text1.Text = Text1.Text "句柄:" hn " 父句柄:" hwnd " 类名:" s "标题:" t vbCrLf
TreeView1.Nodes.Add "k" hwnd, tvwChild, "k" hn, "句柄:" hn " 类名:" s "标题:" t
EnumAllHandles hn
hn = GetWindow(hn, GW_HWNDNEXT)
If hn = firsthd Then Exit Do
Loop
End Sub
Private Sub List1_Click()
If List1.ListIndex = -1 Then Exit Sub
TreeView1.Nodes.Clear
TreeView1.Nodes.Add , , "k" Trim(Str(Val(Mid(List1.Text, 4)))), List1.Text
Text1.Text = ""
EnumAllHandles Val(Mid(List1.Text, 4))
TreeView1.Nodes("k" Trim(Str(Val(Mid(List1.Text, 4))))).Expanded = True
End Sub
'添加两个按钮一个文本框一个列表框和一个树形图
怎么获取桌面的句柄
启动定时器:
SetTimer(...);
....
OnTimer()
{.....}
取得桌面:
HWND hwnd=GetDesktopWindow();
excel vba 调用windows api?
GetPixel()里传入的参数是hdc(Handle to Device Contex,设备上下文句柄),而你通过GetDesktopWindow得到的是hWnd窗口句柄,可以通过GetWindowDC()函数来获得hdc,之后再调用GetPixel(),最后别忘了ReleaseDC()释放。
这两个函数声明如下:
Declare Function GetWindowDC Lib "USER32" (ByVal hWnd As Long) As Long
Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Long, ByVal hdc As Long) As Long