Sign in to follow this  
Followers 0
GrayFox

_SendMessage and WM_SETTEXT not working

7 posts in this topic

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

Share this post


Link to post
Share on other sites



Use 'WinSetTitle' ?


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.

Share this post


Link to post
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. :(

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Use _SendMessageA() or change string type to "wstr" ("wchar" for buffer).


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Thanks alot trancexx, I tested both methods and they both work great :(

Share this post


Link to post
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
Sign in to follow this  
Followers 0