如题,在线等。。

解决方案 »

  1.   

    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种颜色,可是不用线程会很慢,用线程又达不到效果。不知错在哪
      

  2.   

    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种颜色,可是不用线程会很慢,用线程又达不到效果。不知错在哪
      

  3.   

    我有试过只创建一个线程,可是还是很慢
    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;
    }