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. Proper way to add item to ListCtrl

Proper way to add item to ListCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
c++
4 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.
  • M Offline
    M Offline
    Manmohan29
    wrote on last edited by
    #1

    tell me proper way to add an item to ListCtrl. Here is my code:-

    // stdafx.h
    #define WM_MYMESSAGE (WM_USER+1)


    // MyThread.h

    class CMyThread : public CWinThread
    {
    DECLARE_DYNCREATE(CMyThread)
    .
    .
    .
    public:
    unsigned int f0ll, f1ll, f2ll, f3ll;
    unsigned int f0ul, f1ul, f2ul, f3ul;

    public:
    afx_msg void MyMessageHandler(WPARAM, LPARAM);


    // MyThread.cpp
    .
    .
    .
    afx_msg void CMyThread::MyMessageHandler(WPARAM, LPARAM)
    {
    // I have to add an item to ListCtrl here
    }
    BEGIN_MESSAGE_MAP(CMyThread, CWinThread)
    ON_THREAD_MESSAGE(WM_MYMESSAGE, MyMessageHandler)
    END_MESSAGE_MAP()


    // IPMDlg.cpp
    .
    .
    .
    void CIPMDlg::OnBnClickedBrefreshdevices()
    {
    .
    .
    .
    pRefreshThread = AfxBeginThread(RUNTIME_CLASS(CMyThread));
    pRefreshThread->PostThreadMessage(WM_MYMESSAGE, 0, 0);
    }

    Future Lies in Present. Manmohan Bishnoi

    Richard Andrew x64R 1 Reply Last reply
    0
    • M Manmohan29

      tell me proper way to add an item to ListCtrl. Here is my code:-

      // stdafx.h
      #define WM_MYMESSAGE (WM_USER+1)


      // MyThread.h

      class CMyThread : public CWinThread
      {
      DECLARE_DYNCREATE(CMyThread)
      .
      .
      .
      public:
      unsigned int f0ll, f1ll, f2ll, f3ll;
      unsigned int f0ul, f1ul, f2ul, f3ul;

      public:
      afx_msg void MyMessageHandler(WPARAM, LPARAM);


      // MyThread.cpp
      .
      .
      .
      afx_msg void CMyThread::MyMessageHandler(WPARAM, LPARAM)
      {
      // I have to add an item to ListCtrl here
      }
      BEGIN_MESSAGE_MAP(CMyThread, CWinThread)
      ON_THREAD_MESSAGE(WM_MYMESSAGE, MyMessageHandler)
      END_MESSAGE_MAP()


      // IPMDlg.cpp
      .
      .
      .
      void CIPMDlg::OnBnClickedBrefreshdevices()
      {
      .
      .
      .
      pRefreshThread = AfxBeginThread(RUNTIME_CLASS(CMyThread));
      pRefreshThread->PostThreadMessage(WM_MYMESSAGE, 0, 0);
      }

      Future Lies in Present. Manmohan Bishnoi

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      If "MyThread" is not the thread that owns the ListCtrl, then you will have problems. You must add items to the ListCtrl only from the thread that created the ListCtrl.

      M 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        If "MyThread" is not the thread that owns the ListCtrl, then you will have problems. You must add items to the ListCtrl only from the thread that created the ListCtrl.

        M Offline
        M Offline
        Manmohan29
        wrote on last edited by
        #3

        CIPMDlg class created the ListCtrl should I post a message back to the main thread's message pump to add item to ListCtrl

        Future Lies in Present. Manmohan Bishnoi

        D 1 Reply Last reply
        0
        • M Manmohan29

          CIPMDlg class created the ListCtrl should I post a message back to the main thread's message pump to add item to ListCtrl

          Future Lies in Present. Manmohan Bishnoi

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Manmohan29 wrote:

          should I post a message back to the main thread's message pump to add item to ListCtrl

          Yes.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Man who follows car will be exhausted." - Confucius

          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