OldSchoolCode

.com



Edit controls
Ok, were going to add to our previous tutorial :)

From the toolbox, drag a "Static Text" control over and drop it on your dialog box. You will see that it has a default string ( Static ) shown. You will need to resize the length of the box by clicking on the edge and dragging it out. Let's change the defaults :)

With the static text control selected select the "properties" tab. The top line will show "align text". Change it to center. Change the name to IDC_TEXT1. Change the "Caption" from Static to "Hello" and press the enter key on you computer. The Static Text control now shows "Hello". As you can see, you set any text in the Static text control you would like OR you can populate it when you initialize the dialog box. We can do this by calling the function..
SetDlgItemText( hwnd, IDC_TEXT1, "string" );
Go back to the properties of your Static Text control and remove "Hello" leaving it blank. We will send it a string when we initialaize the dialog box.

From you toolbox drag an "Edit Control" over to your dialog box and place it under your blank Static Text control. With the Edit Control selected ( click on the control ) select the properties and change the name to IDC_EDIT1. We will ask the user to type their name in it. Here is another function to get the name entered in the Edit Control.
GetDlgItemText( hwnd, IDC_EDIT1, name, 260 );
In our message listening function we are going to add WM_INITDIALOG. This is the message that is sent when your dialog box is first starting up.

take a look at the sample code...

__________________________________________________________
#include <stdio.h>
#include <windows.h>
#include "resource.h"

INT_PTR CALLBACK DialogMessages(HWND hwnd,UINT 
                                uMsg,WPARAM wparam,LPARAM lparam)
{
    //when the dialog box is first
    //initialized have it send the string " Type in your
    //first name" to our Static Text control
    if( uMsg == WM_INITDIALOG )
    {
        char string [260]= "Type in your first name";

        SetDlgItemText( hwnd, IDC_TEXT1, string );
    }

    if ( uMsg == WM_COMMAND )
    {
        //when the OK button is clicked after
        //the user enters their name, open a messsage box showing
        //the name they entered :)
        if ( HIWORD(wparam) == BN_CLICKED )
        {
            if (LOWORD(wparam) == IDOK)
            {
                char name [260];

                //get the name entered from
                //our Edit Control
                GetDlgItemText( hwnd, IDC_EDIT1, name, 260 );

                //put the name entered in
                //our message box
                MessageBox( NULL,name, "messagebox", 
                            MB_OK|MB_ICONEXCLAMATION  );

                EndDialog( hwnd, 0 );
                return TRUE;
            }
      
            else if (LOWORD(wparam) == IDCANCEL)
            {
                EndDialog( hwnd, 0 );
                return TRUE;
            }
        }
    }

return FALSE;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE 
                            hPrevInstance, LPSTR pCmdLine, int iCmdShow)
{
    DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_MYDIALOG), 
                                            NULL, DialogMessages);
	
    return 0;
}