Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Complex focus problem

Have a modeless userform that can load a modal userform.
This modeless userform behaves like an application through some API code.
Amongst other things it means an icon will show in the taskbar.
A problem arises when the modeless userform loads a modal form, another
application gets activated, say Outlook and then the icon of the modeless
form gets clicked.
What happens then is that the modeless userform is on top of the modal form,
but the modeless form can't get the focus as this is in the modal form. So
you are stuck. You can get out of this with Alt + tab though.
Other than making the modal form modeless, which is no good solution, what
would be the best approach to avoid this problem?
Thanks for any advice.

RBS

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Complex focus problem

Hi Bart,

I'm probably missing something but maybe something like

' in the modeless form
Me.hide
Userform2.show vbmodal
' mbFlag = true
Me.show
' mbFlag = false

Might need to temporarily set a modular boolean to prevent any unwanted code
running in the modeless form's activate event.

Regards,
Peter T


"RB Smissaert" wrote in message
...
Have a modeless userform that can load a modal userform.
This modeless userform behaves like an application through some API code.
Amongst other things it means an icon will show in the taskbar.
A problem arises when the modeless userform loads a modal form, another
application gets activated, say Outlook and then the icon of the modeless
form gets clicked.
What happens then is that the modeless userform is on top of the modal

form,
but the modeless form can't get the focus as this is in the modal form. So
you are stuck. You can get out of this with Alt + tab though.
Other than making the modal form modeless, which is no good solution, what
would be the best approach to avoid this problem?
Thanks for any advice.

RBS



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Complex focus problem

Hi Peter,


The thing is that I don't want to hide the modeless form.
I think I have solved this though with some simple API code:

Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName 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 Const GWL_HWNDPARENT As Long = -8


Sub SetFormParent(strFormCaption As String, _
Optional strParentFormCaption As String = "")

Dim hWndForm As Long
Dim hWndParentForm As Long

hWndForm = FindWindow(vbNullString, strFormCaption) 'the modal form

If Len(strParentFormCaption) = 0 Then
hWndParentForm = FindWindow(vbNullString, MainForm.Caption) 'the
modeless form
Else
hWndParentForm = FindWindow(vbNullString, strParentFormCaption)
'the modeless form
End If

SetWindowLong hWndForm, GWL_HWNDPARENT, hWndParentForm

End Sub

Then in the Initialize event of the modal form I do:

SetFormParent Me.Caption

It has the slight side-effect that if you click the modeless form when the
modal form is loaded the modal
form will flash a few times, but this is no problem. It does solve the
problem of the modal being hidden
behind the modeless form when clicking the taskbar icon of the modeless
form.
So, I think this is OK now.
As I have quite a few forms where I have to do this, it is nice that is only
one line of code extra.


RBS




"Peter T" <peter_t@discussions wrote in message
...
Hi Bart,

I'm probably missing something but maybe something like

' in the modeless form
Me.hide
Userform2.show vbmodal
' mbFlag = true
Me.show
' mbFlag = false

Might need to temporarily set a modular boolean to prevent any unwanted
code
running in the modeless form's activate event.

Regards,
Peter T


"RB Smissaert" wrote in message
...
Have a modeless userform that can load a modal userform.
This modeless userform behaves like an application through some API code.
Amongst other things it means an icon will show in the taskbar.
A problem arises when the modeless userform loads a modal form, another
application gets activated, say Outlook and then the icon of the modeless
form gets clicked.
What happens then is that the modeless userform is on top of the modal

form,
but the modeless form can't get the focus as this is in the modal form.
So
you are stuck. You can get out of this with Alt + tab though.
Other than making the modal form modeless, which is no good solution,
what
would be the best approach to avoid this problem?
Thanks for any advice.

RBS




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Complex focus problem

That works very well. Only thing I'm confused about, you say -

It has the slight side-effect that if you click the modeless form when the
modal form is loaded the modal
form will flash a few times,


I cannot replicate that problem, because if the modal form is loaded and is
the front window, cannot click anything outside of the form. Ie, cannot
click the modeless form.

Regards,
Peter T

"RB Smissaert" wrote in message
...
Hi Peter,


The thing is that I don't want to hide the modeless form.
I think I have solved this though with some simple API code:

Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName 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 Const GWL_HWNDPARENT As Long = -8


Sub SetFormParent(strFormCaption As String, _
Optional strParentFormCaption As String = "")

Dim hWndForm As Long
Dim hWndParentForm As Long

hWndForm = FindWindow(vbNullString, strFormCaption) 'the modal form

If Len(strParentFormCaption) = 0 Then
hWndParentForm = FindWindow(vbNullString, MainForm.Caption)

'the
modeless form
Else
hWndParentForm = FindWindow(vbNullString, strParentFormCaption)
'the modeless form
End If

SetWindowLong hWndForm, GWL_HWNDPARENT, hWndParentForm

End Sub

Then in the Initialize event of the modal form I do:

SetFormParent Me.Caption

It has the slight side-effect that if you click the modeless form when the
modal form is loaded the modal
form will flash a few times, but this is no problem. It does solve the
problem of the modal being hidden
behind the modeless form when clicking the taskbar icon of the modeless
form.
So, I think this is OK now.
As I have quite a few forms where I have to do this, it is nice that is

only
one line of code extra.


RBS




"Peter T" <peter_t@discussions wrote in message
...
Hi Bart,

I'm probably missing something but maybe something like

' in the modeless form
Me.hide
Userform2.show vbmodal
' mbFlag = true
Me.show
' mbFlag = false

Might need to temporarily set a modular boolean to prevent any unwanted
code
running in the modeless form's activate event.

Regards,
Peter T


"RB Smissaert" wrote in message
...
Have a modeless userform that can load a modal userform.
This modeless userform behaves like an application through some API

code.
Amongst other things it means an icon will show in the taskbar.
A problem arises when the modeless userform loads a modal form, another
application gets activated, say Outlook and then the icon of the

modeless
form gets clicked.
What happens then is that the modeless userform is on top of the modal

form,
but the modeless form can't get the focus as this is in the modal form.
So
you are stuck. You can get out of this with Alt + tab though.
Other than making the modal form modeless, which is no good solution,
what
would be the best approach to avoid this problem?
Thanks for any advice.

RBS






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Complex focus problem

Peter,

You can if the modal form is smaller than the modeless form and doesn't
cover it all.
This is the situation with all my forms.

RBS

"Peter T" <peter_t@discussions wrote in message
...
That works very well. Only thing I'm confused about, you say -

It has the slight side-effect that if you click the modeless form when
the
modal form is loaded the modal
form will flash a few times,


I cannot replicate that problem, because if the modal form is loaded and
is
the front window, cannot click anything outside of the form. Ie, cannot
click the modeless form.

Regards,
Peter T

"RB Smissaert" wrote in message
...
Hi Peter,


The thing is that I don't want to hide the modeless form.
I think I have solved this though with some simple API code:

Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName 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 Const GWL_HWNDPARENT As Long = -8


Sub SetFormParent(strFormCaption As String, _
Optional strParentFormCaption As String = "")

Dim hWndForm As Long
Dim hWndParentForm As Long

hWndForm = FindWindow(vbNullString, strFormCaption) 'the modal
form

If Len(strParentFormCaption) = 0 Then
hWndParentForm = FindWindow(vbNullString, MainForm.Caption)

'the
modeless form
Else
hWndParentForm = FindWindow(vbNullString, strParentFormCaption)
'the modeless form
End If

SetWindowLong hWndForm, GWL_HWNDPARENT, hWndParentForm

End Sub

Then in the Initialize event of the modal form I do:

SetFormParent Me.Caption

It has the slight side-effect that if you click the modeless form when
the
modal form is loaded the modal
form will flash a few times, but this is no problem. It does solve the
problem of the modal being hidden
behind the modeless form when clicking the taskbar icon of the modeless
form.
So, I think this is OK now.
As I have quite a few forms where I have to do this, it is nice that is

only
one line of code extra.


RBS




"Peter T" <peter_t@discussions wrote in message
...
Hi Bart,

I'm probably missing something but maybe something like

' in the modeless form
Me.hide
Userform2.show vbmodal
' mbFlag = true
Me.show
' mbFlag = false

Might need to temporarily set a modular boolean to prevent any unwanted
code
running in the modeless form's activate event.

Regards,
Peter T


"RB Smissaert" wrote in message
...
Have a modeless userform that can load a modal userform.
This modeless userform behaves like an application through some API

code.
Amongst other things it means an icon will show in the taskbar.
A problem arises when the modeless userform loads a modal form,
another
application gets activated, say Outlook and then the icon of the

modeless
form gets clicked.
What happens then is that the modeless userform is on top of the modal
form,
but the modeless form can't get the focus as this is in the modal
form.
So
you are stuck. You can get out of this with Alt + tab though.
Other than making the modal form modeless, which is no good solution,
what
would be the best approach to avoid this problem?
Thanks for any advice.

RBS









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Complex focus problem

There still is a slight problem when there is a message box rather than a
modal form.
Just will have to do an Alt + Tab then.

RBS


"Peter T" <peter_t@discussions wrote in message
...
That works very well. Only thing I'm confused about, you say -

It has the slight side-effect that if you click the modeless form when
the
modal form is loaded the modal
form will flash a few times,


I cannot replicate that problem, because if the modal form is loaded and
is
the front window, cannot click anything outside of the form. Ie, cannot
click the modeless form.

Regards,
Peter T

"RB Smissaert" wrote in message
...
Hi Peter,


The thing is that I don't want to hide the modeless form.
I think I have solved this though with some simple API code:

Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName 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 Const GWL_HWNDPARENT As Long = -8


Sub SetFormParent(strFormCaption As String, _
Optional strParentFormCaption As String = "")

Dim hWndForm As Long
Dim hWndParentForm As Long

hWndForm = FindWindow(vbNullString, strFormCaption) 'the modal
form

If Len(strParentFormCaption) = 0 Then
hWndParentForm = FindWindow(vbNullString, MainForm.Caption)

'the
modeless form
Else
hWndParentForm = FindWindow(vbNullString, strParentFormCaption)
'the modeless form
End If

SetWindowLong hWndForm, GWL_HWNDPARENT, hWndParentForm

End Sub

Then in the Initialize event of the modal form I do:

SetFormParent Me.Caption

It has the slight side-effect that if you click the modeless form when
the
modal form is loaded the modal
form will flash a few times, but this is no problem. It does solve the
problem of the modal being hidden
behind the modeless form when clicking the taskbar icon of the modeless
form.
So, I think this is OK now.
As I have quite a few forms where I have to do this, it is nice that is

only
one line of code extra.


RBS




"Peter T" <peter_t@discussions wrote in message
...
Hi Bart,

I'm probably missing something but maybe something like

' in the modeless form
Me.hide
Userform2.show vbmodal
' mbFlag = true
Me.show
' mbFlag = false

Might need to temporarily set a modular boolean to prevent any unwanted
code
running in the modeless form's activate event.

Regards,
Peter T


"RB Smissaert" wrote in message
...
Have a modeless userform that can load a modal userform.
This modeless userform behaves like an application through some API

code.
Amongst other things it means an icon will show in the taskbar.
A problem arises when the modeless userform loads a modal form,
another
application gets activated, say Outlook and then the icon of the

modeless
form gets clicked.
What happens then is that the modeless userform is on top of the modal
form,
but the modeless form can't get the focus as this is in the modal
form.
So
you are stuck. You can get out of this with Alt + tab though.
Other than making the modal form modeless, which is no good solution,
what
would be the best approach to avoid this problem?
Thanks for any advice.

RBS







  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Complex focus problem

I can't add anything useful, but doesn't a message box always appear first
on top. If user then Alt-tabs he should know how to get back again.

Regards,
Peter T

"RB Smissaert" wrote in message
...
There still is a slight problem when there is a message box rather than a
modal form.
Just will have to do an Alt + Tab then.

RBS


"Peter T" <peter_t@discussions wrote in message
...
That works very well. Only thing I'm confused about, you say -

It has the slight side-effect that if you click the modeless form when
the
modal form is loaded the modal
form will flash a few times,


I cannot replicate that problem, because if the modal form is loaded and
is
the front window, cannot click anything outside of the form. Ie, cannot
click the modeless form.

Regards,
Peter T

"RB Smissaert" wrote in message
...
Hi Peter,


The thing is that I don't want to hide the modeless form.
I think I have solved this though with some simple API code:

Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName 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 Const GWL_HWNDPARENT As Long = -8


Sub SetFormParent(strFormCaption As String, _
Optional strParentFormCaption As String = "")

Dim hWndForm As Long
Dim hWndParentForm As Long

hWndForm = FindWindow(vbNullString, strFormCaption) 'the modal
form

If Len(strParentFormCaption) = 0 Then
hWndParentForm = FindWindow(vbNullString, MainForm.Caption)

'the
modeless form
Else
hWndParentForm = FindWindow(vbNullString, strParentFormCaption)
'the modeless form
End If

SetWindowLong hWndForm, GWL_HWNDPARENT, hWndParentForm

End Sub

Then in the Initialize event of the modal form I do:

SetFormParent Me.Caption

It has the slight side-effect that if you click the modeless form when
the
modal form is loaded the modal
form will flash a few times, but this is no problem. It does solve the
problem of the modal being hidden
behind the modeless form when clicking the taskbar icon of the modeless
form.
So, I think this is OK now.
As I have quite a few forms where I have to do this, it is nice that is

only
one line of code extra.


RBS




"Peter T" <peter_t@discussions wrote in message
...
Hi Bart,

I'm probably missing something but maybe something like

' in the modeless form
Me.hide
Userform2.show vbmodal
' mbFlag = true
Me.show
' mbFlag = false

Might need to temporarily set a modular boolean to prevent any

unwanted
code
running in the modeless form's activate event.

Regards,
Peter T


"RB Smissaert" wrote in message
...
Have a modeless userform that can load a modal userform.
This modeless userform behaves like an application through some API

code.
Amongst other things it means an icon will show in the taskbar.
A problem arises when the modeless userform loads a modal form,
another
application gets activated, say Outlook and then the icon of the

modeless
form gets clicked.
What happens then is that the modeless userform is on top of the

modal
form,
but the modeless form can't get the focus as this is in the modal
form.
So
you are stuck. You can get out of this with Alt + tab though.
Other than making the modal form modeless, which is no good

solution,
what
would be the best approach to avoid this problem?
Thanks for any advice.

RBS









  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Complex focus problem

Yes, Alt + Tab will always get you out, but some people don't know about
this.
I can't see a way to fix this with API or anything else.
It will just have to be mentioned in the help.

RBS

"Peter T" <peter_t@discussions wrote in message
...
I can't add anything useful, but doesn't a message box always appear first
on top. If user then Alt-tabs he should know how to get back again.

Regards,
Peter T

"RB Smissaert" wrote in message
...
There still is a slight problem when there is a message box rather than a
modal form.
Just will have to do an Alt + Tab then.

RBS


"Peter T" <peter_t@discussions wrote in message
...
That works very well. Only thing I'm confused about, you say -

It has the slight side-effect that if you click the modeless form when
the
modal form is loaded the modal
form will flash a few times,

I cannot replicate that problem, because if the modal form is loaded
and
is
the front window, cannot click anything outside of the form. Ie, cannot
click the modeless form.

Regards,
Peter T

"RB Smissaert" wrote in message
...
Hi Peter,


The thing is that I don't want to hide the modeless form.
I think I have solved this though with some simple API code:

Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName 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 Const GWL_HWNDPARENT As Long = -8


Sub SetFormParent(strFormCaption As String, _
Optional strParentFormCaption As String = "")

Dim hWndForm As Long
Dim hWndParentForm As Long

hWndForm = FindWindow(vbNullString, strFormCaption) 'the modal
form

If Len(strParentFormCaption) = 0 Then
hWndParentForm = FindWindow(vbNullString, MainForm.Caption)
'the
modeless form
Else
hWndParentForm = FindWindow(vbNullString,
strParentFormCaption)
'the modeless form
End If

SetWindowLong hWndForm, GWL_HWNDPARENT, hWndParentForm

End Sub

Then in the Initialize event of the modal form I do:

SetFormParent Me.Caption

It has the slight side-effect that if you click the modeless form when
the
modal form is loaded the modal
form will flash a few times, but this is no problem. It does solve the
problem of the modal being hidden
behind the modeless form when clicking the taskbar icon of the
modeless
form.
So, I think this is OK now.
As I have quite a few forms where I have to do this, it is nice that
is
only
one line of code extra.


RBS




"Peter T" <peter_t@discussions wrote in message
...
Hi Bart,

I'm probably missing something but maybe something like

' in the modeless form
Me.hide
Userform2.show vbmodal
' mbFlag = true
Me.show
' mbFlag = false

Might need to temporarily set a modular boolean to prevent any

unwanted
code
running in the modeless form's activate event.

Regards,
Peter T


"RB Smissaert" wrote in message
...
Have a modeless userform that can load a modal userform.
This modeless userform behaves like an application through some API
code.
Amongst other things it means an icon will show in the taskbar.
A problem arises when the modeless userform loads a modal form,
another
application gets activated, say Outlook and then the icon of the
modeless
form gets clicked.
What happens then is that the modeless userform is on top of the

modal
form,
but the modeless form can't get the focus as this is in the modal
form.
So
you are stuck. You can get out of this with Alt + tab though.
Other than making the modal form modeless, which is no good

solution,
what
would be the best approach to avoid this problem?
Thanks for any advice.

RBS










Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
cmdbarmenu focus problem pjbur2005 via OfficeKB.com Excel Worksheet Functions 2 January 28th 07 02:44 AM
Set Focus Problem with Multipage Control sebastienm Excel Programming 0 July 16th 04 10:20 PM
Focus problem Jos Vens Excel Programming 0 May 27th 04 10:29 PM
weird focus problem Tom Ogilvy Excel Programming 0 August 8th 03 04:01 PM
weird focus problem Ron de Bruin Excel Programming 0 August 8th 03 03:54 PM


All times are GMT +1. The time now is 05:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"