Jump to content

_SendMessage and WM_SETTEXT not working


Recommended Posts

Does anyone know why none of the following code snippets work?

Basically, I want to rename the window title of any new notepad documents.

#include <WinAPI.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>

$var = WinList()
For $i = 1 To $var[0][0]
    If $var[$i][0] == "Untitled - Notepad" Then
        $struct = DllStructCreate("char[30]")
        DllStructSetData($struct,1,"This doesnt work!")
        _SendMessage($var[$i][1],$WM_SETTEXT,0,DllStructGetPtr($struct))
    EndIf
Next

#include <WinAPI.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>

$var = WinList()
For $i = 1 To $var[0][0]
    If $var[$i][0] == "Untitled - Notepad" Then
        _SendMessage($var[$i][1], $WM_SETTEXT, 0, "This doesnt work either.", 0, "int", "str")
    EndIf
Next

This is the only one I have got working:

#include <WinAPI.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>

$var = WinList()
For $i = 1 To $var[0][0]
    If $var[$i][0] == "Untitled - Notepad" Then
        _WinAPI_SetWindowText($var[$i][1], "This works!")
    EndIf
Next

Thanks

Link to comment
Share on other sites

Thanks for your reply Yoriz, thats a great idea though unfortunately it doesnt accept handles to windows, just the title or the classname or some other complex title. (I should have stated this in the OP) that I would like to rename the window/s straight from the handle as this makes life easier. :(

Link to comment
Share on other sites

It does except Handles to windows try the following

Run("Notepad.exe")
WinWait("Untitled - Notepad")
$hWnd = WinGetHandle("Untitled - Notepad")
WinSetTitle($hWnd,"","Change NotePad title with its hWnd of = " & $hWnd)
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

That works perfectly! Thanks alot Yoriz :(

Edit: your solution solves my problem 100%, though simply out of curiosity would anyone know if its possible to achieve the same effect with _SendMessage?

Edited by GrayFox
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...