3D Button API是由MultiMedia Soft开发的最新的3D按钮软件开发包(SDK),源于ActiveX 控件3D Active Button Magic的经验,在您现有的应用程序和新的开发工具中,它代替了过时的Windows平面直角按钮。对于喜欢使用DLL组件而不喜欢ActiveX控件的开发者来说,它也是3D按钮的替代品。此产品包含在产品集合 3D Button Suite 中。
switch (iMsg)
{
case WM_CREATE:
//here is our combobox we do not need the HMENU parameter in this example
//since im not checking for any notifications here
combo = CreateWindow("combobox",NULL,WS_CHILD|WS_VISIBLE|CBS_DROPDOWNLIST,
15,15,130,200,hWnd,(HMENU)NULL,hInst,NULL);
SendMessage(combo,CB_ADDSTRING,0,(LPARAM)(LPCTSTR)"item1");
SendMessage(combo,CB_ADDSTRING,0,(LPARAM)(LPCTSTR)"item2");
//here is our edit control
edit = CreateWindow("edit","edit control",WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL,
15,40,130,25,hWnd,(HMENU)NULL,hInst,NULL);
//here is the listbox
list = CreateWindow("listbox","",WS_CHILD|WS_VISIBLE|LBS_STANDARD,15,70,100,150,
hWnd,(HMENU)NULL,hInst,NULL);
SendMessage(list,LB_ADDSTRING,0,(LPARAM)(LPCTSTR)"item1");
SendMessage(list,LB_ADDSTRING,0,(LPARAM)(LPCTSTR)"item2");
//here is the button
button = CreateWindow("button","Checkbox",WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,15,230,100,20,hWnd,
(HMENU)NULL,hInst,NULL);
//static:
stat = CreateWindow("static","Hi, i'm a static\nColor me!",WS_CHILD|WS_VISIBLE|SS_CENTER,
150,105,150,50,hWnd,(HMENU)NULL,hInst,NULL);
//here is the buttons to change to colors
changetxtcolor = CreateWindow("button","Change Txt Color",WS_VISIBLE|WS_CHILD,
150,15,150,25,hWnd,(HMENU)CHANGETEXT,hInst,NULL);
changebkcolor = CreateWindow("button","Change BK Color",WS_VISIBLE|WS_CHILD|BS_OWNDERDRAW,
150,45,150,25,hWnd,(HMENU)CHANGEBKG,hInst,NULL);
//we need to set up the brush
logbrush.lbHatch = 0;//模板
logbrush.lbStyle = BS_SOLID;//物理刷子的风格
logbrush.lbColor = RGB(255,255,255); //initially set it to black颜色
hbrush = CreateBrushIndirect(&logbrush);// logbrush被Windows的CreateBrushIndirect和ExtCreatePen函数使用。
//and finally we set up the choosecolor struct for that common dialog
SetupChooseColor(&choosecolor,customcolors,hWnd,currentcolor);
//NEW CODE
changefont = CreateWindow("button","Change Font",WS_VISIBLE|WS_CHILD,150,75,150,25,
hWnd,(HMENU)CHANGEFONT,hInst,NULL);
// EndPaint(hWnd,&ps);
ReleaseDC(hWnd, hdc);
break;
//since all of the controls will have the same color attributes i can
//switch them all at once like so, use seperate ones if you need but return
//the brush for each of them
case WM_CTLCOLORSTATIC://WM_CTLCOLORSTATIC是当静态控件重画时,控件给父窗口发送的消息,在处理该消息时应该返回一个画刷,系统用这个画刷重绘控件的背景颜色。
case WM_CTLCOLOREDIT://WM_CTLCOLOREDIT 控制EDIT控件外观
case WM_CTLCOLORLISTBOX://LISTBOX
case WM_CTLCOLORBTN:// 当一个按钮控件将要被绘制时
// 发送此消息给它的父窗口 通过响应这条消息,所有者窗口可以通过使用给定的相关显示设备的句柄来设置按纽的文本和背景颜色
SetTextColor((HDC)wParam,textcolor);//前景色
SetBkMode((HDC)wParam,OPAQUE); //*look on the bottom for more info //非透明
SetBkColor((HDC)wParam,backcolor); //一个背景,
logbrush.lbColor = backcolor;
//now because ive changed the logbrush have to update the brush
//if your keeping your control at a constant color just set the text and
//return the brush, no need for this in that case
hbrush = CreateBrushIndirect(&logbrush);
return (long)hbrush;
// return OnCtrlColor(wParam, lParam);
break;
case WM_CLOSE:
DeleteObject(hbrush);
DeleteObject(currentfont);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case CHANGETEXT:
if(ChooseColor(&choosecolor))//调用窗口
{
currentcolor = choosecolor.rgbResult;//set currentcolor cause
//we need that variable to have value for the RGB_INIT
textcolor = currentcolor;
SendMessage(hWnd,WM_PAINT,0,0);
}
break;
case CHANGEBKG:
if(ChooseColor(&choosecolor))
{
currentcolor = choosecolor.rgbResult;//set currentcolor cause
//we need that variable to have value for the RGB_INIT
backcolor = currentcolor;
SendMessage(hWnd,WM_PAINT,0,0);
}
break;
//NEW CODE
case CHANGEFONT:
if(ChooseFont(&choosefont))//call the dialog for fonts
{
currentfont = CreateFontIndirect(&logfont);
UpdateFonts(); //update windows
SendMessage(hWnd,WM_PAINT,0,0);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
const char *ClassName = "PCPP_ColorControls";
WNDCLASSEX wclass; //here we set up a variable for our window class 定义一个窗口结构的对象
MSG msg; //this will hold the window messages later on
//Next we set up the properties of the window class
wclass.cbSize = sizeof(wclass); //the size 设置窗口结构的大小
wclass.style = CS_HREDRAW | CS_VREDRAW; //style
wclass.lpfnWndProc = WndProc; //this tells windows the function to send messages to 设置窗口消息处理函数WndProc
wclass.cbClsExtra = 0;
wclass.cbWndExtra = 0;
wclass.hInstance = hInstance; //the instance of your program
wclass.hIcon = LoadIcon(NULL,IDI_APPLICATION); //which icon to use
wclass.hCursor = LoadCursor(NULL,IDC_ARROW); //the cursor to use
wclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); //background color
wclass.lpszMenuName = NULL; //set the menu
wclass.lpszClassName = ClassName; //set classname 设置窗口类型名称。
wclass.hIconSm = LoadIcon(NULL,IDI_APPLICATION); //set small icon 设置窗口小图标。
RegisterClassEx(&wclass); //this registers your window with windows 调用函数RegisterClassEx注册这个窗口类型
while(GetMessage(&msg,NULL,0,0)) //getmessage loops until a message is on the queue
{ //then it returns focus,peekmessage does the same except returns focus no matter what
TranslateMessage(&msg); //translate the message into its char equivelent 把虚拟键消息转换为字符消息
DispatchMessage(&msg); //dispatch to the window 把这条消息发送到窗口里的消息处理函数WindowProc
}