,
GetCursorPos
和GetDC
WinAPI调用,来获得屏幕上任何地方的像素的御扮颜色。
option
Explicit
'在表单镇兄灶中加入计时器,使用鼠标移动到屏幕上任何一处,RGB颜色就会显示在表单中的Caption中
'
private
Type
POINTAPI
x
as
Long
y
as
Long
End
Type
'
private
Declare
Function
GetPixel
Lib
"gdi32"
(byval
hdc
as
Long,
_
byval
x
as
Long,
byval
y
as
Long)
as
Long
private
Declare
Function
GetCursorPos
Lib
"user32"
(lpPoint
as
POINTAPI)
as
Long
private
Declare
Function
GetWindowDC
Lib
"user32"
(byval
hwnd
as
Long)
as
Long
'
private
Sub
Form_Load()
Timer1.Interval
=
100
End
Sub
'
private
Sub
Timer1_Timer()
Dim
tPOS
as
POINTAPI
Dim
sTmp
as
string
Dim
lColor
as
Long
Dim
lDC
as
Long
'
lDC
=
GetWindowDC(0)
Call
GetCursorPos(tPOS)
lColor
=
GetPixel(lDC,
tPOS.x,
tPOS.y)
Label2.BackColor
=
lColor
'
sTmp
=
Right$("000000"
&
Hex(lColor),
6)
Caption
=
"R:"
&
Right$(sTmp,
2)
&
"
G:"
&
mid$(sTmp,
3,
2)
&
"
B:"
&
Left$(sTmp,
2)
End
Sub
至于获取当前窗口,可以使用
Public
Declare
Function
GetForegroundWindow
Lib
"user32"
()
As
Long
获取当前活动窗体的句柄,再使用GetWindowText的API能获取到相应的标题啦!
Public
Declare
Function
GetForegroundWindow
Lib
"user32"
()
As
Long
Public
Declare
Function
SendMessage
Lib
"user32"
Alias
"SendMessageA"
(ByVal
hwnd
As
Long,
ByVal
wMsg
As
Long,
ByVal
wParam
As
Long,
lParam
As
Any)
As
Long
Public
Const
WM_GETTEXT
=
&HD
Public
Function
GetWin()
As
String
Dim
tmp
As
Long
Dim
iLen
As
Long
Dim
Txt
As
String
tmp
=
GetForegroundWindow
Txt
=
String(255,
Chr(0))
iLen
=
SendMessage(tmp,
WM_GETTEXT,
Len(Txt),
ByVal
Txt)
Txt
=
Left(Txt,
iLen)
GetWin=Txt
End
Function
以上代码是获取当前窗体的标题代码!(这里没使用GetWindowText的API)
程序依靠调用外部shutdown实现关机。本例中定时100秒。槐判枯将冲春100改为0,实现立铅洞即关机。
方法一:
#include
#include
void
main(void)
{
system("shutdown.exe
-s
-t
100")
getch()
system("shutdown.exe
-a")
}
方法二:
打开txt文档,输入
shutdown
-s
-t
100
保存。将文件扩展名保存为.bat。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)