就是接收服務器的資料,放在編輯框中,一開始正常,字數變多了就會閃爍,為什么啊。
if(resultList.size()==size2)
{
std::string w;
FILE* fa = fopen("2.txt", "wb+");
fclose(fa);
FILE* fc = fopen("1.txt", "wb+");
fclose(fc);
size2++;
x=pl.output("1.txt", resultList,errorCode);
for( int s = 0 ; s < resultList.size() ; s++ )
{
x=pl.convert_json(resultList[s].c_str(), w,strbuffer); //json的決議
}
CFile sf;
CString str("");
sf.Open(_T("2.TXT"), CFile::modeRead);
DWORD size3 = sf.GetLength();
char *resultbuf;
resultbuf = new char[size3+1];
memset(resultbuf,0,size3+1);
sf.Read(resultbuf,size3);
int len = size3+1;
int unicodeLen = ::MultiByteToWideChar( CP_UTF8,
0,
resultbuf,
-1,
NULL,
0 );
wchar_t * pUnicode;
pUnicode = new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
::MultiByteToWideChar( CP_UTF8,
0,
resultbuf,
-1,
(LPWSTR)pUnicode,
unicodeLen );
CString rt;
rt = ( wchar_t* )pUnicode;
delete pUnicode;
delete[] resultbuf;
CString outresult;
outresult = rt;
int n = outresult.Remove( '"' );
outresult.Remove( '\r\n' );
myedit->SetWindowText(outresult);
myedit->LineScroll(myedit->GetLineCount());
InvalidateRect(NULL, NULL, true);
}
uj5u.com熱心網友回復:
可以試試僅在舊顯示內容和新顯示內容不一樣的矩形區域內InvalidateRect還可以試試使用雙快取技術
提醒:使用任何技術,全屏白和全屏黑交替顯示,都會閃爍。
uj5u.com熱心網友回復:
不要用 myedit->SetWindowText(outresult);Edit.SetSel(-1,-1);
Edit.ReplaceSel((char*)pBuf);
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:

為什么不能用
uj5u.com熱心網友回復:
編輯框的雙緩沖不太會,可以教教我嗎uj5u.com熱心網友回復:
myedit->SetSel(-1,-1);// 你的是指標uj5u.com熱心網友回復:
恩,發現了,但是好像沒什么用,還是會閃。誰會雙緩沖的可以教我一下嗎?uj5u.com熱心網友回復:
不要InvalidateRect(NULL, NULL, true);
試試
uj5u.com熱心網友回復:
這個問題我也遇到過,你直接SetWindowText肯定會閃,可以用ReplaceSel和SetSel。如果你要用雙緩沖,那你就得重寫CEdit這個類,每次只繪制最后可見區域的一串字串。
至于雙緩沖就是先在臨時的memdc下繪制好,然后一次性繪制到螢屏上···
http://www.cnblogs.com/watsonlong/archive/2011/04/19/2021486.html
uj5u.com熱心網友回復:
你還可以去試試看RichEdit控制元件uj5u.com熱心網友回復:
額,發現問題了,好像是我的計時器一直在計時導致的重繪
GetDlgItem(IDC_Timer1)->GetClientRect(&rect);
HWND hWnd = myedit->GetSafeHwnd();
InvalidateRect(hWnd,&rect, true);
myedit->SetWindowText(wtime2);
這樣可以只重繪計時器嗎
uj5u.com熱心網友回復:
為什么 InvalidateRect(hWnd,&rect, true); ?myedit->SetWindowText(wtime2); 自己會重繪
uj5u.com熱心網友回復:
unsigned int __stdcall TimeThread(PVOID pM)
{
CEdit *myedit=(CEdit*)(pM);
//CrecordDlg *myedit=(CrecordDlg*)(pM);
sec2=0;
min2=0;
h2=0;
hmin2=0;
while(st==0)
{
Sleep(10);
hmin2++;
if(hmin2==100){
hmin2=0;
sec2++;
}
if(sec2==60)
{
sec2=0;
min2++;
}
if(min2==60)
{
min2=0;
h2++;
}
wtime2.Format(_T("%d:%d:%d:%d\n"), h2, min2,sec2,hmin2);
//SendMessage(0,WM_MY_MESSAGE,0,0);
//m_timeout=wtime2;
HWND hWnd = myedit->GetSafeHwnd();
InvalidateRect(hWnd,&rect, true);
myedit->SetWindowText(wtime2);
}
return 0;
}
uj5u.com熱心網友回復:
執行緒中不要界面操作 TimeThread(PVOID pM)初始化時
SetTimer(1,1000,0);
代碼 移到 OnTimer 中
uj5u.com熱心網友回復:
ontimer用過的,但是計時很不準,有的時候還會卡住。所以最后才決定用執行緒的。uj5u.com熱心網友回復:
那執行緒中 發 訊息uj5u.com熱心網友回復:
unsigned int __stdcall TimeThread(PVOID pM)
{
CEdit *myedit=(CEdit*)(pM);
//CrecordDlg *myedit=(CrecordDlg*)(pM);
sec2=0;
min2=0;
h2=0;
hmin2=0;
while(st==0)
{
Sleep(10);
hmin2++;
if(hmin2==100){
hmin2=0;
sec2++;
}
if(sec2==60)
{
sec2=0;
min2++;
}
if(min2==60)
{
min2=0;
h2++;
}
wtime2.Format(_T("%d:%d:%d:%d\n"), h2, min2,sec2,hmin2);
//SendMessage(0,WM_MY_MESSAGE,0,0);
//m_timeout=wtime2;
HWND hWnd = myedit->GetSafeHwnd();
InvalidateRect(hWnd,&rect, true);
//myedit->SetWindowText(wtime2);
SendMessage(
AfxGetApp()->GetMainWnd()->GetSafeHwnd(), // 獲得主視窗在句柄
WM_MY_MESSAGE, // 發送自己的視窗訊息
(WPARAM)&wtime2, // 設定發送的內容
NULL); // 預留引數為空
}
return 0;
}
這樣嗎,但是剛剛試了一下還是會閃,怎么限制重繪范圍啊
uj5u.com熱心網友回復:
不要HWND hWnd = myedit->GetSafeHwnd();
InvalidateRect(hWnd,&rect, true);
這個 還是 執行緒中 對 界面操作。
“”怎么限制重繪范圍“” 秒 變化 最快
只有 時分秒 變化時 才 Sendmessage()
所以 設一個 時分秒 變化的 標記
BOOL hmsChaged;
if(sec2==60)
{
sec2=0;
min2++;
hmsChaged=TRUE;
}
if ( hmsChaged) SendMessage( )
uj5u.com熱心網友回復:
Multiple Threads in the User Interface http://msdn.microsoft.com/zh-cn/library/ms810439.aspxuj5u.com熱心網友回復:
這個是讓計時器一分鐘變一次嗎,這樣計時器就沒有意義了啊,我想的是只重繪計時器這一個編輯框區域內的內容,這樣下面輸出結果的編輯框就不會閃爍了但是加上
InvalidateRect(hWnd,&rect, true);
下面的編輯框還是在重繪,為什么限制不成功呢
uj5u.com熱心網友回復:
只有 時 分 秒 變化時 , 你看 時 分 秒 有 幾個地方 (幾個 if )?InvalidateRect(hWnd,&rect, true);
你的 rect 是 整個 edit ,等于無限制,應該 如 CRect rc(0,0,100,20),
你不能 另外 給個 地方 顯示 time 嗎 (如狀態條)? 為什么 在 Edit 的 中間。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/123950.html
標籤:基礎類
上一篇:關于MFC 多執行緒編程的問題
