Home All Groups Group Topic Archive Search About

Having problems with SetWindowText api

Author
23 Oct 2006 2:09 PM
bence.k
Hello all!

I'm writing because I'm having some problems with the SetWindowText api
(Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA"
(ByVal hwnd As Long, ByVal lpString As String) As Long)

I know the handle, and have the string what i want to see in the title.
Here is the code part:
c = SetWindowText(hwnd, "string")

c should be a double which is not null, it is ok because c returns a
good value every time
but after that
the window's caption should be "string", but it's became empty, not
"string".

i tried another way too. It is the SendMessage function.

we have the handle and the string again, and there is the code:
c = SendMessage(hwnd, 12, vbNull, "string")

c returns 1 so it should be ok
but the caption's text not ok again. it not empty but contains only one
character a Chr(8). if i replace the "string" with a vbNullString then
the caption text is empty again.

How can i set the right text in the caption?

Thanks,

Bence (iecs)

Author
23 Oct 2006 5:20 PM
Mattias Sjögren
>I'm writing because I'm having some problems with the SetWindowText api
>(Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA"
>(ByVal hwnd As Long, ByVal lpString As String) As Long)

Make that

Declare Auto Function SetWindowText Lib "user32" (ByVal hwnd As
IntPtr, ByVal lpString As String) As Boolean


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
24 Oct 2006 2:32 PM
Chris Dunaway
benc***@gmail.com wrote:

> I'm writing because I'm having some problems with the SetWindowText api
> (Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA"
> (ByVal hwnd As Long, ByVal lpString As String) As Long)
>

Your api declaration needs to be changed as Mattias already pointed
out.  For additional information see here:

http://www.pinvoke.net/default.aspx/user32.SetWindowText