?? conversion.c
字號:
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include "Richengbiao.h"
//#define IDCANCEL 201
static DLGTEMPLATE DlgInitProcgress=
{
WS_BORDER|WS_CAPTION,
WS_EX_NONE,
0,0,320,215,
"單位換算",
0,0,
11,NULL,
0 //由于沒有控件,所以是0
};
//控件數組,設置各個空間的屬 性
static CTRLDATA CtrlInitProgress[]=
{
{
CTRL_STATIC,
WS_VISIBLE | SS_SIMPLE,
20, 10, 40, 20,
IDC_STATIC,
"類型",
0
},
{
CTRL_COMBOBOX,
WS_VISIBLE | CBS_DROPDOWNLIST | CBS_NOTIFY,
70, 10, 100, 20,
IDL_TYPE,
"",
80
},
{
CTRL_STATIC,
WS_VISIBLE | SS_SIMPLE,
20, 40, 40, 20,
IDC_STATIC,
"單位",
0
},
{
CTRL_COMBOBOX,
WS_VISIBLE | CBS_DROPDOWNLIST | CBS_NOTIFY,
70, 40, 100, 20,
IDL_UNITONE,
"",
80
},
{
CTRL_STATIC,
WS_VISIBLE | SS_SIMPLE,
20, 70, 40, 20,
IDC_STATIC,
"數量",
0
},
{
CTRL_EDIT,
WS_VISIBLE | WS_TABSTOP | WS_BORDER,
70, 70, 150, 20,
IDC_SIZE_UNITONE,
NULL,
0
},
{
CTRL_STATIC,
WS_VISIBLE | SS_SIMPLE,
20, 100, 40, 20,
IDC_STATIC,
"單位",
0
},
{
CTRL_COMBOBOX,
WS_VISIBLE | CBS_DROPDOWNLIST | CBS_NOTIFY,
70, 100, 100, 20,
IDL_UNITTWO,
"",
80
},
{
CTRL_STATIC,
WS_VISIBLE | SS_SIMPLE,
20, 130, 40, 20,
IDC_STATIC,
"數量",
0
},
{
CTRL_STATIC,
WS_VISIBLE | WS_TABSTOP | SS_SIMPLE,
70, 130, 150, 20,
IDC_SIZE_UNITTWO,
"",
0
},
{
CTRL_BUTTON,
WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
170, 150, 60, 25,
IDCANCEL,
"退出",
0
}
};
//換算單位
static const char* typeContent [] =
{
"長度換算",
"面積換算",
"容量換算",
"質量換算",
};
static const char* lengthUnit [] =
{
"米",
"厘米",
"英寸",
};
static const char* areaUnit [] =
{
"公畝",
"公頃",
"英畝",
};
static const char* cubageUnit [] =
{
"升",
"立方米",
"立方英寸",
};
static const char* weightUnit [] =
{
"公斤",
"克",
"磅",
};
static const double Unit[4][3][3] =
{
{
1, 0.01, 0.0254,
100, 1, 2.54,
39.37, 0.39, 1
},
{
1, 100, 40.47,
0.01, 1, 0.4047,
0.0247, 2.4711, 1
},
{
1, 1000, 3.79,
0.001, 1, 0.0038,
0.2642, 264.17, 1
},
{
1, 0.001, 0.4534,
1000, 1, 453.59,
2.2046, 0.0022, 1
}
};
static void unit_calculate_proc (HWND hwnd, int id, int nc, DWORD add_data)
{
int cur_sel_type,cur_sel_unitone,cur_sel_unittwo;
char buff[60];
double len;
if (id == IDC_SIZE_UNITONE && nc == EN_CHANGE) {
cur_sel_type = SendMessage (GetDlgItem(GetParent(hwnd),IDL_TYPE), CB_GETCURSEL, 0, 0);
cur_sel_unitone = SendMessage (GetDlgItem(GetParent(hwnd),IDL_UNITONE), CB_GETCURSEL, 0, 0);
if (cur_sel_unitone == -1) {
cur_sel_unitone = 0;
}
cur_sel_unittwo = SendMessage (GetDlgItem(GetParent(hwnd),IDL_UNITTWO), CB_GETCURSEL, 0, 0);
if (cur_sel_unittwo == -1) {
cur_sel_unittwo = 0;
}
GetWindowText (hwnd, buff, 32);
len = (double) atoi (buff);
len = len / Unit[cur_sel_type][cur_sel_unitone][cur_sel_unittwo];
sprintf (buff, "%.5f", len);
SetDlgItemText (GetParent (hwnd), IDC_SIZE_UNITTWO, buff);
}
}
static void unit_notif_proc (HWND hDlg, int id, int nc, DWORD add_data)
{
int j;
if (nc == CBN_SELCHANGE) {
int cur_sel = SendMessage (hDlg, CB_GETCURSEL, 0, 0);
if (cur_sel == 0) {
SendDlgItemMessage(GetParent(hDlg), IDL_UNITONE, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(GetParent(hDlg), IDL_UNITTWO, CB_RESETCONTENT, 0, 0);
SetWindowText (GetDlgItem (GetParent(hDlg), IDL_UNITONE), lengthUnit [0]);
SetWindowText (GetDlgItem (GetParent(hDlg), IDL_UNITTWO), lengthUnit [0]);
for (j = 0; j < 3; j++) {
SendDlgItemMessage(GetParent(hDlg), IDL_UNITONE, CB_ADDSTRING, 0, (LPARAM)lengthUnit [j]);
SendDlgItemMessage(GetParent(hDlg), IDL_UNITTWO, CB_ADDSTRING, 0, (LPARAM)lengthUnit [j]);
}
}
else if (cur_sel == 1) {
SendDlgItemMessage(GetParent(hDlg), IDL_UNITONE, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(GetParent(hDlg), IDL_UNITTWO, CB_RESETCONTENT, 0, 0);
SetWindowText (GetDlgItem (GetParent(hDlg), IDL_UNITONE), areaUnit [0]);
SetWindowText (GetDlgItem (GetParent(hDlg), IDL_UNITTWO), areaUnit [0]);
for (j = 0; j < 3; j++) {
SendDlgItemMessage(GetParent(hDlg), IDL_UNITONE, CB_ADDSTRING, 0, (LPARAM)areaUnit [j]);
SendDlgItemMessage(GetParent(hDlg), IDL_UNITTWO, CB_ADDSTRING, 0, (LPARAM)areaUnit [j]);
}
}
else if (cur_sel == 2) {
SendDlgItemMessage(GetParent(hDlg), IDL_UNITONE, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(GetParent(hDlg), IDL_UNITTWO, CB_RESETCONTENT, 0, 0);
SetWindowText (GetDlgItem (GetParent(hDlg), IDL_UNITONE), cubageUnit [0]);
SetWindowText (GetDlgItem (GetParent(hDlg), IDL_UNITTWO), cubageUnit [0]);
for (j = 0; j < 3; j++) {
SendDlgItemMessage(GetParent(hDlg), IDL_UNITONE, CB_ADDSTRING, 0, (LPARAM)cubageUnit [j]);
SendDlgItemMessage(GetParent(hDlg), IDL_UNITTWO, CB_ADDSTRING, 0, (LPARAM)cubageUnit [j]);
}
}
else if (cur_sel == 3) {
SendDlgItemMessage(GetParent(hDlg), IDL_UNITONE, CB_RESETCONTENT, 0, 0);
SendDlgItemMessage(GetParent(hDlg), IDL_UNITTWO, CB_RESETCONTENT, 0, 0);
SetWindowText (GetDlgItem (GetParent(hDlg), IDL_UNITONE), weightUnit [0]);
SetWindowText (GetDlgItem (GetParent(hDlg), IDL_UNITTWO), weightUnit [0]);
for (j = 0; j < 3; j++) {
SendDlgItemMessage(GetParent(hDlg), IDL_UNITONE, CB_ADDSTRING, 0, (LPARAM)weightUnit [j]);
SendDlgItemMessage(GetParent(hDlg), IDL_UNITTWO, CB_ADDSTRING, 0, (LPARAM)weightUnit [j]);
}
}
}
}
static int MyUnitDateBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
int i,j;
switch (message) {
case MSG_INITDIALOG:
for (i = 0; i < 4; i++) {
SendDlgItemMessage(hDlg, IDL_TYPE, CB_ADDSTRING, 0, (LPARAM)typeContent [i]);
}
SetNotificationCallback (GetDlgItem (hDlg, IDL_TYPE), unit_notif_proc);
SendDlgItemMessage(hDlg, IDL_TYPE, CB_SETCURSEL, 0, 0);
SetWindowText (GetDlgItem (hDlg, IDL_UNITONE), lengthUnit [0]);
SetWindowText (GetDlgItem (hDlg, IDL_UNITTWO), lengthUnit [0]);
for (j = 0; j < 3; j++) {
SendDlgItemMessage(hDlg, IDL_UNITONE, CB_ADDSTRING, 0, (LPARAM)lengthUnit [j]);
SendDlgItemMessage(hDlg, IDL_UNITTWO, CB_ADDSTRING, 0, (LPARAM)lengthUnit [j]);
}
SetWindowAdditionalData (hDlg, lParam);
SetNotificationCallback (GetDlgItem (hDlg, IDC_SIZE_UNITONE), unit_calculate_proc);
return 1;
case MSG_COMMAND:
switch (wParam) {
case IDCANCEL:
EndDialog(hDlg,wParam);
break;
}
break;
}
return DefaultDialogProc (hDlg, message, wParam, lParam);
}
static void InitDialogBox(HWND hWnd)
{
DlgInitProcgress.controls=CtrlInitProgress;
DialogBoxIndirectParam(&DlgInitProcgress,hWnd,MyUnitDateBoxProc,0L);
}
int Conversion(HWND hWnd)
{
InitDialogBox(hWnd);//句柄
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -