473,498 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing the text of a Command Button using SetWindowText


Hi,

I am trying to change the text of a Command button using the Windows
API Function SetWindowText, which I have declared as follows:

<DllImport("User32")_
Public Function SetWindowText(ByVal hWnd As IntPtr, ByVal
lpString As String) As Boolean
End Function

To change the text I call the function as follows in the Load event of
the form.
SetWindowText(Me.Button1.Handle.ToInt32, "TEST")
Nothing appears to happen however when I examine the Button using Spy++
it tells me the window has the text "TEST".

When I change the text of a label as follows
SetWindowText(Me.Label1.Handle.ToInt32, "TEST")
it works as expected, i.e. the change is immediately visible

I know of course that I can change the text of the button using the
syntax Button1.Text="TEST" however my objective is to use SetWindowText
as I want to change the text later in an external DLL.

It looks to me like this may be a window update issue. I have tried
invalidating the window and repainting it with no success. Can anyone
help me out on this?

Thanks in advance

Joe

Sep 1 '06 #1
7 7838
<su*****@airetec.comschrieb:
I am trying to change the text of a Command button using the Windows
API Function SetWindowText, which I have declared as follows:

<DllImport("User32")_
Public Function SetWindowText(ByVal hWnd As IntPtr, ByVal
lpString As String) As Boolean
End Function
Specify the character set in 'DllImport' and set it to 'Auto'.
To change the text I call the function as follows in the Load event of
the form.
SetWindowText(Me.Button1.Handle.ToInt32, "TEST")
Remove the '.ToInt32'.
Nothing appears to happen however when I examine the Button using Spy++
it tells me the window has the text "TEST".

When I change the text of a label as follows
SetWindowText(Me.Label1.Handle.ToInt32, "TEST")
it works as expected, i.e. the change is immediately visible
It looks to me like this may be a window update issue.
Maybe the reason is that .NET draws the button. You may want to test it
with native Win32 buttons and/or set the .NET button's 'FlatStyle' property
to 'System'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Sep 1 '06 #2
Hi,

thanks for your help.

I tried what you suggested, it worked when I set the .NET button's
'FlatStyle' property to 'System'. It is not an option for me to
change the property however.

Can I force .NET to redraw the button using a Windows API call? I have
tried InvalidateRect and UpdateWindow without any luck.

Regards
Joe

Herfried K. Wagner [MVP] schrieb:
<su*****@airetec.comschrieb:
I am trying to change the text of a Command button using the Windows
API Function SetWindowText, which I have declared as follows:

<DllImport("User32")_
Public Function SetWindowText(ByVal hWnd As IntPtr, ByVal
lpString As String) As Boolean
End Function

Specify the character set in 'DllImport' and set it to 'Auto'.
To change the text I call the function as follows in the Load event of
the form.
SetWindowText(Me.Button1.Handle.ToInt32, "TEST")

Remove the '.ToInt32'.
Nothing appears to happen however when I examine the Button using Spy++
it tells me the window has the text "TEST".

When I change the text of a label as follows
SetWindowText(Me.Label1.Handle.ToInt32, "TEST")
it works as expected, i.e. the change is immediately visible
It looks to me like this may be a window update issue.

Maybe the reason is that .NET draws the button. You may want to test it
with native Win32 buttons and/or set the .NET button's 'FlatStyle' property
to 'System'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Sep 1 '06 #3
Hello su*****@airetec.com,

Why not simply pass the button as a parameter to your DLL ?

-Boo
Hi,

thanks for your help.

I tried what you suggested, it worked when I set the .NET button's
'FlatStyle' property to 'System'. It is not an option for me to
change the property however.

Can I force .NET to redraw the button using a Windows API call? I have
tried InvalidateRect and UpdateWindow without any luck.

Regards
Joe
Herfried K. Wagner [MVP] schrieb:
><su*****@airetec.comschrieb:
>>I am trying to change the text of a Command button using the Windows
API Function SetWindowText, which I have declared as follows:

<DllImport("User32")_
Public Function SetWindowText(ByVal hWnd As IntPtr, ByVal
lpString As String) As Boolean
End Function
Specify the character set in 'DllImport' and set it to 'Auto'.
>>To change the text I call the function as follows in the Load event
of
the form.
SetWindowText(Me.Button1.Handle.ToInt32, "TEST")
Remove the '.ToInt32'.
>>Nothing appears to happen however when I examine the Button using
Spy++ it tells me the window has the text "TEST".

