Skip to content

Instantly share code, notes, and snippets.

@hirosof
Created February 10, 2013 05:01
Show Gist options
  • Select an option

  • Save hirosof/4748439 to your computer and use it in GitHub Desktop.

Select an option

Save hirosof/4748439 to your computer and use it in GitHub Desktop.
int CALLBACK WndProc_CreateColorBoxDlg(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp){
static HDC HDC_parent;
static MyCreateThreadData Data;
static HANDLE hThread;
switch(msg){
case WM_INITDIALOG:
{
RECT rt;
POINT pt;
GetWindowRect(hwnd , &rt);
pt.x = rt.right - rt.left + 1;
pt.y = rt.bottom - rt.top + 1;
SetWindowPos(hwnd , NULL , (GetSystemMetrics(SM_CXSCREEN) - pt.x)/2 ,
(GetSystemMetrics(SM_CYSCREEN) - pt.y)/2 , NULL , NULL , SWP_NOSIZE);
Data.hDC_Base = (HDC)lp;
Data.hProgress = GetDlgItem(hwnd , IDC_MAQ_PROGR);
Data.hProgress_TEXT = GetDlgItem(hwnd , IDC_PROGRESS_TEXT);
Data.hProgress_PERSENT = GetDlgItem(hwnd , IDC_PROGRESS_PERSENT);
hThread = CreateThread(NULL , NULL , ThreadProc_CCB , &Data , NULL , NULL);
SetTimer(hwnd , 100 , 1 , NULL);
}
break;
case WM_TIMER:
if(wp == 100){
if(WaitForSingleObject(hThread , 0) == WAIT_OBJECT_0){
KillTimer(hwnd , 100);
CloseHandle(hThread);
EndDialog(hwnd , IDOK);
}
}
break;
default:
return FALSE;
}
return TRUE;
}
DWORD CALLBACK ThreadProc_CCB(LPVOID lpVData){
MyCreateThreadData *lpData = (MyCreateThreadData*)lpVData;
HDC hdc_main = lpData->hDC_Base;
double dHLS[3] , dRGB[3];
int color_rgb[3];
double plus_h = 360.0 / (ColorBoxSizeX - 1) , plus_s = 1.0 / (ColorBoxSizeY - 1);
TCHAR txtProgress[128];
int progress;
HSConvColorData convdata;
convdata.ModeFlag = 1;
convdata.Color.Pointer.lpInput = dHLS;
convdata.Color.Pointer.lpOutput = dRGB;
SetHSPB_Range(lpData->hProgress , 0 , ColorBoxLightNums);
for (int i = 0; i <= ColorBoxLightNums; i++)
{
dHLS[1] = (double)i / (double)ColorBoxLightNums;
hdc_colorbox[i] = CreateCompatibleDC(hdc_main);
SelectObject(hdc_colorbox[i] , CreateCompatibleBitmap(hdc_main , ColorBoxSizeX , ColorBoxSizeY));
for (int y = 0; y < ColorBoxSizeY; y++)
{
dHLS[2] = 1.0 - y * plus_s ;
for (int x = 0; x < ColorBoxSizeX; x++)
{
dHLS[0] = x * plus_h;
HSColor2_HLStoRGB(&convdata);
for (int j = 0; j < 3; j++) color_rgb[j] = (int)dRGB[j];
SetPixel(hdc_colorbox[i] , x , y , RGB(color_rgb[0],color_rgb[1],color_rgb[2]));
}
}
//進行状況表示
HSPB_SetPos(lpData->hProgress , i);
wsprintf(txtProgress , TEXT("%d 枚中 %d 枚 作成完了") , ColorBoxLightNums + 1 , i + 1);
for (int k = 0; k < i%11; k++) wsprintf(txtProgress , TEXT("%s・") , txtProgress);
SetWindowText(lpData->hProgress_TEXT , txtProgress);
progress = (int)((double)(i + 1) / (double)(ColorBoxLightNums + 1) * 100.0);
wsprintf(txtProgress , TEXT("%d%%") , progress);
SetWindowText(lpData->hProgress_PERSENT , txtProgress);
}
Sleep(1000);
ExitThread(0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment