|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2010-10-20 19:31:59
|
显示全部楼层
最新版本(界面美化,全部由GDI绘图完成)源码:
/*============================================================================*/
#define IDC_NULL 0x0000
#define IDC_0 0x1000
#define IDC_1 0x1001
#define IDC_2 0x1002
#define IDC_3 0x1003
#define IDC_4 0x1004
#define IDC_5 0x1005
#define IDC_6 0x1006
#define IDC_7 0x1007
#define IDC_8 0x1008
#define IDC_9 0x1009
#define IDC_A 0x100a
#define IDC_B 0x100b
#define IDC_C 0x100c
#define IDC_D 0x100d
#define IDC_E 0x100e
#define IDC_F 0x100f
#define IDC_ADD 0x1100
#define IDC_SUB 0x1101
#define IDC_MUL 0x1102
#define IDC_DIV 0x1103
#define IDC_DOT 0x1104
#define IDC_EQU 0x1105
#define IDC_LBR 0x1106
#define IDC_BACK 0x1107
#define IDC_RBR 0x1108
#define IDC_CLR 0x1109
#define IDC_XOR 0x110a
#define IDC_SEM 0x110b
#define IDC_COM 0x110c
#define IDC_SIN 0x1200
#define IDC_ASIN 0x1201
#define IDC_COS 0x1202
#define IDC_ACOS 0x1203
#define IDC_TAN 0x1204
#define IDC_ATAN 0x1205
#define IDC_LOG 0x1206
#define IDC_SQRT 0x1207
#define IDC_SUM 0x1208
#define IDC_AVE 0x1209
#define IDC_SUR 0x120a
#define IDC_BIN 0x1300
#define IDC_OCT 0x1301
#define IDC_DEC 0x1302
#define IDC_HEX 0x1303
#define IDC_ANGLE 0x1400
#define IDC_RADIAN 0x1401
#define IDC_MODE_GROUP 0x2000
#define IDC_TRIFUN_GROUP 0x2001
/*============================================================================*/
char *mode_text[4]={
"二进制",
"八进制",
"十进制",
"十六进制",
};
U16 mode_id[4]={
IDC_BIN,
IDC_OCT,
IDC_DEC,
IDC_HEX,
};
char *tri_fun_text[2]={
"角度",
"弧度",
};
U16 tri_fun_id[2]={
IDC_ANGLE,
IDC_RADIAN,
};
char *btn_text[8*5]={
"0", "1", "2", "3", "%", "CE", "sin", "asin",
"4", "5", "6", "7", "/", "<-", "cos", "acos",
"8", "9", "A", "B", "*", "^", "tan", "atan",
"C", "D", "E", "F", "-", ";", "log", "sum",
".", ",", "(", ")", "+", "=", "sqrt", "ave"
};
U16 btn_id[8*5]={
IDC_0, IDC_1, IDC_2, IDC_3, IDC_SUR, IDC_CLR, IDC_SIN, IDC_ASIN,
IDC_4, IDC_5, IDC_6, IDC_7, IDC_DIV, IDC_BACK, IDC_COS, IDC_ACOS,
IDC_8, IDC_9, IDC_A, IDC_B, IDC_MUL, IDC_XOR, IDC_TAN, IDC_ATAN,
IDC_C, IDC_D, IDC_E, IDC_F, IDC_SUB, IDC_SEM, IDC_LOG, IDC_SUM,
IDC_DOT, IDC_COM, IDC_LBR, IDC_RBR, IDC_ADD, IDC_EQU, IDC_SQRT, IDC_AVE,
};
char output[MAXLEN],input[MAXLEN];
static RESULT WinProc(HWND hwnd,U32 msg,WPARAM wParam,LPARAM lParam)
{
int i,x,y;
RECT rc,*m_rc;
char buf[128];
////
switch(msg)
{
case WM_CREATE:
input[0] =0;
output[0] =0;
jiao =TRUE;
jin =10;
m_rc =MemAlloc(sizeof(RECT)*40);
GetClientRect(hwnd,&rc);
x=4;
y=56;
CreateWindow("groupbox","进制",WS_CHILDWINDOW,x,y,rc.dx>>1,48,hwnd,IDC_MODE_GROUP,hInst,NULL);
SetWindowColor(GetWindowItem(hwnd,IDC_MODE_GROUP),RGB(0,0,0),RGB_TRANS,GetWindowBkColor(hwnd));
GetClientRect(GetWindowItem(hwnd,IDC_MODE_GROUP),&rc);
GetMatrixRectangle(m_rc,0,0,rc.dx,rc.dy,2,2,2,1);
for(i=0;i<4;i++)
{
CreateWindow("radiobutton",mode_text,WS_CHILDWINDOW,m_rc.x,m_rc.y,m_rc.dx,m_rc.dy,GetWindowItem(hwnd,IDC_MODE_GROUP),mode_id,hInst,NULL);
if(mode_id==IDC_DEC)
{
HWND wnd;
wnd =GetWindowItem(hwnd,IDC_MODE_GROUP);
wnd =GetWindowItem(wnd,IDC_DEC);
SendMessage(wnd,WM_SETVALUE,1,0);
}
}
////
GetClientRect(hwnd,&rc);
x=(rc.dx>>1)+8;
CreateWindow("groupbox","三角函数",WS_CHILDWINDOW,x,y,(rc.dx>>1)-8*2,32,hwnd,IDC_TRIFUN_GROUP,hInst,NULL);
SetWindowColor(GetWindowItem(hwnd,IDC_TRIFUN_GROUP),RGB(0,0,0),RGB_TRANS,GetWindowBkColor(hwnd));
GetClientRect(GetWindowItem(hwnd,IDC_TRIFUN_GROUP),&rc);
GetMatrixRectangle(m_rc,0,0,rc.dx,rc.dy,2,1,2,1);
for(i=0;i<2;i++)
{
CreateWindow("radiobutton",tri_fun_text,WS_CHILDWINDOW,m_rc.x,m_rc.y,m_rc.dx,m_rc.dy,GetWindowItem(hwnd,IDC_TRIFUN_GROUP),tri_fun_id,hInst,NULL);
if(tri_fun_id==IDC_ANGLE)
{
HWND wnd;
wnd =GetWindowItem(hwnd,IDC_TRIFUN_GROUP);
wnd =GetWindowItem(wnd,IDC_ANGLE);
SendMessage(wnd,WM_SETVALUE,1,0);
}
}
////
x=0;
y+=50;
GetClientRect(hwnd,&rc);
GetMatrixRectangle(m_rc,x,y,rc.dx,rc.dy-y,8,5,4,4);
for(i=0;i<40;i++)
{
CreateWindow("button",btn_text,WS_CHILDWINDOW|WS_OWNERDRAW,m_rc.x,m_rc.y,m_rc.dx,m_rc.dy,hwnd,btn_id,hInst,NULL);
switch(btn_id)
{
case IDC_0:
case IDC_1:
case IDC_2:
case IDC_3:
case IDC_4:
case IDC_5:
case IDC_6:
case IDC_7:
case IDC_8:
case IDC_9:
case IDC_A:
case IDC_B:
case IDC_C:
case IDC_D:
case IDC_E:
case IDC_F:
SetWindowLong(GetWindowItem(hwnd,btn_id),GWL_BKCOLOR,RGB(20,128,200));
break;
////
case IDC_SIN:
case IDC_ASIN:
case IDC_COS:
case IDC_ACOS:
case IDC_TAN:
case IDC_ATAN:
case IDC_LOG:
case IDC_SUM:
case IDC_SQRT:
case IDC_AVE:
SetWindowLong(GetWindowItem(hwnd,btn_id),GWL_BKCOLOR,RGB(240,128,20));
break;
////
case IDC_SUR:
case IDC_DIV:
case IDC_MUL:
case IDC_SUB:
case IDC_ADD:
case IDC_XOR:
case IDC_SEM:
case IDC_DOT:
case IDC_COM:
case IDC_LBR:
case IDC_RBR:
SetWindowLong(GetWindowItem(hwnd,btn_id),GWL_BKCOLOR,RGB(200,20,128));
break;
////
case IDC_EQU:
SetWindowLong(GetWindowItem(hwnd,btn_id),GWL_BKCOLOR,RGB(20,200,20));
break;
////
case IDC_CLR:
SetWindowLong(GetWindowItem(hwnd,btn_id),GWL_BKCOLOR,RGB(200,20,20));
break;
////
case IDC_BACK:
SetWindowLong(GetWindowItem(hwnd,btn_id),GWL_BKCOLOR,RGB(200,200,20));
break;
////
}
UpdateWindow(GetWindowItem(hwnd,btn_id));
}
MemFree(m_rc);
break;
////////
case WM_COMMAND:
{
U16 id,code;
HWND wnd;
code =HIWORD(wParam);
id =LOWORD(wParam);
if(code==BN_CLICKED)
{
switch(id)
{
case IDC_BIN:
jin =2;
output[0] =0;
break;
////
case IDC_OCT:
jin =8;
output[0] =0;
break;
////
case IDC_DEC:
jin =10;
output[0] =0;
break;
////
case IDC_HEX:
jin =16;
output[0] =0;
break;
////
case IDC_ANGLE:
jiao =TRUE;
output[0] =0;
break;
////
case IDC_RADIAN:
jiao =FALSE;
output[0] =0;
break;
////
case IDC_CLR:
input[0] =0;
output[0] =0;
break;
////
case IDC_BACK:
output[0] =0;
str_back(input);
//StrPrintf(output,"%s",input);
break;
////
case IDC_EQU:
OnEql(output,input);
break;
////
default:
if(jin==2)
{
switch(id)
{
case IDC_2:
case IDC_3:
case IDC_4:
case IDC_5:
case IDC_6:
case IDC_7:
case IDC_8:
case IDC_9:
case IDC_A:
case IDC_B:
case IDC_C:
case IDC_D:
case IDC_E:
case IDC_F:
break;
////
default:
wnd =GetWindowItem(hwnd,id);
str_add(input,GetWindowText(wnd));
output[0] =0;
break;
/////
}
}
if(jin==8)
{
switch(id)
{
case IDC_8:
case IDC_9:
case IDC_A:
case IDC_B:
case IDC_C:
case IDC_D:
case IDC_E:
case IDC_F:
break;
////
default:
wnd =GetWindowItem(hwnd,id);
str_add(input,GetWindowText(wnd));
output[0] =0;
break;
/////
}
}
if(jin==10)
{
switch(id)
{
case IDC_A:
case IDC_B:
case IDC_C:
case IDC_D:
case IDC_E:
case IDC_F:
break;
////
default:
wnd =GetWindowItem(hwnd,id);
str_add(input,GetWindowText(wnd));
output[0] =0;
break;
/////
}
}
if(jin==16)
{
wnd =GetWindowItem(hwnd,id);
str_add(input,GetWindowText(wnd));
output[0] =0;
break;
/////
}
}
InvalidateRect(hwnd,0,0);
}
}
break;
/////////
case WM_DRAWITEM:
{
DRAWITEMSTRUCT *item;
int x,y;
item=(void*)lParam;
switch(item->ID)
{
case IDC_0:
case IDC_1:
case IDC_2:
case IDC_3:
case IDC_4:
case IDC_5:
case IDC_6:
case IDC_7:
case IDC_8:
case IDC_9:
case IDC_A:
case IDC_B:
case IDC_C:
case IDC_D:
case IDC_E:
case IDC_F:
case IDC_SUR:
case IDC_CLR:
case IDC_SIN:
case IDC_ASIN:
case IDC_DIV:
case IDC_BACK:
case IDC_COS:
case IDC_ACOS:
case IDC_MUL:
case IDC_XOR:
case IDC_TAN:
case IDC_ATAN:
case IDC_SUB:
case IDC_SEM:
case IDC_LOG:
case IDC_SUM:
case IDC_DOT:
case IDC_COM:
case IDC_LBR:
case IDC_RBR:
case IDC_ADD:
case IDC_EQU:
case IDC_SQRT:
case IDC_AVE:
SetFontSize(item->hDC,16,0);
FillRectangle(item->hDC,0,0,item->rc.dx,item->rc.dy,GetWindowLong(hwnd,GWL_BKCOLOR));
if(GetWindowLong(item->hwnd,GWL_STYLE)&BS_PUSHED)
{
FillRectangle(item->hDC,0+2,0+2,item->rc.dx-2,item->rc.dy-2,~GetWindowLong(item->hwnd,GWL_BKCOLOR));
Rectangle(item->hDC,0+2,0+2,item->rc.dx-2,item->rc.dy-2,~GetWindowLong(item->hwnd,GWL_BDCOLOR));
DrawText(item->hDC,0+2,0+2,item->rc.dx-2,item->rc.dy-2,~GetWindowLong(item->hwnd,GWL_FRCOLOR),RGB_TRANS,CENTER,GetWindowText(item->hwnd));
}
else
{
FillRectangle(item->hDC,0+3,0+3,item->rc.dx-3,item->rc.dy-3,GetWindowLong(item->hwnd,GWL_BDCOLOR));
//FillRectangle(item->hDC,0+0,0+0,item->rc.dx-3,item->rc.dy-3,GetWindowLong(item->hwnd,GWL_BKCOLOR));
VGradientRectangle(item->hDC,0+0,0+0,item->rc.dx-3,item->rc.dy-3,RGB(240,240,240),GetWindowLong(item->hwnd,GWL_BKCOLOR));
DrawText(item->hDC,0,0,item->rc.dx-3,item->rc.dy-3,GetWindowLong(item->hwnd,GWL_FRCOLOR),RGB_TRANS,CENTER,GetWindowText(item->hwnd));
}
break;
///////
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
}
break;
////////
case WM_PAINT:
{
HDC hdc;
hdc=BeginPaint(hwnd);
if(hdc)
{
GetClientRect(hwnd,&rc);
//Label(hdc,6,4,rc.dx-4*2,40,RGB_TRANS,RGB(0,0,0),RGB(20,80,80),RIGHT,0);
SunkRectangle(hdc,6,4,rc.dx-4*2,48,RGB(10,10,40));
VGradientRectangle(hdc,6+2,4+2,rc.dx-4*2-2*2-1,48-2*2,RGB(0,132,96),RGB(128,220,180));
////
SetFontSize(hdc,16,0);
DrawText(hdc,6,4+00,rc.dx-4*2,24,RGB(000,000,000),RGB_TRANS,LEFT,input);
SetFontSize(hdc,24,0);
DrawText(hdc,6,4+20,rc.dx-4*2,24,RGB(200,000,000),RGB_TRANS,CENTER,output);
////
switch(jin)
{
case 2:
SetFontSize(hdc,12,0);
DrawText(hdc,6,4+48-16,32,16,RGB(200,000,000),RGB_TRANS,CENTER,"BIN");
break;
////
case 8:
SetFontSize(hdc,12,0);
DrawText(hdc,6,4+48-16,32,16,RGB(200,000,000),RGB_TRANS,CENTER,"OCT");
break;
////
case 10:
SetFontSize(hdc,12,0);
DrawText(hdc,6,4+48-16,32,16,RGB(200,000,000),RGB_TRANS,CENTER,"DEC");
break;
////
case 16:
SetFontSize(hdc,12,0);
DrawText(hdc,6,4+48-16,32,16,RGB(200,000,000),RGB_TRANS,CENTER,"HEX");
break;
////
}
////
}
EndPaint(hwnd,hdc);
}
break;
////
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
}
/*============================================================================*/
/*============================================================================*/
int WinMain(HANDLE hInstance,void *argv)
{
HWND hwnd;
MSG msg;
WNDCLASS wcls;
////
hInst =hInstance;
__rt_lib_init(0,0);
wcls.lpClassName =(char*)__Name;
wcls.hInstance =hInstance;
wcls.Style =0;
wcls.lpfnProc =WinProc;
wcls.hIcon =0;
wcls.hIconSm =0;
wcls.hCursor =0;
wcls.BkColor =RGB(128,128,144);
hwnd =CreateWindow( &wcls,(char*)__Name,WS_OVERLAPPEDWINDOW,
120,40,380,320,
NULL,NULL,hInst,NULL);
ShowWindow(hwnd,SW_SHOW);
while(GetMessage(&msg,hwnd))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} |
|