Visual Basic Foro
Programación => Visual Basic 6 => Mensaje iniciado por: coco en Marzo 06, 2013, 02:53:14 am
-
Hola a todos!
Solucion: USAR BorderStyle = 3!!!!
Estaba usando el codigo que una vez publico Lea, pero resulta que en W7 no funciona ni a palos.
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) 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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const WS_EX_APPWINDOW = &H40000
Private Const GWL_EXSTYLE = -20
Public Sub AddToTaskBar(ByVal hwnd As Long)
Dim lStyle As Long
Dim lResult As Long
Dim lHook As Long
Dim lTrayhWnd As Long
Dim lTBhWnd As Long
lStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
lResult = SetWindowLong(hwnd, GWL_EXSTYLE, lStyle Or WS_EX_APPWINDOW)
lHook = RegisterWindowMessage("SHELLHOOK")
lTrayhWnd = FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString)
If lTrayhWnd Then
lTBhWnd = FindWindowEx(lTrayhWnd, 0, "RebarWindow32", vbNullString)
If lTBhWnd Then
lTBhWnd = FindWindowEx(lTBhWnd, 0, "MSTaskSwWClass", vbNullString)
If lTBhWnd Then
lResult = PostMessage(lTBhWnd, lHook, 1, ByVal hwnd)
End If
End If
End If
End Sub
Lo segui con el debug, y encuentra todas las ventanas, y llega a postear el mensaje (devuelve 1 el postmessage, lo cual significa S_OK), pero la ventana no aparece ni a ganchos en el taskbar.
Alguna sugerencia?
Gracias!
-
Hola coco, ami me aparece, osea no se si es que vos queres hacer un setparent, (hay una ventana mas MSTaskListWClass pero parece que da lo mismo)
por las dudas proba con asi con un Picture1
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndChildAfter As Long, ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) 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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Const WS_EX_APPWINDOW = &H40000
Private Const GWL_EXSTYLE = -20
Public Sub AddToTaskBar(ByVal hwnd As Long)
Dim lStyle As Long
Dim lResult As Long
Dim lHook As Long
Dim lTrayhWnd As Long
Dim lTBhWnd As Long
Dim lTaskList As Long
lStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
lResult = SetWindowLong(hwnd, GWL_EXSTYLE, lStyle Or WS_EX_APPWINDOW)
lHook = RegisterWindowMessage("SHELLHOOK")
lTrayhWnd = FindWindowEx(0, 0, "Shell_TrayWnd", vbNullString)
If lTrayhWnd Then
lTBhWnd = FindWindowEx(lTrayhWnd, 0, "RebarWindow32", vbNullString)
If lTBhWnd Then
lTBhWnd = FindWindowEx(lTBhWnd, 0, "MSTaskSwWClass", vbNullString)
If lTBhWnd Then
lTaskList = FindWindowEx(lTBhWnd, 0, "MSTaskListWClass", vbNullString)
If lTaskList Then
lResult = PostMessage(lTaskList, lHook, 1, ByVal hwnd)
SetParent hwnd, lTaskList
End If
End If
End If
End If
End Sub
Private Sub Form_Load()
Picture1.Move 0, 50
AddToTaskBar Picture1.hwnd
End Sub
Private Sub Picture1_Click()
Unload Me
End Sub
-
elea, yo lo que tengo es un formulario modal, pero no le paso ningun parametro al owner (que seria el parent) y como sabras, no aparece en el taskbar. la idea es que aparezca!
alguna idea?
-
no se si entiendo bien, probablemente no. pero vos queres decir que disparas un formulario modal por ej. Form2.show vbmodal, y queres que este aparezca en la barra?
vb de por si lo quita en este caso, quizas lo mas conveniente sea hookear pero no estoy muy seguro.
una forma mas fácil es algo así,
form1
Option Explicit
Private Sub Command1_Click()
Form2.Show vbModal
End Sub
form2
Private Const WS_EX_APPWINDOW As Long = &H40000
Private Const GWL_EXSTYLE As Long = -20
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Dim bUnaVez As Boolean
Private Sub Form_Activate()
If bUnaVez = False Then
bUnaVez = True
ShowWindow hwnd, 0
SetWindowLong hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) Or WS_EX_APPWINDOW
ShowWindow hwnd, 1
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
bUnaVez = False
End Sub
ahora no se si son ventanas creadas con apis o es otra cosa, cualquier cosa decime.
-
Estimado Coco
Quieres abrir un formulario hijo pero como Modal y que este formulario hijo se vean en el Taskbar, en mi caso lo que hago es colocar el siguiente código en el formulario hijo
Private Sub Form_Initialize()
On Error Resume Next
InitializeWindowsThemes
HookAttach
On Error GoTo 0
End Sub
Private Sub Form_Load()
On Error Resume Next
HookDetach
On Error GoTo 0
End Sub
Private Sub Form_Terminate()
On Error Resume Next
TerminateWindowsThemes
On Error GoTo 0
End Sub
Desde el formulario padre invoco al formulario hijo en forma Modal
Public Sub Show()
On Error Resume Next
Set m_objFormModal = New frmFormModal
Load m_objFormModal
m_objFormModal.Show vbModal
On Error GoTo 0
End Sub
En la siguiente URL están los módulos que necesitas, espero sea lo que necesitas.
http://www.technetperu.org/webdrive/EA64835D2E2E41F9AF85EBE06318BC87/WindowModalInTaskbar.rar (http://www.technetperu.org/webdrive/EA64835D2E2E41F9AF85EBE06318BC87/WindowModalInTaskbar.rar)
Por la noche tratare de hacer un proyecto de ejemplo y publicarlo.
Saludos desde algún lugar de Lima – Perú
-
tal cual como dice Albertomi, se ve mas lindo que andar ocultando y mostrando la ventana, yo me tome el atrevimiento de hacer algo en base a lo suyo, seguramente alberto optara por modificar la extructura, pero arriesgo a tirar algo mas cortito ya que omiti las comprovaciones de ventanas, creería que no debería aparecer otra ventana antes que esta.
Modulo
Option Explicit
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
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 Type CWPSTRUCT
lParam As Long
wParam As Long
message As Long
hwnd As Long
End Type
Private Const WH_CALLWNDPROC = 4
Private Const WS_EX_APPWINDOW = &H40000
Private Const GWL_EXSTYLE = (-20)
Private Const WM_STYLECHANGED As Long = &H7D
Private m_hHook As Long
Public Sub HookAttach()
m_hHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf AppHook, App.hInstance, App.ThreadID)
End Sub
Private Function AppHook(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim CWP As CWPSTRUCT
If idHook >= 0 Then
CopyMemory CWP, ByVal lParam, Len(CWP)
If CWP.message = WM_STYLECHANGED Then
SetWindowLong CWP.hwnd, GWL_EXSTYLE, GetWindowLong(CWP.hwnd, GWL_EXSTYLE) Or WS_EX_APPWINDOW
UnhookWindowsHookEx m_hHook
End If
End If
AppHook = CallNextHookEx(m_hHook, idHook, wParam, ByVal lParam)
End Function
Form
Option Explicit
Private Sub Command1_Click()
HookAttach
Form2.Show vbModal
End Sub
Saludos.
-
lea, lo probe recien y no funca. lo llamo asi:
With frmFirstConfig
Call HookAttach
Call .Show(vbModal)
End With
y no aparece nada en el taskbar...
tambien probe lo de Albertomi, y pasa lo mismo.
el form en cuestion tiene de borderstyle FixedSingle, y es llamado desde un modulo (desde el Main).
Gracias!
-
La verdad no se porque pero ami si me aparece, yo estoy en W7
(http://s21.postimage.org/pcjikxsnn/Image1.jpg) (http://postimage.org/image/pcjikxsnn/)
esperemos aver que dice Albertomi
en el ultimo de los casos, pone un form común lo llamas creas un bucle hasta que este se descargue y listo :D
-
Ya esta, el problema es el siguiente: Si tenes Borderstyle 1, no va. Con Borderstyle 3 va como piña!!! Gracias!