注意可能会查不到CHOOSECOLOR结构体,需手动添加#include “Commdlg.h”。
void CALLBACK TextColorSet()
{
CHOOSECOLOR cc; // common dialog box structure
static COLORREF acrCustClr[16]; // array of custom colors
HWND hwnd; // owner window
static DWORD rgbCurrent; // initial color selection
// Initialize CHOOSECOLOR
ZeroMemory(&cc, sizeof(cc));
cc.lStructSize = sizeof(cc);
cc.hwndOwner = temHwnd;
cc.lpCustColors = (LPDWORD)acrCustClr;
cc.rgbResult = rgbCurrent;
cc.Flags = CC_FULLOPEN | CC_RGBINIT;
if (ChooseColor(&cc) == TRUE) {
rNum = (cc.rgbResult & 0x0000ff);
gNum = (cc.rgbResult & 0x00FF00) >> 8;
bNum = (cc.rgbResult & 0xff0000) >> 16; //按位运算将其返回值给对应参数
}
}