Edit Box from funtion
-
Hello! I am new to MFC. I want to change an Edit Box from a function! The situation is the following (simplified):
int function(); //Prototype void TestDlg::OnGo() { SetDlgItemText(IDC_Output, "From OnGo!!!"); //Works fine function(); // Call my function } int function() { SetDlgItemText(IDC_Output, "From funtion()!!"); // ERROR }
So, the output from the function does not work. I know, I have to append something, but what????? -
Hello! I am new to MFC. I want to change an Edit Box from a function! The situation is the following (simplified):
int function(); //Prototype void TestDlg::OnGo() { SetDlgItemText(IDC_Output, "From OnGo!!!"); //Works fine function(); // Call my function } int function() { SetDlgItemText(IDC_Output, "From funtion()!!"); // ERROR }
So, the output from the function does not work. I know, I have to append something, but what?????Try like this from function CEdit *edit; edit=(CEdit*)GetDlgItem(IDC_Output); edit->SetWindowText("From function()!!"); Regards Alpha
-
Hello! I am new to MFC. I want to change an Edit Box from a function! The situation is the following (simplified):
int function(); //Prototype void TestDlg::OnGo() { SetDlgItemText(IDC_Output, "From OnGo!!!"); //Works fine function(); // Call my function } int function() { SetDlgItemText(IDC_Output, "From funtion()!!"); // ERROR }
So, the output from the function does not work. I know, I have to append something, but what?????There are two solutions to your problem: 1. Make
function()
a member of of your TestDlg class. or, 2. You need to pass handle of dialog window (HWND) toSetDlgItemText
as first parameter, infunction
:SetDlgItemText(hWnd, IDC_Output, "From funtion()!!");
You may pass this handle to
function
. This handle is member of TestDlg class with namem_hWnd
. ARSALAN MALIK -
Try like this from function CEdit *edit; edit=(CEdit*)GetDlgItem(IDC_Output); edit->SetWindowText("From function()!!"); Regards Alpha
-
Doesnt work, GetDlgItem() asks for Window Hande (doesn't accept 1 Parameter)! How can I get this? WoodStock
Their are two versions of GetDlgItem. 1. The SDK version needs two param 2. The CWindow::GetDlgItem and CWnd::GetDlgItem needs 1 param. Are you getting some compiler errors ?. Regards Alpha
-
There are two solutions to your problem: 1. Make
function()
a member of of your TestDlg class. or, 2. You need to pass handle of dialog window (HWND) toSetDlgItemText
as first parameter, infunction
:SetDlgItemText(hWnd, IDC_Output, "From funtion()!!");
You may pass this handle to
function
. This handle is member of TestDlg class with namem_hWnd
. ARSALAN MALIK -
Hello! I am new to MFC. I want to change an Edit Box from a function! The situation is the following (simplified):
int function(); //Prototype void TestDlg::OnGo() { SetDlgItemText(IDC_Output, "From OnGo!!!"); //Works fine function(); // Call my function } int function() { SetDlgItemText(IDC_Output, "From funtion()!!"); // ERROR }
So, the output from the function does not work. I know, I have to append something, but what?????You've not shown what the error is. Although it's obvious in this example, it still doesn't hurt to be explicit. Change
function()
to:int TestDlg::function()
{
...
}and don't forget to add the prototype to the class. Don't use
SetDlgItemText()
. Use ClassWizard to create a control variable (CEdit
in this case) and use theSetWindowText()
method to change the text.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen