CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 1999
    Posts
    1

    Locating a control on a dialog


    I am attempting to locate a control on a dialog window via it's ID name.
    The difficulty is caused by the fact that the name is being generated
    using the following function:


    /*
    * Get current component : returns a pointer to the image on the
    * setup map currently being processed
    */
    CStatic* CqcExpSetup::GetCurrentComponent(int x, int y)
    {
    char ControlName[10];
    sprintf(ControlName, "IDC_SM%02d%02d", x, y);

    return (CStatic*) ------------(ControlName);
    } /^\
    |



    I can't find a function to do the job of the blanked out section. I have
    tried GetDlgItem(nID), however this is expecting the int value for the
    control. I need a function that takes the 10 character string calculated
    from the x and y co-ordinates, finds a (CStatic) control of the same name
    and returns it's id number for the GetDlgItem() function call.

    Either that, or I need a function that can find the CStatic control with
    the calculated name, and return a pointer to it.

    Thanks for any assistance.

    Colin Smith



  2. #2
    Join Date
    Jun 1999
    Location
    San Diego, CA
    Posts
    600

    Re: Locating a control on a dialog

    Resource ID names such like IDC_MY_STATIC_CONTROL are for programmers to read, internally the computer represent each resource using it's numerical resource ID, if you open the resource.h file you will see how the resource IDs are defined as numbers.

    In your case, you want to deal with the numerical resource ID, not the symbolic name of them. Your code can look like this:

    UINT myReourceID;

    myResourceID = IDC_SM_BASE + (x*100 + y);
    return (CStatic *) GetDlgItem(myResourceID);

    Be careful that any mixture of x and y would yield a valid resource ID that is actually used in your dialog box.


    I hate fat programs as much as I hate being fat myself. I am lean and mean and so is my program.

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