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 to use arguments Control in another class

how to use arguments Control in another class

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialcsharphelp
5 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.
  • S Offline
    S Offline
    so0_lanhlung2
    wrote on last edited by
    #1

    i have a Dialog and ListBox i created a class to manipulate Controls: CControl my class have function: BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId) and in Dialog's function: CControl ctr; ctr.GetAllProcess(IDC_LIST1,arrProcId); but can't convert int to CListBox don't same CSharp plz Help me... very clearly if you have a example for me...thanks very much sorry if my english isn't good

    H A 2 Replies Last reply
    0
    • S so0_lanhlung2

      i have a Dialog and ListBox i created a class to manipulate Controls: CControl my class have function: BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId) and in Dialog's function: CControl ctr; ctr.GetAllProcess(IDC_LIST1,arrProcId); but can't convert int to CListBox don't same CSharp plz Help me... very clearly if you have a example for me...thanks very much sorry if my english isn't good

      H Offline
      H Offline
      Hans Dietrich
      wrote on last edited by
      #2

      You have defined the function this way:

      BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId)

      but you are calling it this way:

      ctr.GetAllProcess(IDC_LIST1,arrProcId);

      . You can't convert from IDC_LIST1 to a CListCtrl; one is a numeric id, the other is a class. Look at the examples here on Codeproject about how to use the CListCtrl class. Basically, you need to use the resource editor to create a CListCtrl variable; a DDX statement will attach the CListCtrl variable to IDC_LIST1. And you probably want to write the function like this:

      BOOL CControl::GetAllProcess(CListCtrl& list1, int *arrProcId)

      Best wishes, Hans


      [Hans Dietrich Software]

      S 1 Reply Last reply
      0
      • S so0_lanhlung2

        i have a Dialog and ListBox i created a class to manipulate Controls: CControl my class have function: BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId) and in Dialog's function: CControl ctr; ctr.GetAllProcess(IDC_LIST1,arrProcId); but can't convert int to CListBox don't same CSharp plz Help me... very clearly if you have a example for me...thanks very much sorry if my english isn't good

        A Offline
        A Offline
        Andrew Brock
        wrote on last edited by
        #3

        You need to use GetDlgItem()[^] to get the window handle from the control ID. If this is called from within a CWnd derived class this will return a CWnd object which can be cast to the list control. See CWnd::GetDlgItem()[^] Also, window classes are generally passed around as pointers. At a very minimum they should be passed as a reference as Hans suggested. Passing by value will create a copy of the class. Properties changed in the copied class may not reflect back on the original.

        BOOL CControl::GetAllProcess(CListCtrl *list1, int *arrProcId) {
        //do stuff
        }

        CControl ctr;
        ctr.GetAllProcess(GetDlgItem(IDC_LIST1), arrProcId);

        S 1 Reply Last reply
        0
        • H Hans Dietrich

          You have defined the function this way:

          BOOL CControl::GetAllProcess(CListCtrl list1, int *arrProcId)

          but you are calling it this way:

          ctr.GetAllProcess(IDC_LIST1,arrProcId);

          . You can't convert from IDC_LIST1 to a CListCtrl; one is a numeric id, the other is a class. Look at the examples here on Codeproject about how to use the CListCtrl class. Basically, you need to use the resource editor to create a CListCtrl variable; a DDX statement will attach the CListCtrl variable to IDC_LIST1. And you probably want to write the function like this:

          BOOL CControl::GetAllProcess(CListCtrl& list1, int *arrProcId)

          Best wishes, Hans


          [Hans Dietrich Software]

          S Offline
          S Offline
          so0_lanhlung2
          wrote on last edited by
          #4

          oh thanks for your help :)..so much

          1 Reply Last reply
          0
          • A Andrew Brock

            You need to use GetDlgItem()[^] to get the window handle from the control ID. If this is called from within a CWnd derived class this will return a CWnd object which can be cast to the list control. See CWnd::GetDlgItem()[^] Also, window classes are generally passed around as pointers. At a very minimum they should be passed as a reference as Hans suggested. Passing by value will create a copy of the class. Properties changed in the copied class may not reflect back on the original.

            BOOL CControl::GetAllProcess(CListCtrl *list1, int *arrProcId) {
            //do stuff
            }

            CControl ctr;
            ctr.GetAllProcess(GetDlgItem(IDC_LIST1), arrProcId);

            S Offline
            S Offline
            so0_lanhlung2
            wrote on last edited by
            #5

            nice....thanks ^^

            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