Home > Software engineering >  Within the thread, the Listctrl controls to add data, to close the dialog, the program will have a p
Within the thread, the Listctrl controls to add data, to close the dialog, the program will have a p

Time:11-02

The code is as follows:
LpParam CMy_Dlg * p_this_dlg=(CMy_Dlg *);//pass in the pointer is dialog

CListCtrl * p_listctrl=(CListCtrl *) (p_this_dlg - & gt; GetDlgItem (IDC_LISTCTRL1));
P_listctrl - & gt; DeleteAllItems ();

Int i_data_index=0;
for(int i=0; i{
Int i_temp=i_data_index;
P_listctrl - & gt; InsertItem (i_temp, total_value_1 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 1, total_value_2. GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 2, total_value_3 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 3, total_value_4 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 4, total_value_5 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 5, total_value_6 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 6, total_value_7 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 7, total_value_8 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 8, total_value_9 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 9, total_value_10 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 10, total_value_11 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 11, total_value_12 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 12, total_value_13 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 13, total_value_14 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 14, total_value_15 GetAt (I));

I_data_index + +;

Cstrings str_temp1241;
Str_temp1241. The Format (" data has shown that article % d ", i_data_index);
P_this_dlg - & gt; SetDlgItemText (IDC_STATIC_STATUS str_temp1241);

}

return 0;



I write is MFC dialog-based program, the above code is implemented in the thread function, the ListCtrl controls after adding the data, click on the "close" button, the dialog box (child dialogs) can be normally closed, but its parent dialog box (I was opened by the method of DoModal child dialogs) there will be a period of time "no response" (as in the infinite loop), and add to add ListCtrl controls, the more the "no response" the longer the time,
I had a test in the call DoModal place, is indeed what process in the background,
I feel should be in the contents of the empty ListCtrl controls, but I don't know how to avoid this kind of situation...
Want to know the great god to show just a little...
Sorry, I did not have many points, only so much...

CodePudding user response:

First of all, it is inappropriate to manipulate the UI in the thread, suggest PostMessage to the main thread in the thread, by the main program operation UI
Second, you should assess the exit in the for loop processing logo, once want to quit, can immediately interruption from the for loop
Again, if the data quantity is big, with InsertItem and SetItemTex processing speed is quite slow, recommended List of virtual mode,

CodePudding user response:

The
refer to the original poster laodadetou response:
code is as follows:
LpParam CMy_Dlg * p_this_dlg=(CMy_Dlg *);//pass in the pointer is dialog

CListCtrl * p_listctrl=(CListCtrl *) (p_this_dlg - & gt; GetDlgItem (IDC_LISTCTRL1));
P_listctrl - & gt; DeleteAllItems ();

Int i_data_index=0;
for(int i=0; i{
Int i_temp=i_data_index;
P_listctrl - & gt; InsertItem (i_temp, total_value_1 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 1, total_value_2. GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 2, total_value_3 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 3, total_value_4 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 4, total_value_5 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 5, total_value_6 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 6, total_value_7 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 7, total_value_8 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 8, total_value_9 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 9, total_value_10 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 10, total_value_11 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 11, total_value_12 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 12, total_value_13 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 13, total_value_14 GetAt (I));
P_listctrl - & gt; SetItemText (i_temp, 14, total_value_15 GetAt (I));

I_data_index + +;

Cstrings str_temp1241;
Str_temp1241. The Format (" data has shown that article % d ", i_data_index);
P_this_dlg - & gt; SetDlgItemText (IDC_STATIC_STATUS str_temp1241);

}

return 0;



I write is MFC dialog-based program, the above code is implemented in the thread function, the ListCtrl controls after adding the data, click on the "close" button, the dialog box (child dialogs) can be normally closed, but its parent dialog box (I was opened by the method of DoModal child dialogs) there will be a period of time "no response" (as in the infinite loop), and add to add ListCtrl controls, the more the "no response" the longer the time,
I had a test in the call DoModal place, is indeed what process in the background,
I feel should be in the contents of the empty ListCtrl controls, but I don't know how to avoid this kind of situation...
Want to know the great god to show just a little...
Sorry, I did not have many points, only so much...


OnClose tags inside TRUE, insertitem adding a tag, if is TRUE will break
  • Related