⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conversion.c

📁 minigui单位换算程序 包括长度 面积 体积等公式的转换
💻 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 + -