Results 1 to 6 of 6

Thread: How do I change the caption of....

  1. #1

    Thread Starter
    Addicted Member killer_cobra's Avatar
    Join Date
    Jun 2001
    Location
    Lost in space
    Posts
    131

    How do I change the caption of....

    Hi,
    Just wondering what the code would be to find a window and change it's caption? I have the finding the window part down, and I can already change the "Start" button caption, but I am having troubles with other windows. For example: Changing the caption of Notepad to what ever string is typed into Text1.

    Yes I am still new to programming, I only started 2 weeks ago, so all help is VERY much appreciated.

    Thanx,
    Scott

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    VB Code:
    1. 'first use findwindow to get the windows handle
    2. Dim h as Long
    3. h = FindWindow(classname,caption)
    4. 'then use
    5. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    6. Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
    7. Private Sub Form_Activate()
    8.     Dim MyStr As String
    9.     'Create a buffer
    10.     MyStr = String(100, Chr$(0))
    11.     'Get the windowtext
    12.     GetWindowText text1.hwnd, MyStr, 100
    13.     'strip the rest of buffer
    14.     MyStr = Left$(MyStr, InStr(MyStr, Chr$(0)) - 1)
    15.     'Set the new window text
    16.     SetWindowText h, MyStr
    17. End Sub
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    WALDO
    Guest

    Unhappy

    I am working on something similar. It is a Routine to extract the text from a label on a Msgbox from another aplpication. The ultimate goal is to create a web-based interface for registering server scriptlets(through Scrobj.dll) on a server. I've used a variety of API's to shell out to RegSvr32.exe, but I need to retreive the result of any UI-based Error Messages. I can't use a batch file to spool output because I'd need someone sitting at the server to click the 'OK' button. (If I had that, then I might as well tell them to just manually register the scriptlet)

    So far I've used EnumWindows to obtain a list of all the window handles, then GetClassName to get the window's class name, then once i find the class (Spy++ tells me that it's "Static"), I call GetWindowText with the current handle, but it returns nothing.

    I've also tried Using SendMessage, supplying the constants WM_GETTEXTLENGTH and WM_GETTTEXT, but they return nothing as well.

  4. #4
    WALDO
    Guest

    Talking API's find it necessary

    The nature of simple API's like that are are that they need to accept something in order to return something. Typical ones like GetSystemDirectory() require a sting buffer of 255 characters (The longest length you can have for a path under Windows). In the case of GetSystemDirectory(), It takes that 255 length empty-string and returns a value within that length. If the returned value is less than 255, it pads the returned value with nulls. The API, if successful, also returns a long integer specifying the number of characters the return value actually is (without the nulls). Just call Left$() on the result string and use the returned long integer as the second parameter in Left$()




  5. #5
    Fanatic Member steve65's Avatar
    Join Date
    Jun 2000
    Posts
    610
    Thanks Waldo!
    This space for rent...

  6. #6
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    about the message box problem, I don't think you can retrieve the text, but can't you do a screen capture of it with vb and send the capture back, then use send message to simulate the appropriate click based on a hyperlink in the webpage?

    Basically, the server send a picture of the message box to the client, and has a link for button1 button2 button3 or button4.

    You could also use sendmessage with wm_close to close msgboxes with OK buttons. I use that method with programs that have recuring nag screens.

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