What is the Dialog Id, and how do I get it?

Discussion in 'Win32' started by xytor, Jan 24, 2009.

  1. xytor

    xytor Banned

    Joined:
    Jan 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hi, I created a few controls (some edits, a button) inside my window using CreateWindow.
    For the HMENU parameter, i just put in some arbitrary values I predefined. I assumed that this is the dialog id.
    However, when I use functions like SetDlgItemText, the second parameter, int nIDDlgItem, does not accept that HMENU id I gave it upon creation. (the function fails with error code ERROR_CONTROL_ID_NOT_FOUND)

    What is nIDDlgItem, and how do I get it?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Every resource in MFC has an ID and you can get that with the combination of RC file and resource.h file values.

    For Code you need to use the API GetDlgCtrlID function
     
  3. xytor

    xytor Banned

    Joined:
    Jan 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I am not using any resources, I'm just creating the controls using CreateWindow.
    Do I need to create my own resource.h file with the id's?
     
  4. xytor

    xytor Banned

    Joined:
    Jan 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Oh, sorry, I didn't notice that reference to GetDlgCtrlID,
    That should do it, thanks!
     
  5. xytor

    xytor Banned

    Joined:
    Jan 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    unfortunately, it didn't work.
    GetDlgCtrlID failed and returned 0. GetLastError also returned 0 after this.
    How is this possible? The controls are created and visible on the page.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You need to show us some code.

    Post it here.
     
  7. xytor

    xytor Banned

    Joined:
    Jan 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Actually, it was my mistake! I forgot to give it an id when creating it (and left it 0 by mistake)
    Sorry for wasting your time. I wish this forum let new users delete their posts...
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Yes they do when they cross some post count.
     
  9. yasirhs

    yasirhs New Member

    Joined:
    Jan 26, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice