Thread: Edit Box not updating in MFC App

  1. #1
    Unregistered
    Guest

    Edit Box not updating in MFC App

    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,,

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    19
    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,,

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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?

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Actually this should do it:

    In your dialog's 'OnInitDialog()' function place:

    SetDlgItemText(IDC_dept,"some text");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiline Edit Box Parser
    By The Brain in forum Windows Programming
    Replies: 6
    Last Post: 11-01-2005, 07:15 PM
  2. Replies: 3
    Last Post: 07-23-2005, 08:00 AM
  3. display a file in dropdown edit box
    By sunburnbyRA in forum Windows Programming
    Replies: 2
    Last Post: 03-10-2004, 01:58 PM
  4. Dialog Box & Property Sheet :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 01:33 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM