PDA

View Full Version : API problem 2002 to 2003



Remalay
11-14-2006, 02:52 AM
Guys,
Being VERY unfamilair with API I have now come to a block in striving to find a resolution to my problem.

Using info from an exisiting forum thread I have amended to suit and have the following;

Option Explicit

Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Integer, _
ByVal lParam As Long) As Long
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Private Const WM_SETICON = &H80
Private Const ICON_BIG = 1
Private Const ICON_SMALL = 0

Private Sub cbnChange_Click()
ChangeIcon " NEW TITLE :", (Sheet1.Image1.Picture.Handle)

End Sub
Private Sub cbnRestore_Click()
ChangeIcon Empty, 0
End Sub

Function ChangeIcon(strAppName As String, Optional ByVal Icon As Long = 0&)
Dim strIconPath As String
Dim lngXLHwnd As Long

application.ScreenUpdating = False

Windows(ThisWorkbook.Name).WindowState = xlNormal

' change the icon for the workbook window
ChangeWindowIcon WorkbookHandle(ThisWorkbook.Name), Icon
' change the icon for the excel's window
ChangeWindowIcon FindWindowEx(GetDesktopWindow, 0&, "XLMAIN", vbNullString), Icon

Windows(ThisWorkbook.Name).WindowState = xlMaximized
Windows(ThisWorkbook.Name).WindowState = xlNormal
Windows(ThisWorkbook.Name).WindowState = xlMaximized

application.ScreenUpdating = True
application.Caption = strAppName

End Function
Sub ChangeWindowIcon(Whnd As Long, Icon)
SendMessage Whnd, WM_SETICON, ICON_SMALL, Icon
SendMessage Whnd, WM_SETICON, ICON_BIG, Icon
End Sub
Function WorkbookHandle(strWBName As String) As Long
Dim dWnd As Long, hWnd As Long, mWnd As Long, cWnd As Long

dWnd = GetDesktopWindow
hWnd = FindWindowEx(dWnd, 0&, "XLMAIN", vbNullString)
mWnd = FindWindowEx(hWnd, 0&, "XLDESK", vbNullString)

While mWnd <> 0 And cWnd = 0
cWnd = FindWindowEx(mWnd, 0&, "EXCEL7", strWBName)
hWnd = FindWindowEx(dWnd, hWnd, "XLMAIN", vbNullString)
mWnd = FindWindowEx(hWnd, 0&, "XLDESK", vbNullString)
Wend

If cWnd > 0 Then
WorkbookHandle = cWnd
End If
End Function


This works fine within Excel 2002 SP2. However, when used on an Excel 2003 SP2 machine, whilst the Application icon changes, ther workbook icon remains as default.:dunno

Any ideas/suggestions/pointers?

thanks in advance.

remalay

Remalay
12-05-2006, 05:56 AM
:dunno