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. Subclassing a listcontrol in dialog bar

Subclassing a listcontrol in dialog bar

Scheduled Pinned Locked Moved C / C++ / MFC
testingdebuggingbeta-testingquestionannouncement
2 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.
  • M Offline
    M Offline
    manoharbalu
    wrote on last edited by
    #1

    I have to display a Customized list control in a dialog bar and update it frequently. I am subclassing a custom list control in my application using: m_cLstCtrl.SubclassDlgItem(IDC_LSTCTRL_ALARM,this); CSysWindow is the dialog bar class and have created in CMainFrm using: if (!m_SysWnd.Create(this, IDD_DLGBAR_APPBAR, WS_CHILD | WS_VISIBLE | CBRS_GRIPPER |CBRS_FLYBY|CBRS_TOOLTIPS | CBRS_SIZE_DYNAMIC, IDD_DLGBAR_APPBAR)) { TRACE0("Failed to create DlgBar\n"); return -1; // fail to create } void CSysWindow::RecentAlarms() { //I am testing my List control using the below code: m_cLstCtrl.SetColumnHeader(_T("Student ID, 100; Enroll Date, 150; Score, 80, 2")); for (int i = 0; i < 10; i++) { const int IDX = m_cLstCtrl.InsertItem(0, _T("")); m_cLstCtrl.SetItemText(IDX, 0, ""); m_cLstCtrl.SetItemText(IDX, 1, "testDate"); m_cLstCtrl.SetItemText(IDX, 2, (rand() % 51) + 50); for (int j = 0; j < 2; j++) m_cLstCtrl.SetItemImage(IDX, j, rand() % 5); // subitem images } } When I call this function inside a thread, the application crashes by triggering a breakpoint. void tUpdateAllViews( CMainFrame *pMainFrm ) { while( 1 ) { pMainFrm->UpdateAllViews(); pMainFrm->m_SysWnd.RecentAlarms(); Sleep(500); } } void CMainFrame::UpdateAllViews() { //It also crashes when I call here as below. m_SysWnd.RecentAlarms(); } Whereas when I Call this function inside OnUpdate, its working void CMainFrame::OnUpdate() { // TODO: Add your command handler code here m_SysWnd.RecentAlarms(); } which is the proper way to call this function that is in the dialog bar class "m_SysWnd.RecentAlarms();" where to call this function? Please advice.

    V 1 Reply Last reply
    0
    • M manoharbalu

      I have to display a Customized list control in a dialog bar and update it frequently. I am subclassing a custom list control in my application using: m_cLstCtrl.SubclassDlgItem(IDC_LSTCTRL_ALARM,this); CSysWindow is the dialog bar class and have created in CMainFrm using: if (!m_SysWnd.Create(this, IDD_DLGBAR_APPBAR, WS_CHILD | WS_VISIBLE | CBRS_GRIPPER |CBRS_FLYBY|CBRS_TOOLTIPS | CBRS_SIZE_DYNAMIC, IDD_DLGBAR_APPBAR)) { TRACE0("Failed to create DlgBar\n"); return -1; // fail to create } void CSysWindow::RecentAlarms() { //I am testing my List control using the below code: m_cLstCtrl.SetColumnHeader(_T("Student ID, 100; Enroll Date, 150; Score, 80, 2")); for (int i = 0; i < 10; i++) { const int IDX = m_cLstCtrl.InsertItem(0, _T("")); m_cLstCtrl.SetItemText(IDX, 0, ""); m_cLstCtrl.SetItemText(IDX, 1, "testDate"); m_cLstCtrl.SetItemText(IDX, 2, (rand() % 51) + 50); for (int j = 0; j < 2; j++) m_cLstCtrl.SetItemImage(IDX, j, rand() % 5); // subitem images } } When I call this function inside a thread, the application crashes by triggering a breakpoint. void tUpdateAllViews( CMainFrame *pMainFrm ) { while( 1 ) { pMainFrm->UpdateAllViews(); pMainFrm->m_SysWnd.RecentAlarms(); Sleep(500); } } void CMainFrame::UpdateAllViews() { //It also crashes when I call here as below. m_SysWnd.RecentAlarms(); } Whereas when I Call this function inside OnUpdate, its working void CMainFrame::OnUpdate() { // TODO: Add your command handler code here m_SysWnd.RecentAlarms(); } which is the proper way to call this function that is in the dialog bar class "m_SysWnd.RecentAlarms();" where to call this function? Please advice.

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      manoharbalu wrote:

      When I call this function inside a thread, the application crashes by triggering a breakpoint.

      You must not directly access the main GUI thread controls from within a secondary thread! Instead you should PostMessage a user defined message to the main thread window notifying it that it has to do some operation(s). Within the main thread you handle this message and perform the ordered operation(s). See also this great J.Newcomer essay: [Using Worker Threads](http://www.flounder.com/workerthreads.htm)

      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