wyj7485 发表于 2007-1-30 15:37:00
声明: <br/>Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long <br/>此函数用来获取指定窗口的某方面"结构数据"信息。 函数返回值由参数nIndex来决定要返回哪个方面的当前值。若出错则返回0。 <br/>调用如:Const GWL_STYLE = -16 <br/>Private Sub Command1_Click() <br/>X = GetWindowLongA(Form1.hwnd, GWL_STYLE) <br/>Print X <br/>End Sub <br/>参数: <br/>hwnd: Long,欲获取信息的窗口的句柄 <br/>nIndex: Long,欲取回此窗口哪方面的信息,可以是下述任何一个常数: <br/>GWL_EXSTYLE 扩展窗口样式 <br/>(可能包含有:WS_EX_TOOLWINDOW=&H80标题栏缩小可变大小,相当于BorderStyle=5; WS_EX_TRANSPARENT=&H20&隐藏绘图区,但显示其上的子控件。有意思。等,别的我也不太清楚,好象要去查MSDN才可查到) <br/>GWL_STYLE 窗口样式 <br/>(可能值有:WS_VSCROLL=?垂直滚动条,WS_HSCROLL=?水平滚动条, <br/>WS_MAXIMIZEBOX=?标题栏右边最大化纽,WS_MINIMIZEBOX=?最小化纽等等) <br/>GWL_WNDPROC 该窗口的窗口函数的地址 <br/>GWL_HINSTANCE 拥有窗口的实例的句柄 <br/>GWL_HWNDPARENT 该窗口之父的句柄。不要用SetWindowWord来改变这个值 <br/>GWL_ID 对话框中一个子窗口的标识符 <br/>GWL_USERDATA 含义由应用程序规定 <br/>DWL_DLGPROC 这个窗口的对话框函数地址 <br/>DWL_MSGRESULT 在对话框函数中处理的一条消息返回的值 <br/>DWL_USER 含义由应用程序规定 <br/>----- <br/>SetWindowLongA函数:为窗口设置窗口结构信息 <br/>常用此函数来动态地设置窗口的风格(如样式,滚动条等等)。即不在属性窗口中设置。而在API中设置。 <br/>声明: <br/>Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long <br/>调用如: <br/>Public Const WS_EX_TOOLWINDOW = &H80 <br/>lStyle = WS_EX_TOOLWINDOW <br/>lRet = SetWindowLongA(Me.hwnd, GWL_EXSTYLE, GetWindowLongA(Me.hwnd, GWL_EXSTYLE) Or lStyle) 注:这里有1个Or"或"操作。为何要用OR呢?这是因为一个窗口的GWL_EXSTYLE包含了多项设置值的和(如同时可能有滚动条,标题栏等值的组合,如为262400),用or就可只改动其部分值,而保留其他方面原设置不变。 <br/>参数: <br/>hwnd Long,欲设置信息的窗口的句柄 <br/>nIndex Long,请参考GetWindowLong函数的nIndex参数的说明 <br/>dwNewLong Long,由nIndex指定的窗口信息的新值 <br/>------- <br/>GetWindowWord函数:获得指定窗口的结构信息(返回字值) <br/>该函数从附加窗口内存中返回字值。与GetWindowLong相似。 <br/>声明: <br/>Declare Function GetWindowWord Lib "user32" Alias "GetWindowWord" (ByVal hwnd As Long, ByVal nIndex As Long) As Integer <br/>调用如: <br/>Const GWL_HWNDPARENT = -8 <br/>parent = GetWindowWord(Form1.hwnd, GWL_HWNDPARENT) <br/>这里调用后parent返回Form1的上一级父窗口的句柄。再例如command1在form1中, x=GetWindowWord(command1.hwnd,GWL_HWNDPARENT)返回的x就等于form1.hwnd. <br/>参数见GetWindowLong. <br/>====== <br/>获得指定窗口所属的窗口类名称:GetClassNameA函数 <br/>声明: <br/>Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long <br/>调用如--求Form1所属的窗口类的名称 : <br/>pclass = Space(31) <br/>nlen = GetClassNameA(form1.hwnd, pclass, 32) <br/>pclass = Left(pclass, 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 Declare Function SetWindowRgn Lib "user32" Alias "SetWindowRgn" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long <br/>第1个参数为窗口句柄,第2个参数为几何形状区域句柄,第3个参数为是否立即重画。 <br/>函数CreateRoundRectRgn为创建圆角矩形,函数返回创建的圆角区域句柄。声明: <br/>Public Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As 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 = SetWindowRgn(form1.hwnd, CreateRoundRectRgn(form1.ScaleLeft, form1.ScaleTop, form1.ScaleWidth + form1.ScaleLeft, form1.ScaleHeight + form1.ScaleTop, form1.ScaleWidth * 0.6, form1.ScaleHeight * 0.6), True) <br/>最后说明一下,还有一个API函数可直接画圆角矩形,就是RoundRect函数。声明: <br/>Declare Function RoundRect Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long <br/>其中参数hDC是窗口的设备场景句柄。三个(X,Y)和CreateRoundRectRgn的是一样的,分别为左上角,右下角坐标和圆角大小。 <br/>====== <br/>获取本程序活动窗口的句柄:GetActiveWindow函数 <br/>声明: <br/>Declare Function GetActiveWindow Lib "user32"() As Long <br/>很简单,函数返回值为当前本程序活动窗口句柄。调用如:x=GetActiveWindow,这个函数不如GetForegroundWindow函数,建议用下面的: <br/>---- <br/>获取屏幕上当前活动窗口的句柄:GetForegroundWindow函数 <br/>这个函数功能更强大,能获取前台应用程序的活动窗口句柄。声明: <br/>Declare Function GetForegroundWindow Lib "user32" () As Long <br/>函数返回值为当前屏幕上活动窗口的句柄,如:x=GetForegroundWindow。 <br/>----- <br/>判断一个窗口是否是活动窗口:IsWindowEnabled函数 <br/>声明: <br/>Declare Function IsWindowEnabled Lib "user32"(ByVal hwnd As Long) As Long <br/>参数hwnd是待检测窗口句柄。 <br/>调用如:x=IsWindowEnabled(Form1.hwnd),函数返回值若非0表示为活动窗口,返回0表示为失效窗口。 <br/>---- <br/>禁止任务条--任务条所属窗口类为"Shell_traywnd",用FindWindowA函数去查,如下: TaskBarhWnd = FindWindowA("Shell_traywnd", ""),然后用EnableWindow函数: lxn = 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 = &H80000<br/>Private Const GWL_EXSTYLE = (-20)<br/>Private Const LWA_ALPHA = &H2<br/>Private Const LWA_COLORKEY = &H1</p><p>Private Sub Form_Load()</p><p> Dim rtn As Long<br/> rtn = GetWindowLong(hwnd, GWL_EXSTYLE)<br/> rtn = rtn Or WS_EX_LAYERED<br/> SetWindowLong hwnd, GWL_EXSTYLE, rtn<br/> SetLayeredWindowAttributes hwnd, 0, 200, LWA_ALPHA<br/> <br/>End Sub</p>
页:
1
[2]