When I change the text of a label as follows
SetWindowText(Me.Label1.Handle.ToInt32, "TEST")
it works as expected, i.e. the change is immediately visible
It looks to me like this may be a window update issue.
Maybe the reason is that .NET draws the button. You may want to test
it with native Win32 buttons and/or set the .NET button's 'FlatStyle'
property to 'System'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Sep 1 '06 #4
Joe,
Is there a reason you need to use SetWindowText as opposed to simply using
Control.Text?

| Can I force .NET to redraw the button using a Windows API call? I have
| tried InvalidateRect and UpdateWindow without any luck.
I'm not certain, however I would question the need to, as Control.Text
causes the button to be redrawn...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
<su*****@airetec.comwrote in message
news:11*********************@74g2000cwt.googlegrou ps.com...
| Hi,
|
| thanks for your help.
|
| I tried what you suggested, it worked when I set the .NET button's
| 'FlatStyle' property to 'System'. It is not an option for me to
| change the property however.
|
| Can I force .NET to redraw the button using a Windows API call? I have
| tried InvalidateRect and UpdateWindow without any luck.
|
| Regards
| Joe
|
| Herfried K. Wagner [MVP] schrieb:
|
| <su*****@airetec.comschrieb:
| I am trying to change the text of a Command button using the Windows
| API Function SetWindowText, which I have declared as follows:
|
| <DllImport("User32")_
| Public Function SetWindowText(ByVal hWnd As IntPtr, ByVal
| lpString As String) As Boolean
| End Function
| >
| Specify the character set in 'DllImport' and set it to 'Auto'.
| >
| To change the text I call the function as follows in the Load event of
| the form.
| SetWindowText(Me.Button1.Handle.ToInt32, "TEST")
| >
| Remove the '.ToInt32'.
| >
| Nothing appears to happen however when I examine the Button using
Spy++
| it tells me the window has the text "TEST".
|
| When I change the text of a label as follows
| SetWindowText(Me.Label1.Handle.ToInt32, "TEST")
| it works as expected, i.e. the change is immediately visible
| >
| It looks to me like this may be a window update issue.
| >
| Maybe the reason is that .NET draws the button. You may want to test it
| with native Win32 buttons and/or set the .NET button's 'FlatStyle'
property
| to 'System'.
| >
| --
| M S Herfried K. Wagner
| M V P <URL:http://dotnet.mvps.org/>
| V B <URL:http://classicvb.org/petition/>
|
Sep 1 '06 #5
Doh! missed the lower half of the question here.
| I know of course that I can change the text of the button using the
| syntax Button1.Text="TEST" however my objective is to use SetWindowText
| as I want to change the text later in an external DLL.
I missed the part of the external DLL.

