win32: 怎么用多线程在屏幕上画65536条线? 如题,在线等。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 void DrawGraph(HWND hDlg){HDC hdc = ::GetDC(hDlg);for (int indexWidth = 0; indexWidth < 256; indexWidth++){ ::InitializeCriticalSection(&g_cs); g_nHeigh = indexWidth * 600.0/256.0; g_nGreen = (g_nGreen + 1); hThrd[indexWidth] = CreateThread(NULL, 0, ThreadFunc, (LPVOID)indexWidth, 0, &threadId);}for (int indexWidth = 0; indexWidth < 256; indexWidth++){ ::WaitForSingleObject(hThrd[indexWidth], INFINITE); ::CloseHandle (hThrd[indexWidth]); }}一些初始化没copy下来DWORD WINAPI ThreadFunc(LPVOID indexWidth){ HDC hdc = ::GetDC(g_hWndCommandBar); //g_nHeigh = indexWidth * 600.0/256.0; ::EnterCriticalSection(&g_cs); for (int indexHeigh = 0; indexHeigh < 256; indexHeigh++) { HBRUSH hbrush = ::CreateSolidBrush(RGB(g_nRed, g_nGreen, g_nBlue)); RECT rect = {g_nWidth, g_nHeigh, g_nWidth + 800.0/256 , g_nHeigh + 600.0 /256 }; ::FillRect(hdc, &rect, hbrush); g_nWidth = indexHeigh * 800.0/256.0; g_nGreen = (g_nGreen + 1) % 255; ::DeleteObject(hbrush); } ::LeaveCriticalSection(&g_cs); return 0;}我在做LCD测试,画65536种颜色,可是不用线程会很慢,用线程又达不到效果。不知错在哪 void DrawGraph(HWND hDlg) { HDC hdc = ::GetDC(hDlg); for (int indexWidth = 0; indexWidth < 256; indexWidth++) { ::InitializeCriticalSection(&g_cs); g_nHeigh = indexWidth * 600.0/256.0; g_nGreen = (g_nGreen + 1); hThrd[indexWidth] = CreateThread(NULL, 0, ThreadFunc, (LPVOID)indexWidth, 0, &threadId); } for (int indexWidth = 0; indexWidth < 256; indexWidth++) { ::WaitForSingleObject(hThrd[indexWidth], INFINITE); ::CloseHandle (hThrd[indexWidth]); } } 一些初始化没copy下来 DWORD WINAPI ThreadFunc(LPVOID indexWidth) { HDC hdc = ::GetDC(g_hWndCommandBar); //g_nHeigh = indexWidth * 600.0/256.0; ::EnterCriticalSection(&g_cs); for (int indexHeigh = 0; indexHeigh < 256; indexHeigh++) { HBRUSH hbrush = ::CreateSolidBrush(RGB(g_nRed, g_nGreen, g_nBlue)); RECT rect = {g_nWidth, g_nHeigh, g_nWidth + 800.0/256 , g_nHeigh + 600.0 /256 }; ::FillRect(hdc, &rect, hbrush); g_nWidth = indexHeigh * 800.0/256.0; g_nGreen = (g_nGreen + 1) % 255; ::DeleteObject(hbrush); } ::LeaveCriticalSection(&g_cs); return 0; } 我在做LCD测试,画65536种颜色,可是不用线程会很慢,用线程又达不到效果。不知错在哪 我有试过只创建一个线程,可是还是很慢void DrawGraph(HWND hDlg) { HDC hdc = ::GetDC(hDlg); hThrd = CreateThread(NULL, 0, ThreadFunc, (LPVOID)1, 0, &threadId); }DWORD WINAPI ThreadFunc(LPVOID indexWidth){ HDC hdc = ::GetDC(g_hWndCommandBar); for (int indexWidth = 0; indexWidth < 256; indexWidth++) { for (int indexHeigh = 0; indexHeigh < 256; indexHeigh++) { HBRUSH hbrush = ::CreateSolidBrush(RGB(g_nRed, g_nGreen, g_nBlue)); RECT rect = {g_nWidth, g_nHeigh, g_nWidth + 800.0/256 , g_nHeigh + 600.0 /256 }; ::FillRect(hdc, &rect, hbrush); g_nWidth = indexHeigh * 800.0/256.0; g_nGreen = (g_nGreen + 1); ::DeleteObject(hbrush); } g_nHeigh = indexWidth * 600.0/256.0; g_nGreen = (g_nGreen + 1); } return 0;} 关于指针数组的初始化: 编程中经常会遇到的一些问题 用udp可以穿越防火墙吗 为什么我拥有Administrator权限,打开系统进程还是失败? 太欺负人! 顶者有分 为什么我的程序一上来就150K以上呢? 帮忙debug一下 ado小问题 寻找vc新手,大家共同切磋,一起进步! 一个VC中使用WNet函数的问题(有关编译器的) FARPROC的定义? vc.net的atl工程怎样卸载掉注册的exe的组件呢
{
HDC hdc = ::GetDC(hDlg);
for (int indexWidth = 0; indexWidth < 256; indexWidth++)
{
::InitializeCriticalSection(&g_cs);
g_nHeigh = indexWidth * 600.0/256.0;
g_nGreen = (g_nGreen + 1);
hThrd[indexWidth] = CreateThread(NULL, 0, ThreadFunc, (LPVOID)indexWidth, 0, &threadId);
}
for (int indexWidth = 0; indexWidth < 256; indexWidth++)
{
::WaitForSingleObject(hThrd[indexWidth], INFINITE);
::CloseHandle (hThrd[indexWidth]);
}
}
一些初始化没copy下来
DWORD WINAPI ThreadFunc(LPVOID indexWidth)
{
HDC hdc = ::GetDC(g_hWndCommandBar);
//g_nHeigh = indexWidth * 600.0/256.0;
::EnterCriticalSection(&g_cs); for (int indexHeigh = 0; indexHeigh < 256; indexHeigh++)
{ HBRUSH hbrush = ::CreateSolidBrush(RGB(g_nRed, g_nGreen, g_nBlue));
RECT rect = {g_nWidth, g_nHeigh, g_nWidth + 800.0/256 , g_nHeigh + 600.0 /256 };
::FillRect(hdc, &rect, hbrush);
g_nWidth = indexHeigh * 800.0/256.0;
g_nGreen = (g_nGreen + 1) % 255;
::DeleteObject(hbrush);
}
::LeaveCriticalSection(&g_cs);
return 0;
}
我在做LCD测试,画65536种颜色,可是不用线程会很慢,用线程又达不到效果。不知错在哪
{
HDC hdc = ::GetDC(hDlg);
for (int indexWidth = 0; indexWidth < 256; indexWidth++)
{
::InitializeCriticalSection(&g_cs);
g_nHeigh = indexWidth * 600.0/256.0;
g_nGreen = (g_nGreen + 1);
hThrd[indexWidth] = CreateThread(NULL, 0, ThreadFunc, (LPVOID)indexWidth, 0, &threadId);
}
for (int indexWidth = 0; indexWidth < 256; indexWidth++)
{
::WaitForSingleObject(hThrd[indexWidth], INFINITE);
::CloseHandle (hThrd[indexWidth]); }
}
一些初始化没copy下来
DWORD WINAPI ThreadFunc(LPVOID indexWidth)
{
HDC hdc = ::GetDC(g_hWndCommandBar);
//g_nHeigh = indexWidth * 600.0/256.0;
::EnterCriticalSection(&g_cs); for (int indexHeigh = 0; indexHeigh < 256; indexHeigh++)
{ HBRUSH hbrush = ::CreateSolidBrush(RGB(g_nRed, g_nGreen, g_nBlue));
RECT rect = {g_nWidth, g_nHeigh, g_nWidth + 800.0/256 , g_nHeigh + 600.0 /256 };
::FillRect(hdc, &rect, hbrush);
g_nWidth = indexHeigh * 800.0/256.0;
g_nGreen = (g_nGreen + 1) % 255;
::DeleteObject(hbrush);
}
::LeaveCriticalSection(&g_cs);
return 0;
}
我在做LCD测试,画65536种颜色,可是不用线程会很慢,用线程又达不到效果。不知错在哪
void DrawGraph(HWND hDlg)
{
HDC hdc = ::GetDC(hDlg);
hThrd = CreateThread(NULL, 0, ThreadFunc, (LPVOID)1, 0, &threadId);
}
DWORD WINAPI ThreadFunc(LPVOID indexWidth)
{
HDC hdc = ::GetDC(g_hWndCommandBar);
for (int indexWidth = 0; indexWidth < 256; indexWidth++)
{
for (int indexHeigh = 0; indexHeigh < 256; indexHeigh++)
{
HBRUSH hbrush = ::CreateSolidBrush(RGB(g_nRed, g_nGreen, g_nBlue));
RECT rect = {g_nWidth, g_nHeigh, g_nWidth + 800.0/256 , g_nHeigh + 600.0 /256 };
::FillRect(hdc, &rect, hbrush);
g_nWidth = indexHeigh * 800.0/256.0;
g_nGreen = (g_nGreen + 1);
::DeleteObject(hbrush);
}
g_nHeigh = indexWidth * 600.0/256.0;
g_nGreen = (g_nGreen + 1);
}
return 0;
}