Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Fun with Userforms!!!!

I normally create and show a basic userform by using the following
code:

Userform1.Show ' Show the basic userfom


However, I have recently discovered a new way to display
a userform which involves using the code and definitions
below:
--------------------------------------------------------------------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_HWNDPARENT As Long = -8

Private Sub UserForm_Initialize()
Dim hWnd As Long
hWnd = FindWindow("ThunderDFrame", Me.Caption)
SetWindowLongA hWnd, GWL_HWNDPARENT, 0&
End Sub
-------------------------------------------------------------------------------

Then I load this "ThunderDFrame" form using the following call:

UserForm1.Show (vbModeless) ' Show ThunderDFrame as modeless



So..... I was wondering if it's possible to transform the "basic" userform
style described above into the "ThunderDForm" descibed above??? I am
basically interested in toggling my userform back and forth between
the basic style and ThunderDFrame styles when the form is loaded??
I think this is possible with the Win32 API & Visual C++...so I'm wondering
if I can do it with VBA as well???

Thank you everyone!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default Fun with Userforms!!!!

Sorry, I am not getting what hyou think this does. What is the point as far
as you are concerned?


---
HTH

Bob Phillips

"Robert Crandal" wrote in message
...
I normally create and show a basic userform by using the following
code:

Userform1.Show ' Show the basic userfom


However, I have recently discovered a new way to display
a userform which involves using the code and definitions
below:
--------------------------------------------------------------------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_HWNDPARENT As Long = -8

Private Sub UserForm_Initialize()
Dim hWnd As Long
hWnd = FindWindow("ThunderDFrame", Me.Caption)
SetWindowLongA hWnd, GWL_HWNDPARENT, 0&
End Sub
-------------------------------------------------------------------------------

Then I load this "ThunderDFrame" form using the following call:

UserForm1.Show (vbModeless) ' Show ThunderDFrame as modeless



So..... I was wondering if it's possible to transform the "basic" userform
style described above into the "ThunderDForm" descibed above??? I am
basically interested in toggling my userform back and forth between
the basic style and ThunderDFrame styles when the form is loaded??
I think this is possible with the Win32 API & Visual C++...so I'm
wondering
if I can do it with VBA as well???

Thank you everyone!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Fun with Userforms!!!!

" I have recently discovered " !

I believe I gave you that code in response to your request "to create a
modeless Userform that stays visible somewhere on the desktop even when the
Excel application is minimized on the Taskbar"

Think you are misunderstanding a few things. "ThunderDFrame" is simply the
window classname of a Userform (in Office 2000+). It's not a 'style', it
never changes. It's used simply (with the window caption) to pass to the API
to find the form's window handle. Having got that there are all sorts of
things you can do with a form.

Regards,
Peter T


"Robert Crandal" wrote in message
...
I normally create and show a basic userform by using the following
code:

Userform1.Show ' Show the basic userfom


However, I have recently discovered a new way to display
a userform which involves using the code and definitions
below:
--------------------------------------------------------------------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_HWNDPARENT As Long = -8

Private Sub UserForm_Initialize()
Dim hWnd As Long
hWnd = FindWindow("ThunderDFrame", Me.Caption)
SetWindowLongA hWnd, GWL_HWNDPARENT, 0&
End Sub
-------------------------------------------------------------------------------

Then I load this "ThunderDFrame" form using the following call:

UserForm1.Show (vbModeless) ' Show ThunderDFrame as modeless



So..... I was wondering if it's possible to transform the "basic" userform
style described above into the "ThunderDForm" descibed above??? I am
basically interested in toggling my userform back and forth between
the basic style and ThunderDFrame styles when the form is loaded??
I think this is possible with the Win32 API & Visual C++...so I'm
wondering
if I can do it with VBA as well???

Thank you everyone!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Fun with Userforms!!!!

Yes, that is exactly what I was trying to explain to everyone.
I should have worded it as follows:

"Peter T has recently enlightened me about a modeless Userform
that stays visible on the desktop even when the Excel app is minimized"!
8)

I was then curious if I could revert the userform back to the original
"style", but apparently that is not possible. My reasoning for doing this
is because I like some of the qualitities of both the original basic
userform style and the "ThunderDFrame" form. Namely, I want
to show a basic userform style when Excel is active, and then I
wanted to use the "ThunderDFrame" class window when Excel is
minimized.



"Peter T" <peter_t@discussions wrote in message
...
" I have recently discovered " !

I believe I gave you that code in response to your request "to create a
modeless Userform that stays visible somewhere on the desktop even when
the Excel application is minimized on the Taskbar"

Think you are misunderstanding a few things. "ThunderDFrame" is simply the
window classname of a Userform (in Office 2000+). It's not a 'style', it
never changes. It's used simply (with the window caption) to pass to the
API to find the form's window handle. Having got that there are all sorts
of things you can do with a form.

Regards,
Peter T



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default Fun with Userforms!!!!

So Peter explains something to you, and you say that that was what you were
trying to say, and then repeat the previous thing you said.

As Peter T said, ThunderDFrame is not a style, but you still call it so.
That is why I asked you waht you thought the code that you gave is doing.

---
HTH

Bob Phillips

"Robert Crandal" wrote in message
...
Yes, that is exactly what I was trying to explain to everyone.
I should have worded it as follows:

