Thread: First-time Windows programming

  1. #1
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002
    Posts
    96

    First-time Windows programming

    This is my first time programming Windows.

    OK. So I know how to add text to dialog box editor. Right? Well, I've figured out about how I can add another dialog box.

    What I did is, create a test application and named it as Test Dialog. What I did is after I chose MFC appwizard, I follow instructions.

    Then I resize my dialog, move OK button, delete Cancel, name OK as Close, and for that process, I add a new button called a Test.

    Then I add a function after I chose IDC_SENDNAME and BN_CLICKED (I name a Test button of IDC_SENDNAME).

    Then I edit the code:

    Code:
    void CDialogTestDlg::OnSendName()
    {
        // TODO: Add your control handle nodification handle code here
        MessageBox("This is the test.", "Hi!", MB_OK);		
    }
    Well, that's it!

    But... that may sound way to easy to code like that. And, when I visit some of the tutorials you've posted somewhere in the forum, I thought those tutors are hard and just because VC++ are very easy to add controls without adding a single line of code.

    So, for example, unlike cout and cin, I thought there must be a way to copy the text from an edit box and send it to a new dialog box with just a press of a Test button. What I mean is Windows have to take over my text I've entered into, and be able to view text. For example: When I type in "Grayson" in the edit box, and hit "Test", that text string would then be carried over to a dialog box.

    Any suggestions?
    Please keep in mind that I had started to program Windows for the first time.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    If I understand;

    you want to type into one editbox.
    Start a new dialog.
    Have the string you typed in/on the new dialog.

    Look up SetDlgItemText() (or its MFC counterpart)

    I would suggest looking into just the WIN32 API. Understanding the API and how to use it will greatly improve your MFC when you need to do something 'different'.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Unregistered
    Guest

    Question Win32 API (Please note that I'm Grayson_PEDDIE< SO i'm in a hotel.)

    Where can I find that info of Win32 API out? Any suggestions?

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    static char buffer[256];
    GetDlgItemText(hDlg, nIDDlgItem, buffer, 255);

    then, when the dialog loads put.
    SetDlgItemText(hDlg2, nIDDlgItem, buffer);
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  5. #5
    Registered User Grayson_Peddie's Avatar
    Join Date
    May 2002
    Posts
    96

    Exclamation Needed detailed information!

    You didn't give me detailed information for what to put the code at...

    Oh... I somewhat forgot something...

    I have IDs and controls that I have in 2 dialogs:

    IDD_OUTPUTTEST_DIALOG : Main dialog

    IDC_QUESTION : Static text (What is your name?)
    IDC_NAME : Edit box {This is where I type in and send a text to a
    new dialog)
    IDC_SENDNAME : This button should copy the text and send them to a new dialog {Button: (Send)}

    IDOK : (Close) Acts as an OK button...

    In MFC ClassWizard:

    ~Begin...~

    Object ID: IDC_NAME
    Messages: EN_CHANGE
    Member Functions: OnChangeName ON_IDC_NAME EN_CHANGE

    (Indicates the display is updated after text changes)

    Object ID: IDC_SENDNAME
    Messages: BN_CLICKED
    Member Functions: OnSendname ON_IDC_SENDNAME BN_CLICKED

    (Indicates the user clicked a {left mouse} button)

    ~End of information in ClassWizard...~

    IDD_OUTPUT_TEXT_DLG : This is a dialog box where I get an output from an edit box I've inputted into a edit box and clicked Send

    IDC_TEXT_PREFIX : (Hi )
    IDC_OUTPUT_NAME : Border turned off; This is where I recieve text that I've typed from edit box in the previous main dialog

    IDOK : Return

    ClassWizard info I've implemented:

    Object IDs: IDC_OUTPUT_NAME
    Messages: EN_UPDATE
    Member Functions: OnUpdateOutputName ON_IDC_OUTPUT_NAME EN_UPDATE

    OK. I put the code in for those 2 files:

    One is for outputtestDlg.cpp, though I included Windows.h...:

    Code:
    void COutputtestDlg::OnChangeName() 
    {
        static char buffer[256];
        GetDlgItemText(IDD_OUTPUTTEST_DIALOG,
                       IDC_NAME,
                       buffer,
                       255);
    }
    
    void COutputtestDlg::OnSendname() 
    {
    }
    Others for outputtextstring.cpp:

    Code:
    void Outputtextstring::OnUpdateOutputName() 
    {
        extern char buffer;
        SetDlgItemText(IDD_OUTPUT_TEXT_DLG,
                       IDC_NAME,
                       buffer
                      );
    }
    Now I got 2 errors here:

    --------------------Configuration: outputtest - Win32 Debug--------------------
    Compiling...
    outputtestDlg.cpp
    C:\Learn\VCPP\outputtest\outputtestDlg.cpp(102) : error C2661: 'GetDlgItemTextA' : no overloaded function takes 4 parameters
    Outputtextstring.cpp
    C:\Learn\VCPP\outputtest\Outputtextstring.cpp(49) : error C2660: 'SetDlgItemTextA' : function does not take 3 parameters
    Generating Code...
    Compiling...
    outputtest.cpp
    Generating Code...
    Error executing cl.exe.

    outputtest.exe - 2 error(s), 0 warning(s)
    Last edited by Grayson_Peddie; 06-05-2002 at 04:10 AM.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    I think you are using the C versions not the MFC ones

    Try,

    SetDlgItemText(ID_CTRL, sBuffer);
    GetDlgItemText(ID_CTRL, sBuffer, iSizeOfBuffer);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  2. The space time continueimnms mm... (rant)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 06-27-2004, 01:21 PM
  3. Windows Rant followed by installation question
    By confuted in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 06-21-2003, 04:42 PM
  4. FlashWindowEx not declared?
    By Aidman in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2003, 02:58 AM
  5. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM