windows自带的颜色编辑器居中
void xxx::SetOSDColor(CLabelUI * pLabel) { COLORREF color = RGB(1*255, 1*255, 1*255); CColorDialog cdlg(color, CC_ENABLEHOOK|CC_FULLOPEN); // 设置默认颜色 CRect* pRect = new CRect(0,0,800,500); // cdlg.m_cc.Flags |= CC_ENABLEHOOK|CC_FULLOPEN | CC_RGBINIT; cdlg.m_cc.lpfnHook = CdlgHook; cdlg.m_cc.lCustData = (LONG_PTR)pRect; if(cdlg.DoModal() == IDOK) { color = cdlg.GetColor(); int dColorRed = GetRValue(color); int dColorGreen = GetGValue(color); int dColorBlue = GetBValue(color); COLORREF getColor = dColorBlue + dColorGreen * 256 + dColorRed * 256 * 256; getColor |= 0xFF000000; pLabel->SetBkColor(getColor); } }
UINT_PTR CALLBACK CdlgHook( HWND hdlg,UINT uiMsg,WPARAM /*wParam*/, LPARAM lParam) { if(uiMsg == WM_INITDIALOG) { CHOOSECOLOR *pcc = (CHOOSECOLOR*)lParam; CRect *rc = (CRect*)pcc->lCustData; if(rc) { SetWindowPos(hdlg,HWND_TOP,rc->right,rc->bottom, 0,0,SWP_NOZORDER|SWP_NOSIZE); } SetWindowText(hdlg, _T("请选择一种颜色")); delete rc; } return 0; }
通过重写回调函数,使用SetWindowsPos设置弹出的对话框所显示的位置!!