Cambiar el tamaño de un Picture usando el API de Windows (Visual Basic)
Visual Basic 9 noviembre 2007
Redimensionar un Picture usando el API de Windows
Funciones usadas: GetWindowLong, SetWindowLong y SetWindowPos
El ejemplo tiene en el Form los siguientes objetos:
Label1() y Text1() en cada PicColumn()
Label2() en el form
Option Explicit
'Prueba para redimensionar Pictures
Dim NumColumnas As Integer
Dim NumFilas As Integer
Dim bIniciando As Boolean
#If Win32 Then
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
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
#Else
Private Declare Function GetWindowLong Lib "User" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Long
Private Declare Function SetWindowLong Lib "User" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "User" (ByVal hwnd%, ByVal hWndInsertAfter%, ByVal X%, ByVal Y%, ByVal cX%, ByVal cY%, ByVal wFlags%) As Integer
#End If
Const GWL_STYLE = (-16)
Const WS_THICKFRAME = &H40000
Const WS_CHILD = &H40000000
Const SWP_DRAWFRAME = &H20
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const SWP_NOZORDER = &H4
Private Sub Form_Load()
Dim Style as Long
bIniciando = True
Style = GetWindowLong(PicColum(0).hwnd, GWL_STYLE)
Style = Style& Or WS_THICKFRAME
Style = SetWindowLong(PicColum(0).hwnd, GWL_STYLE, Style)
Style = SetWindowPos(PicColum(0).hwnd, _
Me.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or _
SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME)
NumFilas = 2
Load Text1(1)
Set Text1(1).Container = PicColum(0)
Text1(1).Visible = True
Text1(1).Top = Text1(0).Top + Text1(0).Height
Load Label2(1)
Label2(1).Visible = True
Label2(1).Top = Label2(0).Top + Label2(0).Height
Label2(1) = “Fila 2″
NumColumnas = 1
bIniciando = False
End Sub
Private Sub PicColum_Resize(Index As Integer)
Dim k As Integer
Dim i As Integer
If bIniciando Then Exit Sub
‘ajustar el ancho del Label y los texts
Label1(Index).Width = PicColum(Index).Width
For i = 0 To NumFilas – 1
k = i * NumColumnas + Index
Text1(k).Width = PicColum(Index).Width
Next
PicColum(0).Left = Label2(0).Width
For i = 0 To NumColumnas – 1
If i > 0 Then
PicColum(i).Left = PicColum(i – 1).Left + PicColum(i – 1).Width
End If
PicColum(i).Top = 0
Next
End Sub
Vota este artículo:
Posts anterior y posterior:
Posts Relacionados:
- Previo: « Mover y soltar controles con Drag & Drop (Visual Basic)
- Siguiente: Métodos para usar el CommonDialog de Visual Basic »


Comentarios Recientes