Can anyone tell me why the following does not work? Do I need to call an update function. No errors are displayed and the program runs and compiles but IDC_dept is always blank.
SetDlgItemText(GetForegroundWindow(), IDC_dept, "AAA");
Thanks,,
Printable View
Can anyone tell me why the following does not work? Do I need to call an update function. No errors are displayed and the program runs and compiles but IDC_dept is always blank.
SetDlgItemText(GetForegroundWindow(), IDC_dept, "AAA");
Thanks,,
Apologetic disclaimer: I don't use mfc.
1. Probably because GetForegroundWindow is not returning the handle of your edit cntrl - or the class fn 'SetDlgItemText' is being called with insufficient params.
2. If you are using mfc then you should use the class methods:
MyCEditThing.SetDlgItemText(IDC_dept, "AAA");
or MyCEditThing->SetDlgItemText(IDC_dept, "AAA");
depending on how you initialised MyCEditThing.
3. If you still want to use the API fn (note scope resolution operator):
::SetDlgItemText(MyCEdit.m_hWnd,IDC_dept, "AAA");
or ::SetDlgItemText(::GetDlgItem(hParent,IDC_dept),ID C_dept, "AAA");
etc.
Hope that helps some.
I dont have anything close to CeditThing. I have 3 classes App, DLG and a custom class I created myself.
I tried your other suggestions but they did not work. Also GetLastError() returns 0 on the original code!
Any more ideas? this is a simple dialog (form based) app..
Could someone post some sample code so I can try and figure it out.
Thk,,
So you are not using CEdit as an object wrapper around your edit cntrl then? ('CeditThing' was a pseudocode placeholder for the name you might have chosen for a CEdit object - forgive me for assuming that you would have realised this).
What's the point of using mfc if you aren't using its 'features'?
Use win32 API instead.
Here's the code (again):
SetDlgItemText(GetDlgItem(hParent,IDC_dept),ID
C_dept, "AAA");
If that doesn't work to place the text "AAA" in the edit cntrl with id=IDC_dept and parent wnd handle of 'hParent' (YOU must supply this) - then you are very probably doing something wrong.
Where exactly in your program are you attempting to set the cntrl's text?
Actually this should do it:
In your dialog's 'OnInitDialog()' function place:
SetDlgItemText(IDC_dept,"some text");