Results 1 to 14 of 14

Thread: very simple

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    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.

  2. #2
    amac
    Guest
    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();

  3. #3
    amac
    Guest
    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);

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    thanks!
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  6. #6
    amac
    Guest
    Oops... my mistake...

    I have gotten used to using MFC... it was just natural to put the "->SetWindowText()" in there

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  8. #8
    amac
    Guest
    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.

  9. #9
    amac
    Guest
    A little history lesson for ya...

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  11. #11
    amac
    Guest
    I like that comparison

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  13. #13
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post 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

  14. #14
    Lively Member
    Join Date
    Dec 2000
    Location
    Indiana
    Posts
    73

    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
  •  



Click Here to Expand Forum to Full Width