Is the external DLL written in unmanaged C/C++ or is it a managed (VB, C#)
dll?

If its a managed Dll; Why not simply pass Button or Control to the external
DLL allowing it to use Control.Text?

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
<su*****@airetec.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
|
| Hi,
|
| I am trying to change the text of a Command button using the Windows
| API Function SetWindowText, which I have declared as follows:
|
| <DllImport("User32")_
| Public Function SetWindowText(ByVal hWnd As IntPtr, ByVal
| lpString As String) As Boolean
| End Function
|
| To change the text I call the function as follows in the Load event of
| the form.
| SetWindowText(Me.Button1.Handle.ToInt32, "TEST")
| Nothing appears to happen however when I examine the Button using Spy++
| it tells me the window has the text "TEST".
|
| When I change the text of a label as follows
| SetWindowText(Me.Label1.Handle.ToInt32, "TEST")
| it works as expected, i.e. the change is immediately visible
|
| I know of course that I can change the text of the button using the
| syntax Button1.Text="TEST" however my objective is to use SetWindowText
| as I want to change the text later in an external DLL.
|
| It looks to me like this may be a window update issue. I have tried
| invalidating the window and repainting it with no success. Can anyone
| help me out on this?
|
| Thanks in advance
|
| Joe
|
Sep 1 '06 #6
Hi,

that is how my DLL is supposed to work. It takes the window handle as a
parameter and changes the text using the Windows API call
SetWindowText.

That doesn't work either though, so to localise the problem I
simplified it to a direct call to SetWindowText in vb.net.

Joe
GhostInAK schrieb:
Hello su*****@airetec.com,

Why not simply pass the button as a parameter to your DLL ?

-Boo
Hi,

thanks for your help.

I tried what you suggested, it worked when I set the .NET button's
'FlatStyle' property to 'System'. It is not an option for me to
change the property however.

Can I force .NET to redraw the button using a Windows API call? I have
tried InvalidateRect and UpdateWindow without any luck.

Regards
Joe
Herfried K. Wagner [MVP] schrieb:
<su*****@airetec.comschrieb:

I am trying to change the text of a Command button using the Windows
API Function SetWindowText, which I have declared as follows:

<DllImport("User32")_
Public Function SetWindowText(ByVal hWnd As IntPtr, ByVal
lpString As String) As Boolean
End Function
Specify the character set in 'DllImport' and set it to 'Auto'.

To change the text I call the function as follows in the Load event
of
the form.
SetWindowText(Me.Button1.Handle.ToInt32, "TEST")
Remove the '.ToInt32'.

Nothing appears to happen however when I examine the Button using
Spy++ it tells me the window has the text "TEST".

When I change the text of a label as follows
SetWindowText(Me.Label1.Handle.ToInt32, "TEST")
it works as expected, i.e. the change is immediately visible
It looks to me like this may be a window update issue.

Maybe the reason is that .NET draws the button. You may want to test
it with native Win32 buttons and/or set the .NET button's 'FlatStyle'
property to 'System'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Sep 1 '06 #7

Hi Jay,

its an unmanaged C++ DLL.

The curious thing is if I set the text of the button using
SetWindowText to say "XYZ" and then read it back using GetWindowText I
get "XYZ" as a result.

It just doesn't display the text I set even if I repaint the screen. If
however I change the flatstyle of the button to system, then it works.
Problem is that is not an option.
Regards
Joe


Jay B. Harlow [MVP - Outlook] schrieb:
Doh! missed the lower half of the question here.
| I know of course that I can change the text of the button using the
| syntax Button1.Text="TEST" however my objective is to use SetWindowText
| as I want to change the text later in an external DLL.
I missed the part of the external DLL.

Is the external DLL written in unmanaged C/C++ or is it a managed (VB, C#)
dll?

If its a managed Dll; Why not simply pass Button or Control to the external
DLL allowing it to use Control.Text?

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
<su*****@airetec.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
|
| Hi,
|
| I am trying to change the text of a Command button using the Windows
| API Function SetWindowText, which I have declared as follows:
|
| <DllImport("User32")_
| Public Function SetWindowText(ByVal hWnd As IntPtr, ByVal
| lpString As String) As Boolean
| End Function
|
| To change the text I call the function as follows in the Load event of
| the form.
| SetWindowText(Me.Button1.Handle.ToInt32, "TEST")
| Nothing appears to happen however when I examine the Button using Spy++
| it tells me the window has the text "TEST".
|
| When I change the text of a label as follows
| SetWindowText(Me.Label1.Handle.ToInt32, "TEST")
| it works as expected, i.e. the change is immediately visible
|
| I know of course that I can change the text of the button using the
| syntax Button1.Text="TEST" however my objective is to use SetWindowText
| as I want to change the text later in an external DLL.
|
| It looks to me like this may be a window update issue. I have tried
| invalidating the window and repainting it with no success. Can anyone
| help me out on this?
|
| Thanks in advance
|
| Joe
|
Sep 1 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6354
by: Matt | last post by:
Hi group, Here's a problem I've been trying to solve for the past several weeks. I have the standard WebBrowser object added to a form so it can access websites, and I have it load a default...
3
2209
by: Craig | last post by:
Hi, What I'm trying (quite poorly) to do is make it so when a link is clicked the text inside a div or p changes. I've tried numerous things, most of which work in IE but none of which work in...
1
1837
by: semi | last post by:
Hello, I am using VS C++ to make a gui that displays a text file contents from main dialog. So I created main dialog and another dialog for text file viewer. From the main dialog, I call text...
7
2924
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
4
3121
by: Francis | last post by:
Hello i have a continuos form, and i have a command button to help insert information on a control textbox. But when the text box is not null, i dont want the command button to show (to the current...
2
6661
by: bence.k | last post by:
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...
6
7588
Sushi
by: Sushi | last post by:
Hello! I'm new to the Python language(about 2 months). Having done C programming for 2 years I find out I need Python for a final project, and have been trying to do get my head around object...
3
5594
by: =?Utf-8?B?U3JpZGhhcg==?= | last post by:
Hi, Is there a way to change the title of the Popup opened using window.showModalDialog. I have specified the title in the HTML of the popup. At the end of the title, it is attaching Webpage...
2
7403
by: Rinaldo | last post by:
How to change the button text of a openfiledialog in to my own custum test?
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.