Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alt + TAB Icon and a maximize button. 1

Status
Not open for further replies.

kalle82

Technical User
Apr 2, 2009
163
SE
Hi!

How do i even do to change the alt tab icon?

Im using excel 2003. I have looked into the matter but it's way beyond me using those api's...

I have added code to get a minimize button and added the userform to the windows taskbar. This was done with code I found on the net.. But I can't figure out how to add a maximize button and a new icon to the alt + tab screen.

Here's my code I have tried to put a nice structure to it.

Question is how do I CHANGE the alt tab icon, I ahve already changed the taskbar icon. Second questions how do i add a maximizebutton.

Code:
'API functions - These must be included..!
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
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetActiveWindow Lib "user32.dll" _
                                        () As Long
Private Declare Function SendMessage Lib "user32" _
                                    Alias "SendMessageA" _
                                    (ByVal hWnd As Long, _
                                     ByVal wMsg As Long, _
                                     ByVal wParam As Long, _
                                     lParam As Any) As Long
Private Declare Function DrawMenuBar Lib "user32" _
                                    (ByVal hWnd As Long) As Long

'Constants
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const GWL_EXSTYLE = (-20)
Private Const HWND_TOP = 0
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_SHOWWINDOW = &H40
Private Const WS_EX_APPWINDOW = &H40000
Private Const GWL_STYLE = (-16)
Private Const WS_MINIMIZEBOX = &H20000
Private Const SWP_FRAMECHANGED = &H20
Private Const WM_SETICON = &H80
Private Const ICON_SMALL = 0&
Private Const ICON_BIG = 1&

'HERE*S WHEN THE USERFORM ACTIVATES
Private Sub UserForm_Activate()
   AddIcon    'Add an icon on the titlebar
   AddMinimiseButton   'Add a Minimize button to Userform
   AppTasklist Me    'Add this userform into the Task bar
   
End Sub

'HERE ARE THE SUBS DOING ALL MY REQUESTS
Private Sub AddIcon()
'Add an icon on the titlebar
   Dim hWnd As Long
   Dim lngRet As Long
   Dim hIcon As Long
   
   hIcon = UserForm1.Image1.Picture.Handle
   hWnd = FindWindow(vbNullString, Me.Caption)
   lngRet = SendMessage(hWnd, WM_SETICON, ICON_SMALL, ByVal hIcon)
   lngRet = SendMessage(hWnd, WM_SETICON, ICON_BIG, ByVal hIcon)
   lngRet = DrawMenuBar(hWnd)
End Sub

Private Sub AddMinimiseButton()
'//Add a Minimize button to Userform
   Dim hWnd As Long
   hWnd = GetActiveWindow
   Call SetWindowLong(hWnd, GWL_STYLE, _
                      GetWindowLong(hWnd, GWL_STYLE) Or _
                      WS_MINIMIZEBOX)
   Call SetWindowPos(hWnd, 0, 0, 0, 0, 0, _
                     SWP_FRAMECHANGED Or _
                     SWP_NOMOVE Or _
                     SWP_NOSIZE)
End Sub

Private Sub AppTasklist(myForm)
'Add this userform into the Task bar
   Dim WStyle As Long
   Dim Result As Long
   Dim hWnd As Long

   hWnd = FindWindow(vbNullString, myForm.Caption)
   WStyle = GetWindowLong(hWnd, GWL_EXSTYLE)
   WStyle = WStyle Or WS_EX_APPWINDOW
   Result = SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, _
                         SWP_NOMOVE Or _
                         SWP_NOSIZE Or _
                         SWP_NOACTIVATE Or _
                         SWP_HIDEWINDOW)
   Result = SetWindowLong(hWnd, GWL_EXSTYLE, WStyle)
   Result = SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, _
                         SWP_NOMOVE Or _
                         SWP_NOSIZE Or _
                         SWP_NOACTIVATE Or _
                         SWP_SHOWWINDOW)
End Sub
 
The second question
- add declaration:
[tt]Private Const WS_MAXIMIZEBOX = &H10000[/tt]
- change window style:
[tt]Call SetWindowLong(hWnd, GWL_STYLE, _
GetWindowLong(hWnd, GWL_STYLE) Or WS_MAXIMIZEBOX)[/tt]





combo
 
Thanks COMBO! Worked like a charm!

I thee a manual of some sorts to be able to control the api?

Cheers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top