Modeless UserForm doesn't show on Alt+Tab.

J

Jim Luedke

I’m using Excel 2002 in Win 2000.

I'm using Stephen Bullen’s CFormChanger to beef up UserForm with
features like min/max buttons, sizeability, my own icon, etc.:

www.oaltd.co.uk

After tweaking, it works well, thanks to all you knights of the Net
(most recently Peter T.)

Now my problem is, I want it to show in the Alt+Tab dialog and it
doesn’t.

Yet at one point, it did appear there. So I might’ve broken it.

GetWindow(MyHWnd, GW_OWNER) confirms that Excel is the owner of my
UserForm. Is ownship an issue vis-a-vis Alt+Tab? (How could it be,
since an icon used to show in Alt+Tab?)

Do any other Windows properties affect Alt+Tab status?

(One wrinkle: When my icon did appear on Alt+Tab, it was not the one I
was loading (with WM_SETICON, ICON_BIG), but rather a duplicate Excel
icon. Don't know if that problem relates to my current one of no icon
showing at all.)

I don't think Excel’s “Windows in Taskbar” feature is relevant. When
you turn it on, every workbook appears on Alt+Tab, but with a
different icon--a workbook with tiny Excel ‘X’. So that looks like a
different animal.

I’ve scoured MSDN and cpearson.com, but am stuck.

Thanks much.

***
 
J

Jim Luedke

P.S.

- My UserForm shows on the Taskbar, at screen bottom, fine.

- Both UserForm and Taskbar button show my own ICON_SMALL.

***
 
J

Jim Luedke

P.P.S.:

Another test: I tried setting my icons to Excel’s own.

Getting Excel's icons is easy. (Interestingly, these return a
different number from each other):

hIcon = GetClassLong(g_ExcelHWnd, GCL_HICONSM)
hIcon = GetClassLong(g_ExcelHWnd, GCL_HICON)

Both values of hIcon work equally well in setting your small icon (my
UserForm's title bar and Taskbar button):

Call SendMessage(g_OurHWnd, WM_SETICON, ICON_SMALL, hIcon)

But once again, loading the big icon fails. Neither value of hIcon
adds (a second) Excel icon to Alt+Tab:

Call SendMessage(g_OurHWnd, WM_SETICON, ICON_BIG, hIcon)

***
 
P

Peter T

Try something along the following lines (not fully tested)

Private Sub UserForm_Resize()

If IsIconic(mFrmHwnd) Then
ShowWindow mFrmHwnd, SW_HIDE
SetWindowLong mFrmHwnd, GWL_HWNDPARENT, GetDesktopWindow
ShowWindow mFrmHwnd, SW_MINIMIZE
Else ' form being restored
If IsIconic(mAppHwnd) Then
' if XL is minimized restore it
ShowWindow mAppHwnd, SW_RESTORE
Else
' in case XL is not active window
AppActivate (Application.Caption)
End If

SetWindowLong mFrmHwnd, GWL_HWNDPARENT, mAppHwnd
End If

End Sub

' in the initialize event
mAppHwnd = FindWindow("XLMAIN", Application.Caption)

You didn't respond to my followup in your other thread, maybe you didn't see
it.

Regards,
Peter T


I’m using Excel 2002 in Win 2000.

I'm using Stephen Bullen’s CFormChanger to beef up UserForm with
features like min/max buttons, sizeability, my own icon, etc.:

www.oaltd.co.uk

After tweaking, it works well, thanks to all you knights of the Net
(most recently Peter T.)

Now my problem is, I want it to show in the Alt+Tab dialog and it
doesn’t.

Yet at one point, it did appear there. So I might’ve broken it.

GetWindow(MyHWnd, GW_OWNER) confirms that Excel is the owner of my
UserForm. Is ownship an issue vis-a-vis Alt+Tab? (How could it be,
since an icon used to show in Alt+Tab?)

Do any other Windows properties affect Alt+Tab status?

(One wrinkle: When my icon did appear on Alt+Tab, it was not the one I
was loading (with WM_SETICON, ICON_BIG), but rather a duplicate Excel
icon. Don't know if that problem relates to my current one of no icon
showing at all.)

I don't think Excel’s “Windows in Taskbar” feature is relevant. When
you turn it on, every workbook appears on Alt+Tab, but with a
different icon--a workbook with tiny Excel ‘X’. So that looks like a
different animal.

I’ve scoured MSDN and cpearson.com, but am stuck.

Thanks much.

***
 
J

Jim Luedke

Peter:

Is the other thread you mention the one where I was trying to hide the
minimized title bar of a Bullen-enhanced UserForm?

If so, I did take your advice, it works like a charm, and I did submit
my reply into that thread stating that in your code, SW_HIDE is the
thing that does the trick, but I had to comment out SW_MINIMIZE
because it un-hides the title bar again:

Private Sub UserForm_Resize()

If IsIconic(mFrmHwnd) Then
ShowWindow mFrmHwnd, SW_HIDE
' ShowWindow mFrmHwnd, SW_MINIMIZE
End If
End Sub

***

When I submitted that reply a couple days ago, it showed in the thread
fine. But looking at the thread now, you're right; I don't see my
reply.

I don't at all understand this Google interface, which is what I use.
It has a number of points of bone-headed logic. Is it their fault?

The thread has 7 entries by you & me, but the bodies of the last three
headings are suppressed. There seems to have no method to read those
messages, one of which I assume is my reply.

So big thanks for help on both.

Jim

***
 
J

Jim Luedke

Peter:

Aw, nix my last msg. I'm the one that's bone-headed, not Google.

I just discovered you *can* read the suppressed message (with link
'Individual message').

And, I now see that you're talking about your second reply, which I
indeed had not seen.

I will reply to that in that thread.

Thanks.

***
 
J

Jim Luedke

Peter:

Unbelievable. It works. Icon now shows on Alt+Tab.

***

And thanks to you, I learned a few things:

1. Window ownership (or whatever you call what GWL_HWNDPARENT sets)
seems to toggle Alt+Tab display. A window's parent may need to be the
Desktop.

2. Yep, I had to reinstate SW_MINIMIZE. Without it, the Alt+Tab icon
didn't show. That undoubtedly was the problem that started this
thread.

3. However, reinstating SW_MINIMIZE also reinstated that pesky
floating Win 3.1-style minimized title bar (if that’s the right
terminology--guess I was wrong calling it “MDI-style”). Which is what
I wanted to kill in the first place.

4. But happily, it went away again. I'm a little unsure about what
happened, but I surmise that, when Excel owned Me, it kept the
minimized title bar within its own space; whereas xferring my
parentage to Desktop invokes post-Win 3.1 behavior of hiding it at
3000,3000??

5. Finally, I really want the Alt+Tab icon to show at all times, not
just when minimized. All other apps do that, right? So I moved:

SetWindowLong(MyHWnd, GWL_HWNDPARENT, GetDesktopWindow)

amongst UserForm's startup stuff. (I actually put it in CFormChanger’s
class module.)

