CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2004
    Posts
    13

    Why cant I get the resource ID?

    Why can not I get the resource ID of a dialog using GetDlgCtrlID?

    int CTestDlg::GetID()
    {
    return GetDlgCtrlID();
    }

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757
    Interesting.

    Try passing in NULL as the parameter. What does GetDlgCtrlID() return?

    Kuphryn

  3. #3
    Join Date
    Sep 2002
    Posts
    924
    Is your dialog a child window or a top-level window?

    From the documentation of GetDlgCtrlID():
    Although GetDlgCtrlID may return a value if hwndCtl is a handle to a top-level window, top-level windows cannot have identifiers and such a return value is never valid.

  4. #4
    Join Date
    Jun 2004
    Posts
    13
    I have tired creating the dialog as a top-level window as well as a child window, but it always returns 0.

    Well, how can I get the resoucre ID even it is a top-level window?

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Quote Originally Posted by kuphryn
    Try passing in NULL as the parameter. What does GetDlgCtrlID() return?
    Since he obviously uses the 'CWnd' version, how would he supposed to pass 0? The function does not take any parameter as opposed to the API version...

  6. #6
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Quote Originally Posted by PomeloWu
    I have tired creating the dialog as a top-level window as well as a child window, but it always returns 0.

    Well, how can I get the resoucre ID even it is a top-level window?
    Note that GetDlgCtrlID() gives you the control ID of a control - that's something else than the resource ID. AFAIK, there's no way to determine the original resource ID of a dialog once it is created. Anyway, what do you need this for? If you absolutely need to know the ID of the resource at runtime, you could do the following: Create your own CDialog-derived class and derive all your app's dialogs from that class (instead of deriving directly from CDialog). Then add a ctor similar to that of CDialog, which, besides from calling the base ctor, saves the resource ID that is passed upon creation to a member variable. You can then add a member function GetResourceID() which returns that value.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured