Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do I ensure a unique ID for my dynamically created button?

How do I ensure a unique ID for my dynamically created button?

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tommy H D Svensson
    wrote on last edited by
    #1

    Hi all, I create a button dynamically but as it is now, I create the button ID myself like this cause in this case I can't use the editor to create it: #define ID_MY_BUTTON 33333 But how do I ensure a unique ID for this dynamically created button? /Tommy

    X 1 Reply Last reply
    0
    • T Tommy H D Svensson

      Hi all, I create a button dynamically but as it is now, I create the button ID myself like this cause in this case I can't use the editor to create it: #define ID_MY_BUTTON 33333 But how do I ensure a unique ID for this dynamically created button? /Tommy

      X Offline
      X Offline
      XKent
      wrote on last edited by
      #2

      You can use _APS_NEXT_CONTROL_VALUE. Resource editor store here value which will be given to the next created control - so values above this not used. Acid will burn!

      L T 2 Replies Last reply
      0
      • X XKent

        You can use _APS_NEXT_CONTROL_VALUE. Resource editor store here value which will be given to the next created control - so values above this not used. Acid will burn!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        i afraid it is good for first control but not for system dialog or any ole ctrls there he must search all parent's sub-windows or similar (?) t!

        1 Reply Last reply
        0
        • X XKent

          You can use _APS_NEXT_CONTROL_VALUE. Resource editor store here value which will be given to the next created control - so values above this not used. Acid will burn!

          T Offline
          T Offline
          Tommy H D Svensson
          wrote on last edited by
          #4

          Ok, so you mean that I can do like this: m_pBtn->Create(_T("Button"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE); Because m_pBtn is not associated with a resource editor created control, it's createed from scratch and subclassed dynamically. /T

          X 1 Reply Last reply
          0
          • T Tommy H D Svensson

            Ok, so you mean that I can do like this: m_pBtn->Create(_T("Button"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE); Because m_pBtn is not associated with a resource editor created control, it's createed from scratch and subclassed dynamically. /T

            X Offline
            X Offline
            XKent
            wrote on last edited by
            #5

            This true only for first item, then you must increase value youreself: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+1); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+2); You keeping unique values. You need do this only in one scope, so when you create item with different's parent you can use same ID's: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd1, _APS_NEXT_CONTROL_VALUE); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd2, _APS_NEXT_CONTROL_VALUE); There is no problem, couse different parent's: pWnd1, pWnd2. Acid Will Burn!

            T 2 Replies Last reply
            0
            • X XKent

              This true only for first item, then you must increase value youreself: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+1); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+2); You keeping unique values. You need do this only in one scope, so when you create item with different's parent you can use same ID's: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd1, _APS_NEXT_CONTROL_VALUE); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd2, _APS_NEXT_CONTROL_VALUE); There is no problem, couse different parent's: pWnd1, pWnd2. Acid Will Burn!

              T Offline
              T Offline
              Tommy H D Svensson
              wrote on last edited by
              #6

              Ok, thx XKent! /T

              1 Reply Last reply
              0
              • X XKent

                This true only for first item, then you must increase value youreself: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+1); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), this, _APS_NEXT_CONTROL_VALUE+2); You keeping unique values. You need do this only in one scope, so when you create item with different's parent you can use same ID's: m_pBtn->Create(_T("Button1"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd1, _APS_NEXT_CONTROL_VALUE); m_pBtn->Create(_T("Button2"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0,0,19,14), pWnd2, _APS_NEXT_CONTROL_VALUE); There is no problem, couse different parent's: pWnd1, pWnd2. Acid Will Burn!

                T Offline
                T Offline
                Tommy H D Svensson
                wrote on last edited by
                #7

                Hi again, What must I include in order to use the _APS_NEXT_CON... value?

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups