Make a form appear always on top


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Make a form appear always on top

  1. #1
    Rich Guest

    Make a form appear always on top


    I am writing an application that controls Excel using VB6. I have a control
    panel that is a standard VB form and I want it to stay visible when the user
    gives focus to Excel. The form has a minimise button that the user can use
    to remove it from view. I was wondering if there is a way to make the form
    appear always on top or embed the form into Excel so that it always appears
    on top and when Excel is minimised the form also minimises.

    If anyone can offer any advice it will be greatly appreciated.

    Regards

    Rich

  2. #2
    challis Guest

    Re: Make a form appear always on top


    Yes, it is possible

    No, it is not easy

    To make your form the top most form can be done via win API calls
    see

    Delcare Function SetWindowPos _
    Lib "user32"

    in your API viewer.

    You have to subclass the excel window to be notified when it
    gets minimized then minimize your form as required.

    challis

    "Rich" <webmaster@dickie-bow.co.uk> wrote:
    >
    >I am writing an application that controls Excel using VB6. I have a control
    >panel that is a standard VB form and I want it to stay visible when the

    user
    >gives focus to Excel. The form has a minimise button that the user can

    use
    >to remove it from view. I was wondering if there is a way to make the form
    >appear always on top or embed the form into Excel so that it always appears
    >on top and when Excel is minimised the form also minimises.
    >
    >If anyone can offer any advice it will be greatly appreciated.
    >
    >Regards
    >
    >Rich



  3. #3
    Rich Guest

    Re: Make a form appear always on top


    Thnk-you, I'll give it a try. I have never made calls to the win API so unfortunately
    I might need further assistance. I'll keep you posted.

    regards

    Rich

    "challis" <bmlx@yahoo.com> wrote:
    >
    >Yes, it is possible
    >
    >No, it is not easy
    >
    >To make your form the top most form can be done via win API calls
    >see
    >
    >Delcare Function SetWindowPos _
    > Lib "user32"
    >
    >in your API viewer.
    >
    >You have to subclass the excel window to be notified when it
    >gets minimized then minimize your form as required.
    >
    >challis
    >
    >"Rich" <webmaster@dickie-bow.co.uk> wrote:
    >>
    >>I am writing an application that controls Excel using VB6. I have a control
    >>panel that is a standard VB form and I want it to stay visible when the

    >user
    >>gives focus to Excel. The form has a minimise button that the user can

    >use
    >>to remove it from view. I was wondering if there is a way to make the

    form
    >>appear always on top or embed the form into Excel so that it always appears
    >>on top and when Excel is minimised the form also minimises.
    >>
    >>If anyone can offer any advice it will be greatly appreciated.
    >>
    >>Regards
    >>
    >>Rich

    >



  4. #4
    Rich Guest

    Re: Make a form appear always on top


    So far I have been able to make my form appear always on top of
    Excel (thanks for the info), but I am new to VB and I don't know how to subclass
    the excel window to be notified when it gets minimized then minimize my form?

    If you can provide further explanation I would be extremely greatful!!!

    Rich

    "challis" <bmlx@yahoo.com> wrote:
    >
    >Yes, it is possible
    >
    >No, it is not easy
    >
    >To make your form the top most form can be done via win API calls
    >see
    >
    >Delcare Function SetWindowPos _
    > Lib "user32"
    >
    >in your API viewer.
    >
    >You have to subclass the excel window to be notified when it
    >gets minimized then minimize your form as required.
    >
    >challis
    >
    >"Rich" <webmaster@dickie-bow.co.uk> wrote:
    >>
    >>I am writing an application that controls Excel using VB6. I have a control
    >>panel that is a standard VB form and I want it to stay visible when the

    >user
    >>gives focus to Excel. The form has a minimise button that the user can

    >use
    >>to remove it from view. I was wondering if there is a way to make the

    form
    >>appear always on top or embed the form into Excel so that it always appears
    >>on top and when Excel is minimised the form also minimises.
    >>
    >>If anyone can offer any advice it will be greatly appreciated.
    >>
    >>Regards
    >>
    >>Rich

    >



  5. #5
    challis Guest

    Re: Make a form appear always on top


    Hi

    Subclassing and the like is rather complex, and I do not have the time necessary
    to explain it in enough detail here that I think you should use. There is
    however a good article
    on Francesco Balena's site at

    http://www.vb2themax.com/ArticleBank...ID=ArticleBank

    it's located near the end, and contains code samples and all that.

    Have a look, there are also other articles that are most informative.

    challis


    "Rich" <richard.bowen@power.altsom.com> wrote:
    >
    >So far I have been able to make my form appear always on top of
    >Excel (thanks for the info), but I am new to VB and I don't know how to

    subclass
    >the excel window to be notified when it gets minimized then minimize my

    form?
    >
    >If you can provide further explanation I would be extremely greatful!!!
    >
    >Rich
    >
    >"challis" <bmlx@yahoo.com> wrote:
    >>
    >>Yes, it is possible
    >>
    >>No, it is not easy
    >>
    >>To make your form the top most form can be done via win API calls
    >>see
    >>
    >>Delcare Function SetWindowPos _
    >> Lib "user32"
    >>
    >>in your API viewer.
    >>
    >>You have to subclass the excel window to be notified when it
    >>gets minimized then minimize your form as required.
    >>
    >>challis
    >>
    >>"Rich" <webmaster@dickie-bow.co.uk> wrote:
    >>>
    >>>I am writing an application that controls Excel using VB6. I have a control
    >>>panel that is a standard VB form and I want it to stay visible when the

    >>user
    >>>gives focus to Excel. The form has a minimise button that the user can

    >>use
    >>>to remove it from view. I was wondering if there is a way to make the

    >form
    >>>appear always on top or embed the form into Excel so that it always appears
    >>>on top and when Excel is minimised the form also minimises.
    >>>
    >>>If anyone can offer any advice it will be greatly appreciated.
    >>>
    >>>Regards
    >>>
    >>>Rich

    >>

    >



  6. #6
    Rich Guest

    Re: Make a form appear always on top


    I just had a quick look at the site and it looks like a good source of information.
    The article you suggested is exactly what I'm looking for. Thankyou for
    your help!!

    Regards

    "challis" <bmlx@yahoo.com> wrote:
    >
    >Hi
    >
    >Subclassing and the like is rather complex, and I do not have the time necessary
    >to explain it in enough detail here that I think you should use. There is
    >however a good article
    >on Francesco Balena's site at
    >
    >http://www.vb2themax.com/ArticleBank...ID=ArticleBank
    >
    >it's located near the end, and contains code samples and all that.
    >
    >Have a look, there are also other articles that are most informative.
    >
    >challis
    >
    >
    >"Rich" <richard.bowen@power.altsom.com> wrote:
    >>
    >>So far I have been able to make my form appear always on top of
    >>Excel (thanks for the info), but I am new to VB and I don't know how to

    >subclass
    >>the excel window to be notified when it gets minimized then minimize my

    >form?
    >>
    >>If you can provide further explanation I would be extremely greatful!!!
    >>
    >>Rich
    >>
    >>"challis" <bmlx@yahoo.com> wrote:
    >>>
    >>>Yes, it is possible
    >>>
    >>>No, it is not easy
    >>>
    >>>To make your form the top most form can be done via win API calls
    >>>see
    >>>
    >>>Delcare Function SetWindowPos _
    >>> Lib "user32"
    >>>
    >>>in your API viewer.
    >>>
    >>>You have to subclass the excel window to be notified when it
    >>>gets minimized then minimize your form as required.
    >>>
    >>>challis
    >>>
    >>>"Rich" <webmaster@dickie-bow.co.uk> wrote:
    >>>>
    >>>>I am writing an application that controls Excel using VB6. I have a

    control
    >>>>panel that is a standard VB form and I want it to stay visible when the
    >>>user
    >>>>gives focus to Excel. The form has a minimise button that the user can
    >>>use
    >>>>to remove it from view. I was wondering if there is a way to make the

    >>form
    >>>>appear always on top or embed the form into Excel so that it always appears
    >>>>on top and when Excel is minimised the form also minimises.
    >>>>
    >>>>If anyone can offer any advice it will be greatly appreciated.
    >>>>
    >>>>Regards
    >>>>
    >>>>Rich
    >>>

    >>

    >



  7. #7
    challis Guest

    Re: Make a form appear always on top


    Hi

    You are most welcome

    challis

    "Rich" <richard.bowen@power.alstom.com> wrote:
    >
    >I just had a quick look at the site and it looks like a good source of information.
    > The article you suggested is exactly what I'm looking for. Thankyou for
    >your help!!
    >
    >Regards
    >
    >"challis" <bmlx@yahoo.com> wrote:
    >>
    >>Hi
    >>
    >>Subclassing and the like is rather complex, and I do not have the time

    necessary
    >>to explain it in enough detail here that I think you should use. There

    is
    >>however a good article
    >>on Francesco Balena's site at
    >>
    >>http://www.vb2themax.com/ArticleBank...ID=ArticleBank
    >>
    >>it's located near the end, and contains code samples and all that.
    >>
    >>Have a look, there are also other articles that are most informative.
    >>
    >>challis
    >>
    >>
    >>"Rich" <richard.bowen@power.altsom.com> wrote:
    >>>
    >>>So far I have been able to make my form appear always on top of
    >>>Excel (thanks for the info), but I am new to VB and I don't know how to

    >>subclass
    >>>the excel window to be notified when it gets minimized then minimize my

    >>form?
    >>>
    >>>If you can provide further explanation I would be extremely greatful!!!
    >>>
    >>>Rich
    >>>
    >>>"challis" <bmlx@yahoo.com> wrote:
    >>>>
    >>>>Yes, it is possible
    >>>>
    >>>>No, it is not easy
    >>>>
    >>>>To make your form the top most form can be done via win API calls
    >>>>see
    >>>>
    >>>>Delcare Function SetWindowPos _
    >>>> Lib "user32"
    >>>>
    >>>>in your API viewer.
    >>>>
    >>>>You have to subclass the excel window to be notified when it
    >>>>gets minimized then minimize your form as required.
    >>>>
    >>>>challis
    >>>>
    >>>>"Rich" <webmaster@dickie-bow.co.uk> wrote:
    >>>>>
    >>>>>I am writing an application that controls Excel using VB6. I have a

    >control
    >>>>>panel that is a standard VB form and I want it to stay visible when

    the
    >>>>user
    >>>>>gives focus to Excel. The form has a minimise button that the user

    can
    >>>>use
    >>>>>to remove it from view. I was wondering if there is a way to make the
    >>>form
    >>>>>appear always on top or embed the form into Excel so that it always

    appears
    >>>>>on top and when Excel is minimised the form also minimises.
    >>>>>
    >>>>>If anyone can offer any advice it will be greatly appreciated.
    >>>>>
    >>>>>Regards
    >>>>>
    >>>>>Rich
    >>>>
    >>>

    >>

    >



  8. #8
    Rich Guest

    Re: Make a form appear always on top


    I have been looking through Francesco alena's code and I have tried to use
    it without changing anything to sub class the Excel window. I have tried
    the following piece of code to subclass the window.

    Private Sub Form_Load()
    Set FormX = New CFormEvenets
    Set FormX.HookedForm = Excel.Application
    End Sub

    I also changed the return type of HookedForm to Object instead of Form.
    I can't find the property hWnd anywhere within Excel that I need to subclass
    the window.

    Challis can you help?

    Rich

    >>"challis" <bmlx@yahoo.com> wrote:
    >>>
    >>>Hi
    >>>
    >>>Subclassing and the like is rather complex, and I do not have the time

    >necessary
    >>>to explain it in enough detail here that I think you should use. There

    >is
    >>>however a good article
    >>>on Francesco Balena's site at
    >>>
    >>>http://www.vb2themax.com/ArticleBank...ID=ArticleBank
    >>>
    >>>it's located near the end, and contains code samples and all that.
    >>>
    >>>Have a look, there are also other articles that are most informative.
    >>>
    >>>challis
    >>>
    >>>
    >>>"Rich" <richard.bowen@power.altsom.com> wrote:
    >>>>
    >>>>So far I have been able to make my form appear always on top of
    >>>>Excel (thanks for the info), but I am new to VB and I don't know how

    to
    >>>subclass
    >>>>the excel window to be notified when it gets minimized then minimize

    my
    >>>form?
    >>>>
    >>>>If you can provide further explanation I would be extremely greatful!!!
    >>>>
    >>>>Rich
    >>>>
    >>>>"challis" <bmlx@yahoo.com> wrote:
    >>>>>
    >>>>>Yes, it is possible
    >>>>>
    >>>>>No, it is not easy
    >>>>>
    >>>>>To make your form the top most form can be done via win API calls
    >>>>>see
    >>>>>
    >>>>>Delcare Function SetWindowPos _
    >>>>> Lib "user32"
    >>>>>
    >>>>>in your API viewer.
    >>>>>
    >>>>>You have to subclass the excel window to be notified when it
    >>>>>gets minimized then minimize your form as required.
    >>>>>
    >>>>>challis
    >>>>>
    >>>>>"Rich" <webmaster@dickie-bow.co.uk> wrote:
    >>>>>>
    >>>>>>I am writing an application that controls Excel using VB6. I have

    a
    >>control
    >>>>>>panel that is a standard VB form and I want it to stay visible when

    >the
    >>>>>user
    >>>>>>gives focus to Excel. The form has a minimise button that the user

    >can
    >>>>>use
    >>>>>>to remove it from view. I was wondering if there is a way to make

    the
    >>>>form
    >>>>>>appear always on top or embed the form into Excel so that it always

    >appears
    >>>>>>on top and when Excel is minimised the form also minimises.
    >>>>>>
    >>>>>>If anyone can offer any advice it will be greatly appreciated.
    >>>>>>
    >>>>>>Regards
    >>>>>>
    >>>>>>Rich
    >>>>>
    >>>>
    >>>

    >>

    >



  9. #9
    challis Guest

    Re: Make a form appear always on top


    Hi

    Use FindWindowEx

    Declare Function FindWindowEx _
    Lib "user32" _
    Alias "FindWindowA" ( _
    byval hWndParent as Long, _
    byval hWndChildAfter as Long, _
    byval lpClassName as String, _
    byval lpWindowName as String) _
    as Long

    Since you are looking for a top level window,
    hWndParent = 0
    hWndChildAfter = 0 (this lets you enumerate windows)
    lpClassName = "" (you may get wrong results when
    running two instances of excel when using this)
    lpWindowName = [Excel.Application.Caption - I think] but
    it's the text that appears in the top part of the window.

    The function the returns the hWnd of the window containing the caption. Be
    careful, Excel may return it's caption to be "MyFile.xls" when the caption
    is actually more like "MS Excel - MyFile.xls". You must supply the name you
    see.


    I hope this gets you where you want to be

    challis


    "Rich" <richard.bowen@power.alstom.com> wrote:
    >
    >I have been looking through Francesco alena's code and I have tried to use
    >it without changing anything to sub class the Excel window. I have tried
    >the following piece of code to subclass the window.
    >
    >Private Sub Form_Load()
    > Set FormX = New CFormEvenets
    > Set FormX.HookedForm = Excel.Application
    >End Sub
    >
    >I also changed the return type of HookedForm to Object instead of Form.


    >I can't find the property hWnd anywhere within Excel that I need to subclass
    >the window.
    >
    >Challis can you help?
    >
    >Rich
    >
    >>>"challis" <bmlx@yahoo.com> wrote:
    >>>>
    >>>>Hi
    >>>>
    >>>>Subclassing and the like is rather complex, and I do not have the time

    >>necessary
    >>>>to explain it in enough detail here that I think you should use. There

    >>is
    >>>>however a good article
    >>>>on Francesco Balena's site at
    >>>>
    >>>>http://www.vb2themax.com/ArticleBank...ID=ArticleBank
    >>>>
    >>>>it's located near the end, and contains code samples and all that.
    >>>>
    >>>>Have a look, there are also other articles that are most informative.
    >>>>
    >>>>challis
    >>>>
    >>>>
    >>>>"Rich" <richard.bowen@power.altsom.com> wrote:
    >>>>>
    >>>>>So far I have been able to make my form appear always on top of
    >>>>>Excel (thanks for the info), but I am new to VB and I don't know how

    >to
    >>>>subclass
    >>>>>the excel window to be notified when it gets minimized then minimize

    >my
    >>>>form?
    >>>>>
    >>>>>If you can provide further explanation I would be extremely greatful!!!
    >>>>>
    >>>>>Rich
    >>>>>
    >>>>>"challis" <bmlx@yahoo.com> wrote:
    >>>>>>
    >>>>>>Yes, it is possible
    >>>>>>
    >>>>>>No, it is not easy
    >>>>>>
    >>>>>>To make your form the top most form can be done via win API calls
    >>>>>>see
    >>>>>>
    >>>>>>Delcare Function SetWindowPos _
    >>>>>> Lib "user32"
    >>>>>>
    >>>>>>in your API viewer.
    >>>>>>
    >>>>>>You have to subclass the excel window to be notified when it
    >>>>>>gets minimized then minimize your form as required.
    >>>>>>
    >>>>>>challis
    >>>>>>
    >>>>>>"Rich" <webmaster@dickie-bow.co.uk> wrote:
    >>>>>>>
    >>>>>>>I am writing an application that controls Excel using VB6. I have

    >a
    >>>control
    >>>>>>>panel that is a standard VB form and I want it to stay visible when

    >>the
    >>>>>>user
    >>>>>>>gives focus to Excel. The form has a minimise button that the user

    >>can
    >>>>>>use
    >>>>>>>to remove it from view. I was wondering if there is a way to make

    >the
    >>>>>form
    >>>>>>>appear always on top or embed the form into Excel so that it always

    >>appears
    >>>>>>>on top and when Excel is minimised the form also minimises.
    >>>>>>>
    >>>>>>>If anyone can offer any advice it will be greatly appreciated.
    >>>>>>>
    >>>>>>>Regards
    >>>>>>>
    >>>>>>>Rich
    >>>>>>
    >>>>>
    >>>>
    >>>

    >>

    >



  10. #10
    Rich Guest

    Re: Make a form appear always on top


    The function for some reason returns a 0 as the window handle using the Function
    below. I have also tried GetActiveWindow (as only one copy Excel will be
    open), but I had a problem debugging because the active window was VB.

    I also used FindWindow("XLMAIN", 0) and I think the window was subclassed
    but an event I defined in CFormEvents class doesn't work.

    I have added an event called MinMax that looks at WM_SIZE and when the subclassed
    window is minimised it is suppossed to minimise the form.

    I create a form which acts as a control panel to control certain things in
    Excel. In the Form_Load event for that form I create an Excel application
    object and then subclass the window, before the control panel loads. In
    the forms module I have the event which applies to the subclassed Excel called
    MinMax, but it doesn't react when Excel is minimised or maximised.

    I wondered if this sounds like the logical order in which Excel should be
    subclassed.

    Rich


    "challis" <bmlx@yahoo.com> wrote:
    >
    >Hi
    >
    >Use FindWindowEx
    >
    >Declare Function FindWindowEx _
    > Lib "user32" _
    > Alias "FindWindowA" ( _
    > byval hWndParent as Long, _
    > byval hWndChildAfter as Long, _
    > byval lpClassName as String, _
    > byval lpWindowName as String) _
    > as Long
    >
    >Since you are looking for a top level window,
    >hWndParent = 0
    >hWndChildAfter = 0 (this lets you enumerate windows)
    >lpClassName = "" (you may get wrong results when
    > running two instances of excel when using this)
    >lpWindowName = [Excel.Application.Caption - I think] but
    > it's the text that appears in the top part of the window.
    >
    >The function the returns the hWnd of the window containing the caption.

    Be
    >careful, Excel may return it's caption to be "MyFile.xls" when the caption
    >is actually more like "MS Excel - MyFile.xls". You must supply the name

    you
    >see.
    >
    >
    >I hope this gets you where you want to be
    >
    >challis
    >
    >
    >"Rich" <richard.bowen@power.alstom.com> wrote:
    >>
    >>I have been looking through Francesco alena's code and I have tried to

    use
    >>it without changing anything to sub class the Excel window. I have tried
    >>the following piece of code to subclass the window.
    >>
    >>Private Sub Form_Load()
    >> Set FormX = New CFormEvenets
    >> Set FormX.HookedForm = Excel.Application
    >>End Sub
    >>
    >>I also changed the return type of HookedForm to Object instead of Form.

    >
    >>I can't find the property hWnd anywhere within Excel that I need to subclass
    >>the window.
    >>
    >>Challis can you help?
    >>
    >>Rich
    >>
    >>>>"challis" <bmlx@yahoo.com> wrote:
    >>>>>
    >>>>>Hi
    >>>>>
    >>>>>Subclassing and the like is rather complex, and I do not have the time
    >>>necessary
    >>>>>to explain it in enough detail here that I think you should use. There
    >>>is
    >>>>>however a good article
    >>>>>on Francesco Balena's site at
    >>>>>
    >>>>>http://www.vb2themax.com/ArticleBank...ID=ArticleBank
    >>>>>
    >>>>>it's located near the end, and contains code samples and all that.
    >>>>>
    >>>>>Have a look, there are also other articles that are most informative.
    >>>>>
    >>>>>challis
    >>>>>
    >>>>>
    >>>>>"Rich" <richard.bowen@power.altsom.com> wrote:
    >>>>>>
    >>>>>>So far I have been able to make my form appear always on top of
    >>>>>>Excel (thanks for the info), but I am new to VB and I don't know how

    >>to
    >>>>>subclass
    >>>>>>the excel window to be notified when it gets minimized then minimize

    >>my
    >>>>>form?
    >>>>>>
    >>>>>>If you can provide further explanation I would be extremely greatful!!!
    >>>>>>
    >>>>>>Rich
    >>>>>>
    >>>>>>"challis" <bmlx@yahoo.com> wrote:
    >>>>>>>
    >>>>>>>Yes, it is possible
    >>>>>>>
    >>>>>>>No, it is not easy
    >>>>>>>
    >>>>>>>To make your form the top most form can be done via win API calls
    >>>>>>>see
    >>>>>>>
    >>>>>>>Delcare Function SetWindowPos _
    >>>>>>> Lib "user32"
    >>>>>>>
    >>>>>>>in your API viewer.
    >>>>>>>
    >>>>>>>You have to subclass the excel window to be notified when it
    >>>>>>>gets minimized then minimize your form as required.
    >>>>>>>
    >>>>>>>challis
    >>>>>>>
    >>>>>>>"Rich" <webmaster@dickie-bow.co.uk> wrote:
    >>>>>>>>
    >>>>>>>>I am writing an application that controls Excel using VB6. I have

    >>a
    >>>>control
    >>>>>>>>panel that is a standard VB form and I want it to stay visible when
    >>>the
    >>>>>>>user
    >>>>>>>>gives focus to Excel. The form has a minimise button that the user
    >>>can
    >>>>>>>use
    >>>>>>>>to remove it from view. I was wondering if there is a way to make

    >>the
    >>>>>>form
    >>>>>>>>appear always on top or embed the form into Excel so that it always
    >>>appears
    >>>>>>>>on top and when Excel is minimised the form also minimises.
    >>>>>>>>
    >>>>>>>>If anyone can offer any advice it will be greatly appreciated.
    >>>>>>>>
    >>>>>>>>Regards
    >>>>>>>>
    >>>>>>>>Rich
    >>>>>>>
    >>>>>>
    >>>>>
    >>>>
    >>>

    >>

    >



  11. #11
    Rich Guest

    Re: Make a form appear always on top


    Challis

    Since my previous message I have been able to make get my event working in
    Francesco's code. When the form is minmized it gives me a message box saying
    "Going down." Not very exciting but it worked. So I understand how to subclass
    a form.

    I am still having problems getting the Excel hWnd value. The following code
    is an updated version of the HookedForm property declaration from the CFormEvents
    class from FB's code. I have tried all three ways to assign the Excel's
    hWnd value to lngExcel_hWnd, but they all return 0, which suggests the window
    can't be found. The value Excel.Application is passed to new_Form. If you
    can resolve the crisis of getting Excel's handle it would be much appreciated.

    Property Set HookedForm(new_Form As Object)
    ' start the subclassing of a new form

    Dim lngExcel_hWnd As Long

    ' API GetActiveWindow has replaced new_form.hWnd from original code because
    ' as Excel is an object and not a form it doesn't have a hWnd property.

    ' only one used at a time.
    lngExcel_hWnd = FindWindowEx(0, 0, "", new_Form.Caption)
    lngExcel_hWnd = GetActiveWindow
    lngExcel_hWnd = FindWindow("XLMAIN", 0)

    ' do nothing if no real change
    If new_Form Is Nothing Then
    If lngExcel_hWnd = 0 Then Exit Property
    Else
    If lngExcel_hWnd = m_hWnd Then Exit Property
    End If

    ' stop current subclassing, if any
    If m_hWnd Then
    UnhookWindow wndInfoIndex
    wndInfoIndex = 0
    End If

    ' save new value
    Set m_Form = new_Form

    ' exit if trying to assign a null object
    ' (same as stopping subclassing)
    If new_Form Is Nothing Then
    m_hWnd = 0
    Exit Property
    End If

    ' save window handle
    m_hWnd = lngExcel_hWnd

    ' start subclassing, save returned index
    wndInfoIndex = HookWindow(Me, m_hWnd)
    ' signal any error
    If wndInfoIndex = 0 Then
    Err.Raise 999, "CFormEvents class", "Too many subclassed windows"
    End If
    End Property


    Regards

    Rich

  12. #12
    challis Guest

    Re: Make a form appear always on top


    Hi,

    I will look into it this afternoon. In the mean time there is a work around
    .... (possibly) go to excel and see if the application object has and hWnd
    property.

    challis


    "Rich" <richard.bowen@power.alstom.com> wrote:
    >
    >Challis
    >
    >Since my previous message I have been able to make get my event working

    in
    >Francesco's code. When the form is minmized it gives me a message box saying
    >"Going down." Not very exciting but it worked. So I understand how to subclass
    >a form.
    >
    >I am still having problems getting the Excel hWnd value. The following

    code
    >is an updated version of the HookedForm property declaration from the CFormEvents
    >class from FB's code. I have tried all three ways to assign the Excel's
    >hWnd value to lngExcel_hWnd, but they all return 0, which suggests the window
    >can't be found. The value Excel.Application is passed to new_Form. If

    you
    >can resolve the crisis of getting Excel's handle it would be much appreciated.
    >
    >Property Set HookedForm(new_Form As Object)
    > ' start the subclassing of a new form
    >
    > Dim lngExcel_hWnd As Long
    >
    > ' API GetActiveWindow has replaced new_form.hWnd from original code

    because
    > ' as Excel is an object and not a form it doesn't have a hWnd property.
    >
    > ' only one used at a time.
    > lngExcel_hWnd = FindWindowEx(0, 0, "", new_Form.Caption)
    > lngExcel_hWnd = GetActiveWindow
    > lngExcel_hWnd = FindWindow("XLMAIN", 0)
    >
    > ' do nothing if no real change
    > If new_Form Is Nothing Then
    > If lngExcel_hWnd = 0 Then Exit Property
    > Else
    > If lngExcel_hWnd = m_hWnd Then Exit Property
    > End If
    >
    > ' stop current subclassing, if any
    > If m_hWnd Then
    > UnhookWindow wndInfoIndex
    > wndInfoIndex = 0
    > End If
    >
    > ' save new value
    > Set m_Form = new_Form
    >
    > ' exit if trying to assign a null object
    > ' (same as stopping subclassing)
    > If new_Form Is Nothing Then
    > m_hWnd = 0
    > Exit Property
    > End If
    >
    > ' save window handle
    > m_hWnd = lngExcel_hWnd
    >
    > ' start subclassing, save returned index
    > wndInfoIndex = HookWindow(Me, m_hWnd)
    > ' signal any error
    > If wndInfoIndex = 0 Then
    > Err.Raise 999, "CFormEvents class", "Too many subclassed windows"
    > End If
    >End Property
    >
    >
    >Regards
    >
    >Rich



  13. #13
    Rich Guest

    Re: Make a form appear always on top


    Challis

    Late Friday afternoon I found a solution to the problem below. I can get
    Excels hWnd value using the following code:

    new_Form.Caption = "New Caption Supplied by Program"
    lngExcel_hWnd = FindWindow("XLMAIN", new_Form.Caption)
    new_Form.Caption = Empty

    This also deals with more than one instance of Excel. The problem I have
    now is that when the HookForm procedure is called it doesn't hook the form
    because the line:

    ' enforce new window procedure, get old address
    .wndProcAddr = SetWindowLong(hwnd, GWL_WNDPROC, .localProcAddr)

    in the With wndInfo(Index) statement in the HookWindow procedure in the HookEvents
    bas module is always equal to 0. For some reason it has trouble setting
    a value in the internal table related to the specified window and getting
    the original value. I don't know why this isn't working. When I do it with
    a form I don't have any problems but it seems to have a difficulty with Excel.

    Can you help?

    Rich

    "challis" <bmlx@yahoo.com> wrote:
    >
    >Hi,
    >
    >I will look into it this afternoon. In the mean time there is a work around
    >.... (possibly) go to excel and see if the application object has and hWnd
    >property.
    >
    >challis
    >
    >
    >"Rich" <richard.bowen@power.alstom.com> wrote:
    >>
    >>Challis
    >>
    >>Since my previous message I have been able to make get my event working

    >in
    >>Francesco's code. When the form is minmized it gives me a message box

    saying
    >>"Going down." Not very exciting but it worked. So I understand how to

    subclass
    >>a form.
    >>
    >>I am still having problems getting the Excel hWnd value. The following

    >code
    >>is an updated version of the HookedForm property declaration from the CFormEvents
    >>class from FB's code. I have tried all three ways to assign the Excel's
    >>hWnd value to lngExcel_hWnd, but they all return 0, which suggests the

    window
    >>can't be found. The value Excel.Application is passed to new_Form. If

    >you
    >>can resolve the crisis of getting Excel's handle it would be much appreciated.
    >>
    >>Property Set HookedForm(new_Form As Object)
    >> ' start the subclassing of a new form
    >>
    >> Dim lngExcel_hWnd As Long
    >>
    >> ' API GetActiveWindow has replaced new_form.hWnd from original code

    >because
    >> ' as Excel is an object and not a form it doesn't have a hWnd property.
    >>
    >> ' only one used at a time.
    >> lngExcel_hWnd = FindWindowEx(0, 0, "", new_Form.Caption)
    >> lngExcel_hWnd = GetActiveWindow
    >> lngExcel_hWnd = FindWindow("XLMAIN", 0)
    >>
    >> ' do nothing if no real change
    >> If new_Form Is Nothing Then
    >> If lngExcel_hWnd = 0 Then Exit Property
    >> Else
    >> If lngExcel_hWnd = m_hWnd Then Exit Property
    >> End If
    >>
    >> ' stop current subclassing, if any
    >> If m_hWnd Then
    >> UnhookWindow wndInfoIndex
    >> wndInfoIndex = 0
    >> End If
    >>
    >> ' save new value
    >> Set m_Form = new_Form
    >>
    >> ' exit if trying to assign a null object
    >> ' (same as stopping subclassing)
    >> If new_Form Is Nothing Then
    >> m_hWnd = 0
    >> Exit Property
    >> End If
    >>
    >> ' save window handle
    >> m_hWnd = lngExcel_hWnd
    >>
    >> ' start subclassing, save returned index
    >> wndInfoIndex = HookWindow(Me, m_hWnd)
    >> ' signal any error
    >> If wndInfoIndex = 0 Then
    >> Err.Raise 999, "CFormEvents class", "Too many subclassed windows"
    >> End If
    >>End Property
    >>
    >>
    >>Regards
    >>
    >>Rich

    >



  14. #14
    Rich Guest

    Re: Make a form appear always on top


    Challis

    Another update. I noticed that my code was never calling the Clas_Terminate
    procedure in CFormEvents, which is I know is a bad thing. I have corrected
    the problem but I was wondering if I might have done some permanent damage
    to Excel because the line:

    .wndProcAddr = SetWindowLong(hwnd, GWL_WNDPROC, .localProcAddr)

    still returns zero?

    I have tried changing the second parameter to GWL_HINSTANCE (-6) which sets
    a new application instance handle rather than GWL_WNDPROC (-4) which sets
    a new address for the window procedure, but from reading FB's document the
    latter is required. I don't know what to do because it isn't subclassing
    properly :-(

    Can you shead any more light?
    Rich

    "Rich" <richard.bowen@power.alstom.com> wrote:
    >
    >Challis
    >
    >Late Friday afternoon I found a solution to the problem below. I can get
    >Excels hWnd value using the following code:
    >
    >new_Form.Caption = "New Caption Supplied by Program"
    >lngExcel_hWnd = FindWindow("XLMAIN", new_Form.Caption)
    >new_Form.Caption = Empty
    >
    >This also deals with more than one instance of Excel. The problem I have
    >now is that when the HookForm procedure is called it doesn't hook the form
    >because the line:
    >
    >' enforce new window procedure, get old address
    >.wndProcAddr = SetWindowLong(hwnd, GWL_WNDPROC, .localProcAddr)
    >
    >in the With wndInfo(Index) statement in the HookWindow procedure in the

    HookEvents
    >bas module is always equal to 0. For some reason it has trouble setting
    >a value in the internal table related to the specified window and getting
    >the original value. I don't know why this isn't working. When I do it

    with
    >a form I don't have any problems but it seems to have a difficulty with

    Excel.
    >
    >Can you help?
    >
    >Rich
    >
    >"challis" <bmlx@yahoo.com> wrote:
    >>
    >>Hi,
    >>
    >>I will look into it this afternoon. In the mean time there is a work around
    >>.... (possibly) go to excel and see if the application object has and hWnd
    >>property.
    >>
    >>challis
    >>
    >>
    >>"Rich" <richard.bowen@power.alstom.com> wrote:
    >>>
    >>>Challis
    >>>
    >>>Since my previous message I have been able to make get my event working

    >>in
    >>>Francesco's code. When the form is minmized it gives me a message box

    >saying
    >>>"Going down." Not very exciting but it worked. So I understand how to

    >subclass
    >>>a form.
    >>>
    >>>I am still having problems getting the Excel hWnd value. The following

    >>code
    >>>is an updated version of the HookedForm property declaration from the

    CFormEvents
    >>>class from FB's code. I have tried all three ways to assign the Excel's
    >>>hWnd value to lngExcel_hWnd, but they all return 0, which suggests the

    >window
    >>>can't be found. The value Excel.Application is passed to new_Form. If

    >>you
    >>>can resolve the crisis of getting Excel's handle it would be much appreciated.
    >>>
    >>>Property Set HookedForm(new_Form As Object)
    >>> ' start the subclassing of a new form
    >>>
    >>> Dim lngExcel_hWnd As Long
    >>>
    >>> ' API GetActiveWindow has replaced new_form.hWnd from original code

    >>because
    >>> ' as Excel is an object and not a form it doesn't have a hWnd property.
    >>>
    >>> ' only one used at a time.
    >>> lngExcel_hWnd = FindWindowEx(0, 0, "", new_Form.Caption)
    >>> lngExcel_hWnd = GetActiveWindow
    >>> lngExcel_hWnd = FindWindow("XLMAIN", 0)
    >>>
    >>> ' do nothing if no real change
    >>> If new_Form Is Nothing Then
    >>> If lngExcel_hWnd = 0 Then Exit Property
    >>> Else
    >>> If lngExcel_hWnd = m_hWnd Then Exit Property
    >>> End If
    >>>
    >>> ' stop current subclassing, if any
    >>> If m_hWnd Then
    >>> UnhookWindow wndInfoIndex
    >>> wndInfoIndex = 0
    >>> End If
    >>>
    >>> ' save new value
    >>> Set m_Form = new_Form
    >>>
    >>> ' exit if trying to assign a null object
    >>> ' (same as stopping subclassing)
    >>> If new_Form Is Nothing Then
    >>> m_hWnd = 0
    >>> Exit Property
    >>> End If
    >>>
    >>> ' save window handle
    >>> m_hWnd = lngExcel_hWnd
    >>>
    >>> ' start subclassing, save returned index
    >>> wndInfoIndex = HookWindow(Me, m_hWnd)
    >>> ' signal any error
    >>> If wndInfoIndex = 0 Then
    >>> Err.Raise 999, "CFormEvents class", "Too many subclassed windows"
    >>> End If
    >>>End Property
    >>>
    >>>
    >>>Regards
    >>>
    >>>Rich

    >>

    >



  15. #15
    challis Guest

    Re: Make a form appear always on top


    Hi

    I doubt you have caused any damage that can't be fixed by a reboot. This
    is highly unlikely (perhaps possible).

    I have not sudied the CFormEvents class, so I am not fully familiar with
    it's implementation, but when you call setwindowlong you are diverting the
    messages intended for the old address to the one you specify.(The old address
    is the windows message handler for a specific window, not application instance
    [ie specify a handle to a window not a handle to an instance]). Be sure in
    your situation to pass along the intercepted messages to the original handler
    at old address! And also ensure you restore the windows handler from your
    address back to the old address! This is very important!!

    challis

    "Rich" <richard.bowen@power.alstom.com> wrote:
    >
    >Challis
    >
    >Another update. I noticed that my code was never calling the Clas_Terminate
    >procedure in CFormEvents, which is I know is a bad thing. I have corrected
    >the problem but I was wondering if I might have done some permanent damage
    >to Excel because the line:
    >
    >.wndProcAddr = SetWindowLong(hwnd, GWL_WNDPROC, .localProcAddr)
    >
    >still returns zero?
    >
    >I have tried changing the second parameter to GWL_HINSTANCE (-6) which sets
    >a new application instance handle rather than GWL_WNDPROC (-4) which sets
    >a new address for the window procedure, but from reading FB's document the
    >latter is required. I don't know what to do because it isn't subclassing
    >properly :-(
    >
    >Can you shead any more light?
    >Rich
    >
    >"Rich" <richard.bowen@power.alstom.com> wrote:
    >>
    >>Challis
    >>
    >>Late Friday afternoon I found a solution to the problem below. I can get
    >>Excels hWnd value using the following code:
    >>
    >>new_Form.Caption = "New Caption Supplied by Program"
    >>lngExcel_hWnd = FindWindow("XLMAIN", new_Form.Caption)
    >>new_Form.Caption = Empty
    >>
    >>This also deals with more than one instance of Excel. The problem I have
    >>now is that when the HookForm procedure is called it doesn't hook the form
    >>because the line:
    >>
    >>' enforce new window procedure, get old address
    >>.wndProcAddr = SetWindowLong(hwnd, GWL_WNDPROC, .localProcAddr)
    >>
    >>in the With wndInfo(Index) statement in the HookWindow procedure in the

    >HookEvents
    >>bas module is always equal to 0. For some reason it has trouble setting
    >>a value in the internal table related to the specified window and getting
    >>the original value. I don't know why this isn't working. When I do it

    >with
    >>a form I don't have any problems but it seems to have a difficulty with

    >Excel.
    >>
    >>Can you help?
    >>
    >>Rich
    >>
    >>"challis" <bmlx@yahoo.com> wrote:
    >>>
    >>>Hi,
    >>>
    >>>I will look into it this afternoon. In the mean time there is a work around
    >>>.... (possibly) go to excel and see if the application object has and

    hWnd
    >>>property.
    >>>
    >>>challis
    >>>
    >>>
    >>>"Rich" <richard.bowen@power.alstom.com> wrote:
    >>>>
    >>>>Challis
    >>>>
    >>>>Since my previous message I have been able to make get my event working
    >>>in
    >>>>Francesco's code. When the form is minmized it gives me a message box

    >>saying
    >>>>"Going down." Not very exciting but it worked. So I understand how to

    >>subclass
    >>>>a form.
    >>>>
    >>>>I am still having problems getting the Excel hWnd value. The following
    >>>code
    >>>>is an updated version of the HookedForm property declaration from the

    >CFormEvents
    >>>>class from FB's code. I have tried all three ways to assign the Excel's
    >>>>hWnd value to lngExcel_hWnd, but they all return 0, which suggests the

    >>window
    >>>>can't be found. The value Excel.Application is passed to new_Form.

    If
    >>>you
    >>>>can resolve the crisis of getting Excel's handle it would be much appreciated.
    >>>>
    >>>>Property Set HookedForm(new_Form As Object)
    >>>> ' start the subclassing of a new form
    >>>>
    >>>> Dim lngExcel_hWnd As Long
    >>>>
    >>>> ' API GetActiveWindow has replaced new_form.hWnd from original code
    >>>because
    >>>> ' as Excel is an object and not a form it doesn't have a hWnd property.
    >>>>
    >>>> ' only one used at a time.
    >>>> lngExcel_hWnd = FindWindowEx(0, 0, "", new_Form.Caption)
    >>>> lngExcel_hWnd = GetActiveWindow
    >>>> lngExcel_hWnd = FindWindow("XLMAIN", 0)
    >>>>
    >>>> ' do nothing if no real change
    >>>> If new_Form Is Nothing Then
    >>>> If lngExcel_hWnd = 0 Then Exit Property
    >>>> Else
    >>>> If lngExcel_hWnd = m_hWnd Then Exit Property
    >>>> End If
    >>>>
    >>>> ' stop current subclassing, if any
    >>>> If m_hWnd Then
    >>>> UnhookWindow wndInfoIndex
    >>>> wndInfoIndex = 0
    >>>> End If
    >>>>
    >>>> ' save new value
    >>>> Set m_Form = new_Form
    >>>>
    >>>> ' exit if trying to assign a null object
    >>>> ' (same as stopping subclassing)
    >>>> If new_Form Is Nothing Then
    >>>> m_hWnd = 0
    >>>> Exit Property
    >>>> End If
    >>>>
    >>>> ' save window handle
    >>>> m_hWnd = lngExcel_hWnd
    >>>>
    >>>> ' start subclassing, save returned index
    >>>> wndInfoIndex = HookWindow(Me, m_hWnd)
    >>>> ' signal any error
    >>>> If wndInfoIndex = 0 Then
    >>>> Err.Raise 999, "CFormEvents class", "Too many subclassed windows"
    >>>> End If
    >>>>End Property
    >>>>
    >>>>
    >>>>Regards
    >>>>
    >>>>Rich
    >>>

    >>

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center