How to read from edit control?

How to read in from edit control? I got an interface where the user has to input his/her username and password in order to log in. However, I dont know how to read in from the boxes...I found that Edit_GetText is used to get the text from it, but i dont know how to use it. I am also confused about Edit_GetPasswordChar and Edit_GetLine. Are these functions interchangeable in this case?

Researched Syntax:
1
2
3
4
5
int Edit_GetText(
  HWND hwndCtl,
  LPTSTR lpch,
  int cchMax
);


This is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
HWND login(HWND hwnd){
     HWND hWindow;     
   
     hWindow = CreateWindow("Static","Username: ", 
            WS_CHILD | WS_VISIBLE ,1,50,550,100,hwnd,(HMENU)NULL,NULL,NULL);
     hWindow = CreateWindow("EDIT", "",
			   WS_VISIBLE | WS_CHILD | WS_BORDER,
               80,50,80,20,
			   hwnd, (HMENU) ID_BUTTON, NULL, NULL
			   );
	 hWindow = CreateWindow("Static","Password: ", 
            WS_CHILD | WS_VISIBLE ,1,90,550,100,hwnd,(HMENU)NULL,NULL,NULL);		   
	 hWindow = CreateWindow("EDIT", "",
			   WS_VISIBLE | WS_CHILD | ES_PASSWORD | WS_BORDER,
               80,90,80,20,
			   hwnd, (HMENU) ID_BUTTON, NULL, NULL
			   );
     hWindow = CreateWindow("BUTTON", "LOGIN",
			   WS_VISIBLE | WS_CHILD | WS_BORDER,
               80,130,80,20,
			   hwnd, (HMENU) ID_BUTTON, NULL, NULL
			   );                      		  			
}
Last edited on
I'm not entirely sure but try GetWindowText().
According to the MSDN it retrieves the text of the window's title bar, but IIRC for an EDIT control the "title bar" text is the text written in the control.
How to actually use it in the program tho?
Are we supposed to do something like this:?
(I know its wrong.. but i am really noob..)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
int WINAPI GetWindowText(
  _In_   HWND hWnd,
  _Out_  LPTSTR lpString,
  _In_   int nMaxCount
);

HWND login(HWND hwnd){
     HWND hWindow; 
     TCHAR id [5], password [5];
     const int defaultid=12345;
     const int defaultpassword=23456;     

     hWindow = CreateWindowA("Static","Welcome!", 
               WS_CHILD | WS_VISIBLE ,1,1,500,100,hwnd,   
               HMENU)NULL,NULL,NULL);	
     hWindow = CreateWindow("Static","Username: ", 
            WS_CHILD | WS_VISIBLE ,1,50,550,100,hwnd,
            (HMENU)NULL,NULL,NULL);
     hWindow = CreateWindow("EDIT", "",
			WS_VISIBLE | WS_CHILD | WS_BORDER,
                        80,50,80,20,
			hwnd, (HMENU) ID_BUTTON, NULL, NULL
			);
     id=GetWindowText(hwnd,LPSTR,5);
     hWindow = CreateWindow("Static","Password: ", 
                        WS_CHILD | WS_VISIBLE ,1,90,550,100,hwnd,               
                        (HMENU)NULL,NULL,NULL);		   

     hWindow = CreateWindow("EDIT", "",
			WS_VISIBLE | WS_CHILD | ES_PASSWORD | WS_BORDER,
                        80,90,80,20, hwnd, (HMENU) ID_BUTTON, NULL, NULL
			);
     password=GetWindowText(hwnd,LPSTR,5);
     hWindow = CreateWindow("BUTTON", "LOGIN",
			WS_VISIBLE | WS_CHILD | WS_BORDER,
                        80,130,80,20,
			hwnd, (HMENU) ID_BUTTON, NULL, NULL
			);
     if (id==defaultid&&password==defaultpassword){
            hWindow= CreateWindow("Static","Log-in succesful! ", 
                 WS_CHILD | WS_VISIBLE ,1,90,550,100,hwnd,  
                 (HMENU)NULL,NULL,NULL);  
     }                                		  			
}

Last edited on
It's a bit more complicated. You need a window procedure, in there you can read the edit control after the user pressed the "Login" button. The GetWindowText() function can't be in the same function that creates the login window.

I recommend to read this article: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632597%28v=vs.85%29.aspx
It explains most of the things you need to know about window handling.

The most important things you should know about is the function RegisterClass(), the message loop and the window procedure.

About the window procedure read this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633570%28v=vs.85%29.aspx
Topic archived. No new replies allowed.