Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,
I have code using one form for that. My code is pure win32.
I want try set one predefined text for one Edit_Box.
C++
INT_PTR CALLBACK DialogFunc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	HMENU hMenu;
	
	switch(uMsg)
	{
	case WM_INITDIALOG:
		
		break;
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case IDC_BUTTON2:
			char buff1[1024];
			char buff2[1024];
			char buff3[1024];
			hDlg1=GetDlgItem(hDlg,IDC_EDIT1);
			hDlg3=hDlg;
			read(pathh);
			MessageBox(0,UserSaved,0,0);
			SetWindowText(hDlg1,"reza");
			GetWindowText(hDlg1,username,1024);
			write(pathh);
			hDlg2=GetDlgItem(hDlg,IDC_EDIT2);
			GetWindowText(hDlg2,key,1024);
			if(memcmp(Get_Account_Number_FromWEB(),b1,sizeof(b1))==0 ){result=1; DestroyWindow(hDlg);}
			else MessageBox(0,TEXT("Wrong User or PWD"),0,0);
		  
			break;
			case IDC_BUTTON3:
				DestroyWindow(hDlg);
				break;
				case IDC_EDIT1:
		         break;
			case IDC_EDIT2:
              break;

			
		
		}
		break;
	case WM_CLOSE:
		SetWindowLongA(hDlg, GWL_WNDPROC, dwNewLong);
		DestroyWindow(hDlg);
		return TRUE;
		break;
	
	}
	return FALSE;
}


SetWindowText(hDlg1,"reza") not set "reza" in IDC_EDIT1.
I tried SetWindowTextA(hDlg1,"reza") too but not worked too.

How to solve that?
Regards,
Posted
Comments
JackDingler 24-Jan-13 13:46pm    
Are you invalidating and repainting the dialog at any time?
Rezame 24-Jan-13 13:48pm    
This dialog only call one time, when start my application that this dialoge using on that.
JackDingler 24-Jan-13 13:52pm    
So does your dialog get a paint message after you set the window text?

If it doesn't, your change may be taking place. You just can't see it.
JackDingler 24-Jan-13 13:53pm    
What do you get when you call GetWindowText, afterwards?
Jibesh 24-Jan-13 13:49pm    
move your Text setting code to WM_INITDIALOG, WM_COMMAND will be executed only when someone send a command message to this dialog

SetWindowsText should be applicable to valid window handle, of the type HWND. I don't know if hDlg value you used is valid, but this is what you should use as a first parameter of the call to SetWindowsText. This should change the title text of the dialog. If you want to modify some other text, you should use some other valid HWND. This is just the first bug I could spot; you might have other ones.

—SA
 
Share this answer
 
I think you should use SetDlgItem to set the text of a control in a dialog like below.
VC
SetDlgItemText(hDlg, IDC_EDIT1, "reza"); 
 
Share this answer
 
Comments
Rezame 25-Jan-13 2:38am    
Hi,
Jibesh below your solution works:

move your Text setting code to WM_INITDIALOG, WM_COMMAND will be executed only when someone send a command message to this dialog

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900