VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 可以直接用API改变textbox的扩展样式
发表评论(0)作者:, 平台:, 阅读:10030, 日期:2000-09-19
大家网
可以直接用API改变textbox的扩展样式

VERSION 5.00

Begin VB.Form Form1

Caption = "Form1"

ClientHeight = 6135

ClientLeft = 165

ClientTop = 735

ClientWidth = 7080

LinkTopic = "Form1"

ScaleHeight = 6135

ScaleWidth = 7080

StartUpPosition = 3 'Windows Default

Begin VB.CommandButton Command2

Caption = "Command2"

Height = 375

Left = 4800

TabIndex = 4

Top = 5040

Width = 1455

End

Begin VB.PictureBox Pic1

BorderStyle = 0 'None

Height = 495

Left = 960

ScaleHeight = 495

ScaleWidth = 2655

TabIndex = 5

Top = 2880

Width = 2655

End

Begin VB.Timer Timer1

Interval = 10

Left = 240

Top = 3120

End

Begin VB.CheckBox Check1

Caption = "选择,再看按钮的文字,然后不要选择"

Height = 855

Left = 960

TabIndex = 1

Top = 3600

Width = 4575

End

Begin VB.CommandButton Command1

Caption = "歪歪的VB技巧演示"

Height = 1695

Left = 360

TabIndex = 0

Top = 960

Width = 5295

End

Begin VB.TextBox Text1

Height = 495

Left = 1080

MultiLine = -1 'True

TabIndex = 3

Top = 5040

Width = 2415

End

Begin VB.Label Label1

Caption = "Label1"

Height = 375

Left = 600

TabIndex = 2

Top = 240

Width = 1215

End

Begin VB.Menu mnuChange

Caption = "改变样式(&C)"

Begin VB.Menu mnuFlash

Caption = "FlashWindow(&F)"

End

End

End

Attribute VB_Name = "Form1"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

'这是我机子中的一个例子,包含了你说的那个功能,我想就没必要再改了,凑合着看看应该可以吧:)

Private Declare Function 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) As Long

'Alignment constants

Private Const BS_CENTER& = &H300&

Private Const BS_LEFT& = &H100&

Private Const BS_RIGHT& = &H200&

Private Const BS_TOP& = &H400&

Private Const GWL_STYLE& = (-16)

Private Const GWL_EXSTYLE = (-20)

Private Const WS_EX_TRANSPARENT = &H20&

Private Const WS_THICKFRAME = &H40000

Private Const WS_BORDER = &H400000

Private Const WS_EX_CLIENTEDGE = &H200&

Dim FlashYn As Boolean, Yn As Boolean



'API Calls

Private Declare Function GetWindowLong& Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long)

Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)

Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long

Const SWP_DRAWFRAME = &H20

Const SWP_NOMOVE = &H2

Const SWP_NOSIZE = &H1

Const SWP_NOZORDER = &H4

Const SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE


Private Sub Check1_Click()

'Declare Variables

Dim tmpValue&, ret&

Dim Align&

'Check if the state is checked

If Check1.Value = Checked Then 'Yes


fAlignment& = BS_LEFT

tmpValue& = GetWindowLong&(Command1.hwnd, GWL_STYLE) And Not BS_RIGHT

ret& = SetWindowLong&(Command1.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)

Command1.Refresh

Else 'No

fAlignment& = BS_CENTER

tmpValue& = GetWindowLong&(Command1.hwnd, GWL_STYLE) And Not BS_RIGHT Or BS_LEFT

ret& = SetWindowLong&(Command1.hwnd, GWL_STYLE, tmpValue& Or fAlignment&)

Command1.Refresh

End If

End Sub




Private Sub Command2_Click()

'Declare Variables

Dim tmpValue&, ret&

Dim Align&

'Check if the state is checked

tmpValue& = (GetWindowLong&(Text1.hwnd, GWL_EXSTYLE)) 'Or WS_EX_CLIENTEDGE) 'And Not WS_BORDER

ret& = SetWindowLong&(Text1.hwnd, GWL_EXSTYLE, tmpValue&)


tmpValue& = (GetWindowLong&(Text1.hwnd, GWL_STYLE) Or WS_THICKFRAME) 'And Not WS_BORDER

ret& = SetWindowLong&(Text1.hwnd, GWL_STYLE, tmpValue&)

SetWindowPos Text1.hwnd, Me.hwnd, 0, 0, 0, 0, SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOZORDER Or SWP_DRAWFRAME

Text1.Refresh

End Sub


' -> VB WorkShop 2000

Private Sub Form_Load()

Dim tmpValue&, ret&

FlashYn = False: Yn = False

'tmpValue& = GetWindowLong&(Me.hwnd, GWL_EXSTYLE)

'ret& = SetWindowLong&(Me.hwnd, GWL_EXSTYLE, tmpValue& Or WS_EX_TRANSPARENT)

tmpValue& = GetWindowLong&(Check1.hwnd, GWL_EXSTYLE)

ret& = SetWindowLong&(Check1.hwnd, GWL_EXSTYLE, tmpValue& Or WS_EX_TRANSPARENT)

Command1.Refresh

Check1.Refresh

Me.Refresh


End Sub


Private Sub mnuFlash_Click()

FlashYn = True

End Sub


Private Sub Text11_Change()


End Sub


Private Sub Timer1_Timer()

If (FlashYn = True) Then FlashWindow Me.hwnd, Not Yn

End Sub