wyj7485 发表于 2007-1-30 15:37:00

声明: <br/>Public&nbsp;Declare&nbsp;Function&nbsp;GetWindowLong&nbsp;Lib&nbsp;"user32"&nbsp;Alias&nbsp;"GetWindowLongA"&nbsp;(ByVal&nbsp;hwnd&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;nIndex&nbsp;As&nbsp;Long)&nbsp;As&nbsp;Long <br/>此函数用来获取指定窗口的某方面"结构数据"信息。&nbsp;函数返回值由参数nIndex来决定要返回哪个方面的当前值。若出错则返回0。 <br/>调用如:Const&nbsp;GWL_STYLE&nbsp;=&nbsp;-16 <br/>Private&nbsp;Sub&nbsp;Command1_Click() <br/>X&nbsp;=&nbsp;GetWindowLongA(Form1.hwnd,&nbsp;GWL_STYLE) <br/>Print&nbsp;X <br/>End&nbsp;Sub <br/>参数: <br/>hwnd:&nbsp;Long,欲获取信息的窗口的句柄&nbsp; <br/>nIndex:&nbsp;Long,欲取回此窗口哪方面的信息,可以是下述任何一个常数:&nbsp; <br/>GWL_EXSTYLE&nbsp;扩展窗口样式&nbsp; <br/>(可能包含有:WS_EX_TOOLWINDOW=&amp;H80标题栏缩小可变大小,相当于BorderStyle=5;&nbsp;WS_EX_TRANSPARENT=&amp;H20&amp;隐藏绘图区,但显示其上的子控件。有意思。等,别的我也不太清楚,好象要去查MSDN才可查到)&nbsp; <br/>GWL_STYLE&nbsp;窗口样式&nbsp; <br/>(可能值有:WS_VSCROLL=?垂直滚动条,WS_HSCROLL=?水平滚动条, <br/>WS_MAXIMIZEBOX=?标题栏右边最大化纽,WS_MINIMIZEBOX=?最小化纽等等) <br/>GWL_WNDPROC&nbsp;该窗口的窗口函数的地址&nbsp; <br/>GWL_HINSTANCE&nbsp;拥有窗口的实例的句柄&nbsp; <br/>GWL_HWNDPARENT&nbsp;该窗口之父的句柄。不要用SetWindowWord来改变这个值&nbsp; <br/>GWL_ID&nbsp;对话框中一个子窗口的标识符&nbsp; <br/>GWL_USERDATA&nbsp;含义由应用程序规定&nbsp; <br/>DWL_DLGPROC&nbsp;这个窗口的对话框函数地址&nbsp; <br/>DWL_MSGRESULT&nbsp;在对话框函数中处理的一条消息返回的值&nbsp; <br/>DWL_USER&nbsp;含义由应用程序规定&nbsp; <br/>----- <br/>SetWindowLongA函数:为窗口设置窗口结构信息 <br/>常用此函数来动态地设置窗口的风格(如样式,滚动条等等)。即不在属性窗口中设置。而在API中设置。&nbsp; <br/>声明: <br/>Public&nbsp;Declare&nbsp;Function&nbsp;SetWindowLong&nbsp;Lib&nbsp;"user32"&nbsp;Alias&nbsp;"SetWindowLongA"&nbsp;(ByVal&nbsp;hwnd&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;nIndex&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;dwNewLong&nbsp;As&nbsp;Long)&nbsp;As&nbsp;Long <br/>调用如: <br/>Public&nbsp;Const&nbsp;WS_EX_TOOLWINDOW&nbsp;=&nbsp;&amp;H80 <br/>lStyle&nbsp;=&nbsp;WS_EX_TOOLWINDOW <br/>lRet&nbsp;=&nbsp;SetWindowLongA(Me.hwnd,&nbsp;GWL_EXSTYLE,&nbsp;GetWindowLongA(Me.hwnd,&nbsp;GWL_EXSTYLE)&nbsp;Or&nbsp;lStyle)&nbsp;注:这里有1个Or"或"操作。为何要用OR呢?这是因为一个窗口的GWL_EXSTYLE包含了多项设置值的和(如同时可能有滚动条,标题栏等值的组合,如为262400),用or就可只改动其部分值,而保留其他方面原设置不变。 <br/>参数: <br/>hwnd&nbsp;Long,欲设置信息的窗口的句柄&nbsp; <br/>nIndex&nbsp;Long,请参考GetWindowLong函数的nIndex参数的说明&nbsp; <br/>dwNewLong&nbsp;Long,由nIndex指定的窗口信息的新值&nbsp; <br/>------- <br/>GetWindowWord函数:获得指定窗口的结构信息(返回字值)&nbsp; <br/>该函数从附加窗口内存中返回字值。与GetWindowLong相似。&nbsp; <br/>声明:&nbsp; <br/>Declare&nbsp;Function&nbsp;GetWindowWord&nbsp;Lib&nbsp;"user32"&nbsp;Alias&nbsp;"GetWindowWord"&nbsp;(ByVal&nbsp;hwnd&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;nIndex&nbsp;As&nbsp;Long)&nbsp;As&nbsp;Integer <br/>调用如: <br/>Const&nbsp;GWL_HWNDPARENT&nbsp;=&nbsp;-8 <br/>parent&nbsp;=&nbsp;GetWindowWord(Form1.hwnd,&nbsp;GWL_HWNDPARENT)&nbsp; <br/>这里调用后parent返回Form1的上一级父窗口的句柄。再例如command1在form1中,&nbsp;x=GetWindowWord(command1.hwnd,GWL_HWNDPARENT)返回的x就等于form1.hwnd. <br/>参数见GetWindowLong. <br/>====== <br/>获得指定窗口所属的窗口类名称:GetClassNameA函数 <br/>声明: <br/>Declare&nbsp;Function&nbsp;GetClassName&nbsp;Lib&nbsp;"user32"&nbsp;Alias&nbsp;"GetClassNameA"&nbsp;(ByVal&nbsp;hwnd&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;lpClassName&nbsp;As&nbsp;String,&nbsp;ByVal&nbsp;nMaxCount&nbsp;As&nbsp;Long)&nbsp;As&nbsp;Long <br/>调用如--求Form1所属的窗口类的名称&nbsp;: <br/>pclass&nbsp;=&nbsp;Space(31)&nbsp; <br/>nlen&nbsp;=&nbsp;GetClassNameA(form1.hwnd,&nbsp;pclass,&nbsp;32) <br/>pclass&nbsp;=&nbsp;Left(pclass,&nbsp;nlen) <br/>第1个参数为某窗口句柄。第2个参数为字符串缓冲区,第3个参数为缓冲区长度。 <br/>参数lpClassName返回值为窗口类名称字符串,如上例为ThunderFormDC类。 <br/>函数返回值为类名字符串长度。如上面nlen为13。 <br/>==== <br/>创建不规则窗口之"圆角矩形":SetWindowRgn结合CreateRoundRectRgn函数 <br/><cc></cc>

