Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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.
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 24-Jan-13 7:53am
Rezame951
Comments
JackDingler at 24-Jan-13 13:46pm
   
Are you invalidating and repainting the dialog at any time?
Rezame at 24-Jan-13 13:48pm
   
This dialog only call one time, when start my application that this dialoge using on that.
JackDingler at 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 at 24-Jan-13 13:53pm
   
What do you get when you call GetWindowText, afterwards?
jibesh at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I think you should use SetDlgItem to set the text of a control in a dialog like below.
SetDlgItemText(hDlg, IDC_EDIT1, "reza"); 
  Permalink  
Comments
Rezame at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100