"Peter T has recently enlightened me about a modeless Userform
that stays visible on the desktop even when the Excel app is minimized"!
8)

I was then curious if I could revert the userform back to the original
"style", but apparently that is not possible. My reasoning for doing this
is because I like some of the qualitities of both the original basic
userform style and the "ThunderDFrame" form. Namely, I want
to show a basic userform style when Excel is active, and then I
wanted to use the "ThunderDFrame" class window when Excel is
minimized.



"Peter T" <peter_t@discussions wrote in message
...
" I have recently discovered " !

I believe I gave you that code in response to your request "to create a
modeless Userform that stays visible somewhere on the desktop even when
the Excel application is minimized on the Taskbar"

Think you are misunderstanding a few things. "ThunderDFrame" is simply
the window classname of a Userform (in Office 2000+). It's not a 'style',
it never changes. It's used simply (with the window caption) to pass to
the API to find the form's window handle. Having got that there are all
sorts of things you can do with a form.

Regards,
Peter T







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Fun with Userforms!!!!

"Robert Crandal" wrote in message news:9QxTm.61260$%
Yes, that is exactly what I was trying to explain to everyone.
I should have worded it as follows:

"Peter T has recently enlightened me about a modeless Userform
that stays visible on the desktop even when the Excel app is minimized"!
8)


:-)

I was then curious if I could revert the userform back to the original
"style", but apparently that is not possible. My reasoning for doing this
is because I like some of the qualitities of both the original basic
userform style and the "ThunderDFrame" form. Namely, I want
to show a basic userform style when Excel is active, and then I
wanted to use the "ThunderDFrame" class window when Excel is
minimized.


Terminology is still wrong here, the previous code has nothing to do with
changing "style" or "basic" vs "ThunderDFrame", it only changes the form's
window parent.

OK, If you want to toggle the form's parent between Excel (default) and the
desktop, put a button on a form and try this -

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLongA Lib "user32" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_HWNDPARENT As Long = -8
Private mhWndFrm As Long
Private mhWndApp As Long
Private mbDeskTop As Boolean

Private Sub CommandButton1_Click()
Dim h As Long

mbDeskTop = Not mbDeskTop

If mbDeskTop Then
h = 0&
Else
h = mhWndApp
End If

SetWindowLongA mhWndFrm, GWL_HWNDPARENT, h

Me.Caption = IIf(mbDeskTop, "Desktop", "Excel")

End Sub

Private Sub UserForm_Initialize()
Dim hWnd As Long

mhWndFrm = FindWindow("ThunderDFrame", Me.Caption)

If Val(Application.Version) < 10 Then
mhWndApp = FindWindow("XLMAIN", Application.Caption)
Else
mhWndApp = Application.hWnd
End If
Me.Caption = "Excel"

End Sub

again show the form as modeless from a routine in a normal module

UserForm1.Show vbModeless

Anticipating your next question - can the code be automatically triggered to
run as appropriate when Excel is minimized/restored - difficult. Min/Restore
Excel does not trigger any events.

Regards,
Peter T




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Fun with Userforms!!!!


Terminology is still wrong here, the previous code has nothing to do with
changing "style" or "basic" vs "ThunderDFrame", it only changes the form's
window parent.


Yes, I know. I was in hurry to quickly go to bed, so I just worded
it very carelessly (or indifferently). My apologies to both you and
Bob Phillips! 8)


OK, If you want to toggle the form's parent between Excel (default) and
the desktop, put a button on a form and try this :

[code snipped for brevity]


Thank you, that code is exactly what I was looking for. You, also
anticipated
my next question very well too.

Well, since Excel has no way to detect application minimize or restore,
might
there be another work around??? For example, I really only want to
display the "basic" userform whenever someone is actually editing a
sheet (ie. Worksheet_Change()). If no editing is taking place, then it
seems
like a good idea to change the form to "ThunderDFrame" at this time.
I just figured that detecting app minimize or restore would be the best
times
to toggle the different userforms, but now I need to look for other
options...


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Fun with Userforms!!!!

"Robert Crandal" wrote in message

Well, since Excel has no way to detect application minimize or restore,
might
there be another work around??? For example, I really only want to
display the "basic" userform whenever someone is actually editing a
sheet (ie. Worksheet_Change()).


Now I'm confused, why on earth would you want the form to be displayed while
Excel is minimized (ie its parent changed to the desktop) if the form is
only required visible while editing a cell, or maybe I misunderstand.

I'm obviously missing something because you cannot interact with the form
while in a cell is in edit mode (or is it only for information purposes).

If no editing is taking place, then it seems
like a good idea to change the form to "ThunderDFrame" at this time.


Please refer to my previous explainations as to why the concept "change the
form to ThunderDFrame" is totally misconstrued.

Regards,
Peter T



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
UserForms sparx[_6_] Excel Programming 1 June 25th 06 09:30 PM
Userforms Greg[_20_] Excel Programming 1 April 4th 06 10:12 AM
Esc out of userforms Mark \(InWales\)[_23_] Excel Programming 2 February 2nd 05 10:08 PM
Userforms..... Candee[_8_] Excel Programming 1 November 27th 03 06:02 PM
userforms again... Jo[_4_] Excel Programming 3 September 21st 03 12:31 AM


All times are GMT +1. The time now is 02:35 PM.

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

About Us

"It's about Microsoft Excel"