炫彩界面库论坛

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 2156|回复: 4

list控件刷新与botton事件的问题

[复制链接]

该用户从未签到

发表于 2014-7-3 11:29:57 | 显示全部楼层 |阅读模式
界面上 有一个按钮,一个list控件,
我想实现当点击按钮时,list控件开始 不断的动态添加数据。

目前是在OnBtnClick事件中,添加了
while(1000)

      XList_AddItem()。
      XEle_RedrawEle()


可目前效果来看。还是假死,整个Click事件过后,才会刷新。

mfc的话,可以消息驱动,这样就不用等while跟事件结束,再updatewindow
因为不是消息驱动,所以 不知道如何解决此类问题。
请各位了解的大哥给个思路。

该用户从未签到

发表于 2014-7-3 11:34:15 | 显示全部楼层
XWnd_Redraw()即可

该用户从未签到

 楼主| 发表于 2014-7-3 11:46:53 | 显示全部楼层
  1. BOOL CXPage1::OnStartSaoMiaoBtnClick(HELE hEle,HELE hEleEvent)
  2. {
  3.         //WCHAR* aa=XStatic_GetText(CXPage1::m_hEdit);
  4.         if (XEdit_IsEmpty(CXPage1::m_hEdit))
  5.         {
  6.                 return false;
  7.         }
  8.         BOOL bRet = FALSE;
  9.         USES_CONVERSION;

  10.         WCHAR szCmdPath[MAX_PATH] = {0};
  11.         GetSystemDirectory(szCmdPath, sizeof(szCmdPath));
  12.         PathAppend(szCmdPath, L"cmd.exe");

  13.         SECURITY_ATTRIBUTES SecurityAttributes;
  14.         SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
  15.         SecurityAttributes.lpSecurityDescriptor = NULL;
  16.         SecurityAttributes.bInheritHandle = TRUE;

  17.         HANDLE hRead = NULL;
  18.         HANDLE hWrite = NULL;
  19.         WCHAR pszCommand[] = L"ping 127.0.0.1 -t";

  20.         WCHAR pszResult[256]=L"";
  21.         DWORD dwCount=_countof(pszResult);
  22.         if(CreatePipe(&hRead, &hWrite, &SecurityAttributes, 0))
  23.         {
  24.                 STARTUPINFO StartupInfo = {0};
  25.                 StartupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
  26.                 StartupInfo.hStdOutput = hWrite;
  27.                 StartupInfo.hStdError = hWrite;
  28.                 StartupInfo.wShowWindow = SW_HIDE;

  29.                 PROCESS_INFORMATION ProcessInformation = {0};

  30.                 WCHAR szCurrentPath[MAX_PATH] = {0};
  31.                 GetCurrentDirectory(sizeof(szCurrentPath), szCurrentPath);

  32.        
  33.                 if(CreateProcess(NULL, pszCommand, NULL, NULL, TRUE, 0, NULL, szCurrentPath, &StartupInfo, &ProcessInformation))
  34.                 {
  35.                         CloseHandle(hWrite);

  36.                         char szBuffer[4096] = {0};
  37.                         DWORD dwRead = 0;
  38.                         string tmp;
  39.                         string strBuffer;
  40.                         if(pszResult)
  41.                         {
  42.                                 pszResult[0] = 0;
  43.                                
  44.                                 while(TRUE)
  45.                                 {
  46.                                         memset(szBuffer, 0, sizeof(szBuffer));
  47.                                         bRet = ReadFile(hRead, szBuffer, sizeof(szBuffer), &dwRead, NULL);
  48.                                         if((FALSE == bRet) || (dwRead = 0))
  49.                                                 break;

  50.                                         int pos=0,found=0,i=0;
  51.                                         strBuffer="";
  52.                                         strBuffer = szBuffer;
  53.                                         while(found!=string::npos)
  54.                                         {
  55.                                                 tmp="";
  56.                                                 found = strBuffer.find("\n",pos);
  57.                                                 tmp=strBuffer.substr(pos,found-pos);

  58.                                                 memset(pszResult, 0, _countof(pszResult));
  59.                                                 wcscat_s(pszResult, dwCount, A2W(tmp.c_str()));
  60.                                                 XList_AddItem(CXPage1::m_hList,pszResult,i);
  61.                                                 pos=found+1;
  62.                                                 i++;
  63.                                                 XEle_RedrawEle(CXPage1::m_hList,true);
  64.                                                
  65.                                         }
  66.                                        
  67.                                        
  68.                                 }
  69.                         }
  70.                 }
  71.                
  72.                
  73.                 CloseHandle(hRead);
  74.         }


  75.         //free(strBuff);
  76.        
  77.         return true;
  78. }
复制代码


该用户从未签到

发表于 2014-7-3 12:35:41 | 显示全部楼层
在按钮事件中 创建线程
  • TA的每日心情
    开心
    2022-1-9 18:18
  • 发表于 2014-7-3 23:31:30 | 显示全部楼层
    1. while(1000)  //这里是一个死循环,会把UI线程阻塞掉

    2.       XList_AddItem()。
    3.       XEle_RedrawEle()
    复制代码
    for(int i=0;i<1000;i++)
    {
    XList_AddItem();
          //XEle_RedrawEle();
    }
    XEle_RedrawEle();  //最好放在末尾调用,因为UI重绘是比较占CPU的,而且你的重绘频率这么高.电影的绘制速度也才每秒24帧.

    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    QQ|Archiver|手机版|小黑屋|炫彩界面库 ( 鄂ICP备2023014763号-1 )

    GMT+8, 2024-5-9 06:38 , Processed in 0.068263 second(s), 18 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表