is there anyway to just completely clear every edit box ina window? And is there any way for the prog to write stuff in edit boxes after the user does something?
Printable View
is there anyway to just completely clear every edit box ina window? And is there any way for the prog to write stuff in edit boxes after the user does something?
>> And is there any way for the prog to write stuff in edit boxes after the user does something? <<
Just send a message I believe with the message being EM_SETTEXT (maybe this, but something like this). I'll look for the reference. I'm not sure if that's the constant. I just...blanked out :D
Garfield
If you know in advance the handles of the edits then sending a WM_SETTEXT msg with appropriate params will work (SetDlgItemText does the same thing, SetWindowText too) to set the text to anything you want, including clearing all text. To respond to user input you must trap the EN_CHANGE msg within the parent's WM_COMMAND handler.
If you don't know in advance what the edit handles are, or if there are a variety of cntrls then you might want to consider using EnumChildWindows. You will have to define a callback fn which is called for each child cntrl. The callback will be sent the handle of each child wnd in turn so you can use GetClassName on that handle to see whether it is "EDIT". Return FALSE from the callback fn to signal you are finished.
eg.
Hope that is of some use to you.Code:const int NUM_EDITS=10; //eg you have 10 edit cntrls
int nNumEditCntrls=NUM_EDITS;
BOOL CALLBACK MyEnumChildProc(HWND hwnd,LPARAM lParam)
{
if (!lstrcmp(CharUpper(GetClassName(hwnd)),TEXT("EDIT")))
{
//cntrl is EDIT so clear it
SetWindowText(hwnd,TEXT(""));
nNumEditCntrls--;
if (!nNumEditCntrls)
{
return FALSE; //no more edits
}
}
return TRUE; //keep enumerating child wnd's
}
////////////////////////////////
//To call the EnumChildProc:
EnumChildWindows(hParent,MyEnumChildProc,0);