|
-
Sep 13th, 2001, 02:24 PM
#1
Thread Starter
Fanatic Member
very simple
i know the basic C++ language, but i have only worked with console applications and im used to the Visual Basic way of coding
my big problem is how do i reference (in code) a control name that is on a dialog?
like in VB you just do cmdWhatever.Caption = "Hello"
is it like IDC_BUTTON1.Caption("Hello"); in C++?
thanx
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 13th, 2001, 02:33 PM
#2
One wat is to use GetDlgItem()
so if you wanted to set the text of IDC_BUTTON1
you could do...
GetDlgItem(IDC_BUTTON1)->SetWindowText("Button");
GetDlgItem() returns a pointer to a CWnd object (base class for the majority MFC)... If you wanna do a control specific task you can just cast the the pointer...
((CListBox*)GetDlgItem(IDC_LISTBOX1))->GetCurSel();
-
Sep 13th, 2001, 02:40 PM
#3
There is also this option... which is basically the smae thing except not MFC
Code:
GetDlgItem(hDialgBox, IDC_BUTTON1)->SetWindowText("Butto");
or
Code:
SetDlgItemText(hDialogBox, IDC_BUTTON1, "Button);
-
Sep 13th, 2001, 02:43 PM
#4
Thread Starter
Fanatic Member
The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.
-
Sep 13th, 2001, 03:15 PM
#5
Monday Morning Lunatic
Code:
GetDlgItem(hDialgBox, IDC_BUTTON1)->SetWindowText("Butto");
You what? 
You need the GetDlgItemText and SetDlgItemText functions.
Although all this is moot unless we know whether you're using MFC or not...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 13th, 2001, 03:20 PM
#6
Oops... my mistake...
I have gotten used to using MFC... it was just natural to put the "->SetWindowText()" in there
-
Sep 13th, 2001, 03:28 PM
#7
Monday Morning Lunatic
AAARGGGHHH!!!
EVIL EVIL EVIL! MFC!!! *gag* *ack* *choke*
Just wondering, but why do you use MFC? Nothing against you for it, just asking...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 13th, 2001, 03:50 PM
#8
Lets see...
In the beginning I began with C++... just doing command line applications... nothing very interesting...
Then I was exposed to VB and Windows Programming... It kinda grew on me... soon after that I started looking into the Win32 API... and using some of the functions in VB... (CDAudio control, System Tray Icons, etc)
Then I took a class in school on VC++, which taught MFC... I wanted to use API, but we didnt... I never really go into windows programming in VC++ until about 6 months ago... when I first started obviously I had to use what I already knew, which was MFC and i used the API functions I already knew....
I guess I would say 4 months ago I guess I started learning more about the Win32 API...
Currently, I will only use API... I actually enjoy it much more than MFC... there is more satisfaction when you get things to work...
The reason why I put the "->SetWindowText()" things was because where I work... all GUI is done in MFC (and Stringray Controls: basically Enhanced MFC controls)... Kinda gets stuck in there sometimes...
But I am with you on the API thing... much better... helps you understand how things actually work...
For the people who like knowing how things work... and who want more satisfaction out of windows programming... use API and throw MFC out the window.
-
Sep 13th, 2001, 03:50 PM
#9
A little history lesson for ya...
-
Sep 13th, 2001, 03:52 PM
#10
Monday Morning Lunatic
Fair enough...
It's like a prostitute, MFC is quicker but not as satisfying...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 14th, 2001, 06:09 AM
#11
-
Sep 14th, 2001, 08:11 AM
#12
Monday Morning Lunatic
I thought so too
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 15th, 2001, 07:48 AM
#13
Fanatic Member
Try this:)
Get "hBUTTON" text
PHP Code:
GetDlgItemText(hwnd,hBUTTON,GetWindowText(hwnd,GetDlgItem(hwnd,hBUTTON)+1);
Set "hBUTTON" text
PHP Code:
SetWindowText(hBUTTON,"GO ****");
I'm not sure if the 1st one right... I haven't touch computers for more than 2 weeks, and yet I'm only a beginner in VC++.

prog_tom
JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
http://physics.sviesoft.com/forum
-
Sep 15th, 2001, 08:40 PM
#14
Lively Member
Wrong
Wrong, try THIS:
Get "hBUTTON" text
PHP Code:
char buffer[256]="";
GetWindowText(GetDlgItem(hwnd,hBUTTON),buffer,sizeof(buffer));
//Then use buffer. It holds the window (control)'s caption at
//the time the code executed.
Set "hBUTTON" text
PHP Code:
SetWindowText(GetDlgItem(hwnd,hBUTTON),"GO ****");
if(GetWindowLong(hwnd,GWL_ID)==IDC_MICROSOFT_APPLICATION)
{
SetWindowText(hwnd,"I suck.");
SendMessage(hwnd,WM_START_SUCKING,0,0);
SendMessage(hwnd,WM_CRASH,0,0);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|