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