CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2000
    Posts
    127

    Detect Change Caption of a Window

    Is there a way to detect if the caption of a window has changed ?


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Detect Change Caption of a Window

    You could subclass the wndproc and check for the WM_SETTEXT message..


    '\\ Declarations
    Const WM_SETTEXT = &HC
    private Declare Function SetWindowLongApi Lib "user32" Alias "SetWindowLongA" (byval hwnd as Long, byval nIndex as Long, byval dwNewLong as Long) as Long
    const GWL_WNDPROC = (-4)




    using the following Vb equivalent of the wndproc:

    '\\ --[VB_WindowProc]-------------------------------------------------------------------
    '\\ 'typedef LRESULT (CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM);
    '\\ Parameters:
    '\\ hwnd - window handle receiving message
    '\\ wMsg - The window message (WM_..etc.)
    '\\ wParam - First message parameter
    '\\ lParam - Second message parameter
    '\\ Note:
    '\\ When subclassing a window proc using this, set the eventhandler's
    '\\ hOldWndProc property to the window's previous window proc address.
    '\\ ----------------------------------------------------------------------------------------
    '\\ You have a royalty free right to use, reproduce, modify, publish and mess with this code
    '\\ I'd like you to visit http://www.merrioncomputing.com for updates, but won't force you
    '\\ ----------------------------------------------------------------------------------------
    public Function VB_WindowProc(byval hwnd as Long, byval wMsg as Long, byval wParam as Long, byval lParam as Long) as Long

    on Local error resume next

    If wMsg = WM_SETTEXT then
    '\\ Window text has changed
    End If

    VB_WindowProc = lRet

    End Function




    To start subclassing:

    lRet = SetWindowLongApi(Form1.hwnd, GWL_WNDPROC,AddressOf VB_WindowProc)
    '\\ store this lret




    To end subclassing:


    Call SetWindowLongApi(Form1.hwnd, GWL_WNDPROC,lRet)




    You must end subclassing before you kill the window...


    HTH,
    Duncan



    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Aug 2000
    Location
    KY
    Posts
    766

    Re: Detect Change Caption of a Window

    if it is your code and you are wanting to detect a caption change then it is simple. Add a property to your form and then call your property rather than the caption property.

    public property let MyCaption(data as string)
    If me.Caption &lt;&gt; data then
    me.Caption = data
    msgbox "Hey myCaption has Changed"
    End If

    End property




    Yahoo Messenger ID dfWade10900

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured