none
SetFocus throws the error "class "System::Int32" has no member "SetFocus" " RRS feed

All replies

  • You're probably trying to setFocus on an integer variable.

    The SetFocus method exists usually on controls e.g. a form, textbox.


    "If there's nothing wrong with me, maybe there's something wrong with the universe!"

    Tuesday, October 13, 2015 5:42 AM
  • I'm using an OpenFielDialog and converting the resultant stream to CString. Now I want to display the filename and path on the edittext box. I'm using SetWindowText() for it. But the path and file name is not getting displayed on the edittext box. So i though of using SetFocus() before SetWindowText(). The it throws this error.
    Tuesday, October 13, 2015 5:46 AM
  • Probably you should use something like ‘SetFocus(hwnd)’ instead of ‘hwnd.SetFocus()’. Show your definitions and code related to SetWindowText and SetFocus.

    Tuesday, October 13, 2015 6:44 AM
  • void CMFCApplication6Dlg::OnBnClickedBrowse()
    {
    	System::IO::Stream^ myStream;
    	
    	System::Windows::Forms::OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
    	CString path;
    
    	openFileDialog1->InitialDirectory = "c:\\";
    	openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
    	openFileDialog1->FilterIndex = 2;
    	openFileDialog1->RestoreDirectory = true;
    
    	
    	if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
    	{
    		if ((myStream = openFileDialog1->OpenFile()) != nullptr)
    		{
    			path = myStream->ToString();
    			editBox1.SetWindowText(path);			
    			myStream->Close();
    		}
    	}
    }
    


    Tuesday, October 13, 2015 6:59 AM
  • The error is " error C2039: 'SetWindowTextW' : is not a member of 'System::Int32' ".
    Tuesday, October 13, 2015 7:01 AM
  • Seems that editBox1 is not a CEdit. In order to check, place the cursor, then press <F12>.

    What editBox1 is?

    Using Dialog Editor, try adding another variable associated with textbox, but select “Control Variable” checkbox and “CEdit” variable type.

    By the way, there are other MFC-based ways to display the file dialogs, which do not require mixing with .NET technology.

    • Edited by Viorel_MVP Tuesday, October 13, 2015 7:18 AM
    Tuesday, October 13, 2015 7:18 AM
  • editBox1 is the variable added to the edittext box.

    Sorry forgot to mention it with my previous comment.

    Tuesday, October 13, 2015 7:22 AM
  • editBox1 is already a control variable of type CEdit. and If you can suggest me more simpler ways to implement this, please help me out with it.
    Tuesday, October 13, 2015 7:27 AM
  • If not difficult, check the header file of your CMFCApplication6Dlg or other files. How is editBox1 defined, is it “CEdit editBox1;”?

    Tuesday, October 13, 2015 7:29 AM
  • Check:

    Compiler Error C2039

    msdn[dot]microsoft[dot]com/en-us/library/fdwb3fd7%28VS.80%29[dot]aspx

    (Replace . with [dot] )

    Tuesday, October 13, 2015 7:32 AM
  • Te type was of int and then i changed it to CEdit in the header file. But then this error shows up

    error C2664: 'CEdit::CEdit(const CEdit &)' : cannot convert argument 1 from 'int' to 'const CEdit &'   

    I have included the block of code where this error is thrown.

    When i place the arrow over the red marker it shows the following

    IntelliSense: no instance of constructor "CEdit::CEdit" matches the argument list
                argument types are: (int)   

    Tell me If you need any additional details to solve the error.

    CMFCApplication6Dlg::CMFCApplication6Dlg(CWnd* pParent /*=NULL*/)
    	: CDialogEx(CMFCApplication6Dlg::IDD, pParent)
    	, browseButton(0)
    	, editBox1(0)
    {
    	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }

    Tuesday, October 13, 2015 8:09 AM