wyj7485 发表于 2007-1-30 15:40:00

SetWindowRgn函数用于创建各种几何形状的窗口,声明前面已有,为: <br/>Public&nbsp;Declare&nbsp;Function&nbsp;SetWindowRgn&nbsp;Lib&nbsp;"user32"&nbsp;Alias&nbsp;"SetWindowRgn"&nbsp;(ByVal&nbsp;hWnd&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;hRgn&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;bRedraw&nbsp;As&nbsp;Boolean)&nbsp;As&nbsp;Long <br/>第1个参数为窗口句柄,第2个参数为几何形状区域句柄,第3个参数为是否立即重画。&nbsp; <br/>函数CreateRoundRectRgn为创建圆角矩形,函数返回创建的圆角区域句柄。声明: <br/>Public&nbsp;Declare&nbsp;Function&nbsp;CreateRoundRectRgn&nbsp;Lib&nbsp;"gdi32"&nbsp;(ByVal&nbsp;X1&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;Y1&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;X2&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;Y2&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;X3&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;Y3&nbsp;As&nbsp;Long)&nbsp;As&nbsp;Long <br/>参数就是三个(X,Y)值,X1,Y1为左上角坐标,因为是用窗口自身坐标系统来度量,所以左上角坐标一般为0,0(注:FORM窗体为scaleleft,scaletop),X2,Y2为右下角坐标(注意不一定是直接的width或scalewidth,要用scaleleft+scalewidth才是"右下角"横坐标):如果是控件,就是其width,height的值,而如果是窗体,要加上其scaleleft,scaletop <br/>得到右下角坐标值。X3,Y3表示圆角的大小。X3的取值范围是0(无圆角)到矩形宽(width或scalewidth,全圆),Y3的取值范围是0(无圆角)到矩形高(height或scaleheight,全圆),常乘以一个0至1的单精度数来表示。例如: <br/>x&nbsp;=&nbsp;SetWindowRgn(form1.hwnd,&nbsp;CreateRoundRectRgn(form1.ScaleLeft,&nbsp;form1.ScaleTop,&nbsp;form1.ScaleWidth&nbsp;+&nbsp;form1.ScaleLeft,&nbsp;form1.ScaleHeight&nbsp;+&nbsp;form1.ScaleTop,&nbsp;form1.ScaleWidth&nbsp;*&nbsp;0.6,&nbsp;form1.ScaleHeight&nbsp;*&nbsp;0.6),&nbsp;True) <br/>最后说明一下,还有一个API函数可直接画圆角矩形,就是RoundRect函数。声明: <br/>Declare&nbsp;Function&nbsp;RoundRect&nbsp;Lib&nbsp;"gdi32"&nbsp;(ByVal&nbsp;hdc&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;X1&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;Y1&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;X2&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;Y2&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;X3&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;Y3&nbsp;As&nbsp;Long)&nbsp;As&nbsp;Long <br/>其中参数hDC是窗口的设备场景句柄。三个(X,Y)和CreateRoundRectRgn的是一样的,分别为左上角,右下角坐标和圆角大小。 <br/>====== <br/>获取本程序活动窗口的句柄:GetActiveWindow函数 <br/>声明: <br/>Declare&nbsp;Function&nbsp;GetActiveWindow&nbsp;Lib&nbsp;"user32"()&nbsp;As&nbsp;Long <br/>很简单,函数返回值为当前本程序活动窗口句柄。调用如:x=GetActiveWindow,这个函数不如GetForegroundWindow函数,建议用下面的: <br/>---- <br/>获取屏幕上当前活动窗口的句柄:GetForegroundWindow函数 <br/>这个函数功能更强大,能获取前台应用程序的活动窗口句柄。声明: <br/>Declare&nbsp;Function&nbsp;GetForegroundWindow&nbsp;Lib&nbsp;"user32"&nbsp;()&nbsp;As&nbsp;Long <br/>函数返回值为当前屏幕上活动窗口的句柄,如:x=GetForegroundWindow。 <br/>----- <br/>判断一个窗口是否是活动窗口:IsWindowEnabled函数 <br/>声明: <br/>Declare&nbsp;Function&nbsp;IsWindowEnabled&nbsp;Lib&nbsp;"user32"(ByVal&nbsp;hwnd&nbsp;As&nbsp;Long)&nbsp;As&nbsp;Long&nbsp; <br/>参数hwnd是待检测窗口句柄。 <br/>调用如:x=IsWindowEnabled(Form1.hwnd),函数返回值若非0表示为活动窗口,返回0表示为失效窗口。 <br/>---- <br/>禁止任务条--任务条所属窗口类为"Shell_traywnd",用FindWindowA函数去查,如下:&nbsp;TaskBarhWnd&nbsp;=&nbsp;FindWindowA("Shell_traywnd",&nbsp;""),然后用EnableWindow函数:&nbsp;lxn&nbsp;=&nbsp;EnableWindow(TaskBarhWnd,0)就可以了。<cc></cc>

StartMe 发表于 2007-1-30 23:32:00

收藏,谢谢!辛苦!

gzmkshjsh 发表于 2007-1-31 12:02:00

好东西,版主辛苦了。谢谢!!

wyj7485 发表于 2007-2-2 08:34:00

<p>Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long<br/>Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long<br/>Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long<br/>Private Const WS_EX_LAYERED = &amp;H80000<br/>Private Const GWL_EXSTYLE = (-20)<br/>Private Const LWA_ALPHA = &amp;H2<br/>Private Const LWA_COLORKEY = &amp;H1</p><p>Private Sub Form_Load()</p><p>&nbsp;&nbsp;&nbsp; Dim rtn As Long<br/>&nbsp;&nbsp;&nbsp; rtn = GetWindowLong(hwnd, GWL_EXSTYLE)<br/>&nbsp;&nbsp;&nbsp; rtn = rtn Or WS_EX_LAYERED<br/>&nbsp;&nbsp;&nbsp; SetWindowLong hwnd, GWL_EXSTYLE, rtn<br/>&nbsp;&nbsp;&nbsp; SetLayeredWindowAttributes hwnd, 0, 200, LWA_ALPHA<br/>&nbsp;&nbsp;&nbsp; <br/>End Sub</p>
页: 1 [2]
查看完整版本: VB做外挂编程入门(转)