6. There is a residual problem:

The Alt+Tab icon isn't the icon I load (and which successfully
displays on the form and Taskbar button). It's the generic Windows
icon. If you have any ideas about that, I’d like to know. If not, I
can certainly live with it.

To summarize:

***

‘MODULE CFormChanger.
'Thanks to Steve Bullen.

‘Private Sub Class_Terminate()

‘By not xferring our parentage back to Excel on terminate, I feared we
'might be left in memory. But on exiting Excel (in fact, on just
exiting
'the workbook), we seem to be destroyed fine. So not necesary?:

‘Call SetWindowLong(MyHWnd, GWL_HWNDPARENT, ExcelHWnd)
‘End Sub

Public Property Set Form(oUserForm As Object)
‘This Bullen property--more of a method, really--is write-only.

‘(Apology: as a Delphi programmer, naked params w/out parens simply go
against God & country:)

Call SetWindowLong(MyHWnd, GWL_HWNDPARENT, GetDesktopWindow)
AddOtherGoodies ‘Min/max buttons, sizeability, etc.
End Property

Public Property Set ChangeIconTo(ByVal IconPath as String)

'Load and set ICON_SMALL and ICON_BIG.
'- ICON_SMALL displays on the U.L. corner of your window, and
' on the Taskbar button.
'- ICON_BIG displays on Alt+Tab. This has never worked for me.
End Property


‘MODULE UserForm.

Private FormChanger as CFormChanger

Private Sub UserForm_Initialize()

Set FormChanger = New CFormChanger
With FormChanger
If FindOurIcoFile(Path, ThisWorkbook.Path) Then
.ChangeIconTo = Path
End If
Set .Form = Me
'Etc.
End With
End Sub

Private Sub UserForm_Resize()
'Thanks to Peter T. in microsoft.public.excel.programming.

If IsIconic(MyHWnd) Then
Call ShowWindow(MyHWnd, SW_HIDE)
Call ShowWindow(MyHWnd, SW_MINIMIZE)
Else
If IsIconic(ExcelHWnd) Then
'If XL is minimized restore it
Call ShowWindow(ExcelHWnd, SW_RESTORE)
Else
' in case XL is not active window
Call AppActivate(Application.Caption)
End If
End If
End With
End Sub

Private Sub UserForm_Terminate()
Set FormChanger = Nothing
End Sub

'Or thereabouts.

***

So thanks again, Peter.

***
 
J

Jim Luedke

I just realized:

By changing UserForm's GWL_HWNDPARENT to the Desktop, it's the
Desktop's icon (the generic Windows icon) that shows on Alt+Tab.

It also explains why, when an icon appeared sporadically on Alt+Tab
before, it was a second Excel icon, since Excel was my parent window.

So maybe the Q is:

Can you show an icon other than your parent's, on Alt+Tab?

'Cause as I said, WM_SETICON displays ICON_SMALL just fine (form and
Taskbar), but fails to execute ICON_BIG (Alt+Tab).

***
 
P

Peter T

So maybe the Q is:
Can you show an icon other than your parent's, on Alt+Tab?

It's a good question. I'm guess it should be possible though I don't know
how. Keep tinkering, if/when you get it drop me a line!


Referring to your previous post -

Not sure why that was happening for you - you're not by any chance
re-showing an already loaded form, that could indeed cause your floating
window (I mean doing myForm.Show again while already loaded).

A hidden window's x:y is given a notional -32000:-32000. However you can't
simply move the hidden window (say with the MoveWindow API) back onto the
desktop to make visible.

Regards,
Peter T
 
P

Peter T

Can you show an icon other than your parent's, on Alt+Tab?

With thanks to Karl Peterson over in vb.general.discussion who suggested
instead of

SetWindowLong mFrmHwnd, GWL_HWNDPARENT, GetDesktopWindow
do
SetWindowLong mFrmHwnd, GWL_HWNDPARENT, 0&

I now see the form's custom icon in Alt-tab (when the form is minimized)

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top