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. Display data in Dialog Box

Display data in Dialog Box

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
3 Posts 2 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.
  • L Offline
    L Offline
    louis 0
    wrote on last edited by
    #1

    Hi there, I can't seem to display my data received from a host PC in my listbox which is placed in a dialog, using an SDI application. this code however works fine when I used a single dialog application. Can someone please help. here are some code. /****************************************/ //MySocket.h /***************************************/ .... .... .... class CMyListBox; ///////////////////////////////////////////////////////////////// /// CMySocket command target class CMySocket : public CAsyncSocket { // Attributespublic: // Operations public: char m_charBuff[sizeof(RcvStvRec)]; UINT m_nSendersPort; CString m_strSendersIP; CMySocket(); virtual ~CMySocket(); // Overrides public: // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMySocket) public: virtual void OnReceive(int nErrorCode); //}}AFX_VIRTUAL............} /***************************************/ //MySocket.cpp /***************************************/ void CMySocket::OnReceive(int nErrorCode) { if (m_bActivateDlg) { if (m_pModeless == NULL) { m_pModeless = new CMyListBox; m_pModeless->Create(IDD_DIALOG2); m_pModeless->ShowWindow(TRUE); } m_bActivateDlg = FALSE; // create modeless dialog box only once } int nError = ReceiveFrom (m_charBuff, sizeof(m_charBuff),m_strSendersIP, m_nSendersPort); MoveMemory(&RcvStv, &m_charBuff, sizeof(TRcvStvRec)); CMyListBox *Ref=(CMyListBox *)AfxGetApp()->m_pMainWnd; Ref->UpdateListBox(); // function in MyListBox.cpp CAsyncSocket::OnReceive(nErrorCode); } /******************************************/ //MyListBox.h /******************************************/ ... .... ..... # include "MySocket.h" class CMySocket; //////////////////////////////////////////////////////////////////////////// /// CMyListBox dialog class CMyListBox : public CDialog { // Construction public: int m_nCount, m_nListCount; CListBox *pList; void UpdateListBox (); CMyListBox(CWnd* pParent = NULL); // standard constructor ... .... ..... } /******************************************/ //MyListBox.cpp /******************************************/ void CMyListBox::UpdateListBox() { CString Rv, RCount; pList = (CListBox *) (GetDlgItem(IDC_LIST1)); if ((m_nListCount = pList->GetCount()) > 50) { pList->ResetContent(); // clear listbox when full } RCount.Format("%d ", m_nCount); Rv.Format("%d, %10.3f, %10

    M 1 Reply Last reply
    0
    • L louis 0

      Hi there, I can't seem to display my data received from a host PC in my listbox which is placed in a dialog, using an SDI application. this code however works fine when I used a single dialog application. Can someone please help. here are some code. /****************************************/ //MySocket.h /***************************************/ .... .... .... class CMyListBox; ///////////////////////////////////////////////////////////////// /// CMySocket command target class CMySocket : public CAsyncSocket { // Attributespublic: // Operations public: char m_charBuff[sizeof(RcvStvRec)]; UINT m_nSendersPort; CString m_strSendersIP; CMySocket(); virtual ~CMySocket(); // Overrides public: // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMySocket) public: virtual void OnReceive(int nErrorCode); //}}AFX_VIRTUAL............} /***************************************/ //MySocket.cpp /***************************************/ void CMySocket::OnReceive(int nErrorCode) { if (m_bActivateDlg) { if (m_pModeless == NULL) { m_pModeless = new CMyListBox; m_pModeless->Create(IDD_DIALOG2); m_pModeless->ShowWindow(TRUE); } m_bActivateDlg = FALSE; // create modeless dialog box only once } int nError = ReceiveFrom (m_charBuff, sizeof(m_charBuff),m_strSendersIP, m_nSendersPort); MoveMemory(&RcvStv, &m_charBuff, sizeof(TRcvStvRec)); CMyListBox *Ref=(CMyListBox *)AfxGetApp()->m_pMainWnd; Ref->UpdateListBox(); // function in MyListBox.cpp CAsyncSocket::OnReceive(nErrorCode); } /******************************************/ //MyListBox.h /******************************************/ ... .... ..... # include "MySocket.h" class CMySocket; //////////////////////////////////////////////////////////////////////////// /// CMyListBox dialog class CMyListBox : public CDialog { // Construction public: int m_nCount, m_nListCount; CListBox *pList; void UpdateListBox (); CMyListBox(CWnd* pParent = NULL); // standard constructor ... .... ..... } /******************************************/ //MyListBox.cpp /******************************************/ void CMyListBox::UpdateListBox() { CString Rv, RCount; pList = (CListBox *) (GetDlgItem(IDC_LIST1)); if ((m_nListCount = pList->GetCount()) > 50) { pList->ResetContent(); // clear listbox when full } RCount.Format("%d ", m_nCount); Rv.Format("%d, %10.3f, %10

      M Offline
      M Offline
      Masaaki Onishi
      wrote on last edited by
      #2

      Hello, the codegurus around the world.;)

      CMyListBox *Ref=(CMyListBox *)AfxGetApp()->m_pMainWnd;
      ASSERT(Ref); //You will get the assertion failure.
      Ref->UpdateListBox();

      As long as you use the dailog based application, the above lines is OK because m_pMainWnd is same as m_pModeless. However, if you use SDI,m_pMainWnd is the application object of your SDI. So, I think that this simple works.

      if (m_pModeless) {
      m_pModeless->SetFocus(); //might need to execute the process?
      m_pModeless->UpdateListBox();
      }

      Have a nice day!

      -Masaaki Onishi-

      L 1 Reply Last reply
      0
      • M Masaaki Onishi

        Hello, the codegurus around the world.;)

        CMyListBox *Ref=(CMyListBox *)AfxGetApp()->m_pMainWnd;
        ASSERT(Ref); //You will get the assertion failure.
        Ref->UpdateListBox();

        As long as you use the dailog based application, the above lines is OK because m_pMainWnd is same as m_pModeless. However, if you use SDI,m_pMainWnd is the application object of your SDI. So, I think that this simple works.

        if (m_pModeless) {
        m_pModeless->SetFocus(); //might need to execute the process?
        m_pModeless->UpdateListBox();
        }

        Have a nice day!

        -Masaaki Onishi-

        L Offline
        L Offline
        louis 0
        wrote on last edited by
        #3

        Thank you. It works. :-O

        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