| View previous topic :: View next topic |
| Author |
Message |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Thu May 01, 2008 9:51 pm Post subject: [c++] how to constantly change the text in static control |
|
|
i want to add HP,MP and exp hook i had to my trainer and display these info on my trainer using one of its static control.
but i can't seem to edit static control text once its created in my dialog.
i tried this but didn't work
| Code: |
SetWindowText(GetDlgItem(hWnd,IDC_STATIC_1),"blah blah blah");
|
also if its possible, how would i change certain static control to a different color.
it seems to me static control is very limited :S
thank you in advance
Bizarro _________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils
Last edited by Bizarro on Thu May 01, 2008 10:07 pm; edited 1 time in total |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu May 01, 2008 10:05 pm Post subject: |
|
|
| SetDlgItemText |
|
| Back to top |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Thu May 01, 2008 10:07 pm Post subject: |
|
|
| slovach wrote: | | SetDlgItemText |
doesn't seem to work with static control =S _________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils |
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Thu May 01, 2008 10:21 pm Post subject: |
|
|
| Bizarro wrote: | | slovach wrote: | | SetDlgItemText |
doesn't seem to work with static control =S |
Give it its own reference number (hMenu parameter with CreateWindowEx();) and use that instead of the static declaration (-1). |
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Thu May 01, 2008 10:53 pm Post subject: |
|
|
well i did something like this, lemme find it
| Code: |
HWND Static1;
Static1 = CreateWindow(TEXT("STATIC"), TEXT("Text"), WS_CHILD | WS_VISIBLE, 0, 0, 100, 15, hWnd, 0, hInstance, NULL);
SetWindowText( Static1, TEXT("Texty text")); |
that works for me _________________
|
|
| Back to top |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Fri May 02, 2008 12:13 am Post subject: |
|
|
ty guys
@snooate
setwindowtext still doesn't work for constant updating:S
edit:
looks like setwindowtext and SetDlgItemText only work for me in WM_INITDIALOG. if i used it any where outside it (ie WM_COMMAND), it will become not effective. any one know whats the problem? _________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils |
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Fri May 02, 2008 4:57 am Post subject: |
|
|
i've used my way when using hotkeys (WM_HOTKEY), it should really work for all commands _________________
|
|
| Back to top |
|
 |
Renkokuken GO Moderator
Reputation: 4
Joined: 22 Oct 2006 Posts: 3249
|
Posted: Fri May 02, 2008 5:17 am Post subject: |
|
|
| Are you redrawing the window after each update to the static? |
|
| Back to top |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Fri May 02, 2008 9:47 am Post subject: |
|
|
| Renkokuken wrote: | | Are you redrawing the window after each update to the static? |
any idea how do i redraw the dialog static control?
i tried updatewindow(); didn't work _________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils |
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Fri May 02, 2008 10:02 am Post subject: |
|
|
| Bizarro wrote: | | slovach wrote: | | SetDlgItemText |
doesn't seem to work with static control =S |
The first parameter (HWND) should be the parent window. |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Fri May 02, 2008 10:07 am Post subject: |
|
|
Redraw the window using RedrawWindow:
| Code: | | RedrawWindow( hWnd, 0, 0, RDW_INVALIDATE ); |
Also try calling InvalidateRect before that if you need to as well. (Just fill in the hWnd for that as well then null the rest of the params to invalidate the full window.) _________________
- Retired. |
|
| Back to top |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Fri May 02, 2008 10:16 am Post subject: |
|
|
| Wiccaan wrote: | Redraw the window using RedrawWindow:
| Code: | | RedrawWindow( hWnd, 0, 0, RDW_INVALIDATE ); |
Also try calling InvalidateRect before that if you need to as well. (Just fill in the hWnd for that as well then null the rest of the params to invalidate the full window.) |
wiccan somehow it still doesn't update
i made 2 buttons (ON and OFF) on my dialog
after i use createwindow for the static control in WM_INITDIALOG
i did the setwindowtext in WM_ON and WM_OFF under WM_COMMAND
| Code: |
case WM_INITDIALOG:
{
Static1 = CreateWindow(TEXT("STATIC"), TEXT("Text"), WS_CHILD | WS_VISIBLE, 0, 0, 100, 15, hWnd, 0, hInstance, NULL);
ShowWindow( hWnd, SW_SHOW );
}
return TRUE;
case WM_COMMAND:
switch( wParam )
{
case IDC_ON:
SetWindowText( Static1, TEXT("hp on"));
InvalidateRect(hWnd,0,0);
RedrawWindow( hWnd, 0, 0, RDW_INVALIDATE );
return true;
...
|
still didn't work
setWindowText and SetDlgItemText only works within WM_INITDIALOG _________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils |
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Fri May 02, 2008 11:19 am Post subject: |
|
|
Here is an example on using SetWindowText().
| Code: |
case WM_COMMAND:
{
if (HIWORD(wParam) == BN_CLICKED)
{
switch (LOWORD(wParam))
{
case btnOnOff:
{
if (num)
{
SetWindowText(hStatic, "OFF");
SetWindowText(hButton, "OFF");
num--;
}
else
{
SetWindowText(hStatic, "ON");
SetWindowText(hButton, "ON");
num++;
}
}
break;
}
}
break;
}
|
I would only recommend using SetWindowText when you dynamically create the control. Since you are using are dialog, you should use SetDlgItemText.
| Code: |
case WM_COMMAND:
{
if (HIWORD(wParam) == BN_CLICKED)
{
switch (LOWORD(wParam))
{
case IDC_BTN_UP:
{
char temp[MAX_PATH] = { 0 };
GetDlgItemText(hWnd, IDC_EDIT_UP, temp, MAX_PATH);
SetDlgItemText(hWnd, IDC_STATIC_UP, temp);
}
break;
}
}
}
return true;
|
I've provided the source for using SetWindowText and SetDlgItemText. |
|
| Back to top |
|
 |
Bizarro I post too much
Reputation: 0
Joined: 01 May 2007 Posts: 2648
|
Posted: Fri May 02, 2008 10:32 pm Post subject: |
|
|
killer
if you looked my partial code up there, i did almost the same as ur example code.
but something must be wrong with my code. SetWindowText and SetDlgItemText doesn't work for me outside WM_WM_INITDIALOG
:S _________________
w8 baby.com Banner contest, Come join NOW!!
Check us out for Prize deatils |
|
| Back to top |
|
 |
|