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

📄 call.cpp

📁 一个多功能计算器calc
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include<windows.h>
#include<commctrl.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<malloc.h>
#include"resource.h"
#include"comput.c"
LRESULT CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK ArrayDialog1(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK ArrayDialog2(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK ArrayDialog3(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK ArrayCarryDialog2(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK ArrayCarryDialog3(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK RotatePixelDialog(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK DivLineDialog(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK DropLineDialog(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK PandCDialog(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK IsPrimaryDialog(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK YueBeiDialog(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK FenShuDialog(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK KaiFangDialog(HWND,UINT,WPARAM,LPARAM);
struct gengshi *kaifang(UINT);
struct fenshu *carryout(struct fenshu*,struct fenshu*);
BOOL isprimary(UINT);
void InitTree(void);
struct fenshu
{
	UINT fenzi;
	UINT fenmu;
};
struct gengshi
{
 UINT xishu;
 UINT beikaifangshu;
};
int getanswer(int array[4][4]);
HWND hDlg=(HWND)NULL;
HWND treewnd,htreewndctrl;
HTREEITEM htreewnd[20];
HINSTANCE hInst;
char name[]="cal";
NOTIFYICONDATA trayicon;
int WINAPI WinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,
				   LPSTR lpszArgs,int nWinMode)
{
	
	HWND hwnd;
	MSG msg;
	WNDCLASS wcl;

	wcl.hInstance=hThisInst;
	wcl.lpszClassName=name;
	wcl.lpfnWndProc=WindowFunc;
	wcl.style=0;

	wcl.hIcon=LoadIcon(hThisInst,MAKEINTRESOURCE(CALICON));
	wcl.hCursor=LoadCursor(NULL,IDC_ARROW);
	wcl.lpszMenuName=NULL;

	wcl.cbClsExtra=0;
	wcl.cbWndExtra=0;
	wcl.hbrBackground=(HBRUSH)GetStockObject(LTGRAY_BRUSH);

	if(!RegisterClass(&wcl))
		return 0;

	hwnd=CreateWindow(name,"实用计算器v2.2(Final) written by John Bill",WS_SYSMENU|WS_MINIMIZEBOX,
		CW_USEDEFAULT,CW_USEDEFAULT,532,190,
		HWND_DESKTOP,NULL,hThisInst,NULL);

	InitCommonControls();

	hInst=hThisInst;

	htreewndctrl=CreateWindow(WC_TREEVIEW,"",
	 WS_BORDER|WS_VISIBLE|WS_TABSTOP|WS_CHILD|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
	 0,0,150,164,
	 hwnd,NULL,hInst,NULL);
	InitTree();	
	hDlg=CreateDialog(hInst,MAKEINTRESOURCE(COVER),hwnd,NULL);

	trayicon.cbSize=sizeof(NOTIFYICONDATA);
	trayicon.hWnd=hwnd;
	trayicon.uID=CALLCAL;
	trayicon.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
	trayicon.uCallbackMessage=WM_USER+100;
	trayicon.hIcon=wcl.hIcon;
	strcpy(trayicon.szTip,"实用计算器,想用请双击");
	ShowWindow(hwnd,nWinMode);
	UpdateWindow(hwnd);
	
	while(GetMessage(&msg,NULL,0,0))
	{
		if(!IsDialogMessage(hDlg,&msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return msg.wParam;
}

LRESULT CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
	NMHDR *nm;
	switch(message)
	{
		case WM_USER+100:
			if(lParam==WM_LBUTTONDBLCLK)
			{
				ShowWindow(hwnd,SW_SHOWNORMAL);
				UpdateWindow(hwnd);
				Shell_NotifyIcon(NIM_DELETE,&trayicon);
			}
			break;
		case WM_SIZE:
			if(wParam==SIZE_MINIMIZED)
			{
				ShowWindow(hwnd,SW_HIDE);
				UpdateWindow(hwnd);
				Shell_NotifyIcon(NIM_ADD,&trayicon);
			}
			break;
		case WM_NOTIFY:
			nm=(LPNMHDR)lParam;
			if(nm->code==TVN_SELCHANGED)
			{
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[14])
				{
					if(!GetDlgItem(hDlg,IDC_COVER))
					{
						DestroyWindow(hDlg);
						hDlg=CreateDialog(hInst,MAKEINTRESOURCE(COVER),hwnd,NULL);
					}
					break;
				}
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[9])
				{
					if(!GetDlgItem(hDlg,IDC_COVER))
					{
						DestroyWindow(hDlg);
						hDlg=CreateDialog(hInst,MAKEINTRESOURCE(COVER),hwnd,NULL);
					}
					break;
				}
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[10])
				{
					if(!GetDlgItem(hDlg,IDC_COVER))
					{
						DestroyWindow(hDlg);
						hDlg=CreateDialog(hInst,MAKEINTRESOURCE(COVER),hwnd,NULL);
					}
					break;
				}
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[15])
				{
					if(!GetDlgItem(hDlg,IDC_COVER))
					{
						DestroyWindow(hDlg);
						hDlg=CreateDialog(hInst,MAKEINTRESOURCE(COVER),hwnd,NULL);
					}
					break;
				}
				if(hDlg) DestroyWindow(hDlg);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[19])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(KAIFANG),hwnd,(DLGPROC)KaiFangDialog);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[16])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(ISPRIMARY),hwnd,(DLGPROC)IsPrimaryDialog);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[17])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(YUEBEI),hwnd,(DLGPROC)YueBeiDialog);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[18])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(FENSHU),hwnd,(DLGPROC)FenShuDialog);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[11])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(ROTATEPIXEL),hwnd,(DLGPROC)RotatePixelDialog);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[12])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(LINE),hwnd,(DLGPROC)DivLineDialog);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[13])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(X2),hwnd,(DLGPROC)DropLineDialog);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[5])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(ARRAYCARRY),hwnd,NULL);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[7])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(ARRAYCARRY3),hwnd,(DLGPROC)ArrayCarryDialog3);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[6])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(ARRAYCARRY2),hwnd,(DLGPROC)ArrayCarryDialog2);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[8])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(ARRAY),hwnd,NULL);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[3])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(ARRAY1),hwnd,(DLGPROC)ArrayDialog1);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[2])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(ARRAY2),hwnd,(DLGPROC)ArrayDialog2);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[1])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(ARRAY3),hwnd,(DLGPROC)ArrayDialog3);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[4])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(PANDC),hwnd,(DLGPROC)PandCDialog);
				if(((LPNM_TREEVIEW)nm)->itemNew.hItem==htreewnd[0])
					hDlg=CreateDialog(hInst,MAKEINTRESOURCE(ABOUTDIALOG),hwnd,NULL);
			}
			break;
		case WM_DESTROY:
			if(hDlg) DestroyWindow(hDlg);
			UnregisterHotKey(hwnd,CALLCAL);
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hwnd,message,wParam,lParam);
	}
	return 0;
}

	
BOOL CALLBACK ArrayDialog1(HWND hdwnd,UINT message,WPARAM wParam,
						  LPARAM lParam)
{
	static float array[4][4];
	int i,j;
	char p[10];
	switch(message)
	{
		case WM_INITDIALOG:
				for(i=0;i<16;i++)
					SetDlgItemText(hdwnd,1000+i,"");
				SetDlgItemText(hdwnd,RESULT,"");
			return 1;
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case IDOK:
					for(j=0;j<4;j++)
						for(i=0;i<4;i++)
						{
							GetDlgItemText(hdwnd,1000+j*4+i,p,10);
							sscanf(p,"%g",&array[i][j]);
						}
					sprintf(p,"%g",getanswer(array));
					SetDlgItemText(hdwnd,RESULT,p);
					return 1;
				case IDCANCEL:
					for(j=0;j<4;j++)
						for(i=0;i<4;i++)
							SetDlgItemText(hdwnd,1000+j*4+i,"0");
					SetDlgItemInt(hdwnd,RESULT,0,0);
					return 1;
			}
			return 1;
	}
	return 0;
}

BOOL CALLBACK ArrayDialog2(HWND hdwnd,UINT message,WPARAM wParam,
						  LPARAM lParam)
{
	static float array[3][3];
	int i,j;
	char p[10];
	switch(message)
	{
		case WM_INITDIALOG:
				for(i=0;i<9;i++)
					SetDlgItemText(hdwnd,1000+i,"");
				SetDlgItemText(hdwnd,RESULT,"");
			return 1;
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case IDOK:
					for(j=0;j<3;j++)
						for(i=0;i<3;i++)
						{
							GetDlgItemText(hdwnd,1000+j*3+i,p,10);
							sscanf(p,"%g",&array[i][j]);
						}
					sprintf(p,"%g",getanswer(array));
					SetDlgItemText(hdwnd,RESULT,p);
					return 1;
				case IDCANCEL:
					for(j=0;j<3;j++)
						for(i=0;i<3;i++)
							SetDlgItemText(hdwnd,1000+j*3+i,"");
					SetDlgItemInt(hdwnd,RESULT,0,0);
					return 1;
			}
			return 1;
	}
	return 0;
}

BOOL CALLBACK ArrayDialog3(HWND hdwnd,UINT message,WPARAM wParam,
						  LPARAM lParam)
{
	static float array[2][2];
	int i,j;
	char p[10];
	switch(message)
	{
		case WM_INITDIALOG:
				for(i=0;i<4;i++)
					SetDlgItemText(hdwnd,1000+i,"");
				SetDlgItemText(hdwnd,RESULT,"");
			return 1;
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case IDOK:
					for(j=0;j<2;j++)
						for(i=0;i<2;i++)
						{
							GetDlgItemText(hdwnd,1000+j*2+i,p,10);
							sscanf(p,"%g",&array[i][j]);
						}
					sprintf(p,"%g",getanswer(array));
					SetDlgItemText(hdwnd,RESULT,p);
					return 1;
				case IDCANCEL:
					for(j=0;j<2;j++)
						for(i=0;i<2;i++)
							SetDlgItemText(hdwnd,1000+j*2+i,"");
					SetDlgItemInt(hdwnd,RESULT,0,0);
					return 1;
			}
			return 1;
	}
	return 0;
}

BOOL CALLBACK ArrayCarryDialog2(HWND hdwnd,UINT message,WPARAM wParam,
						  LPARAM lParam)
{
	static float array[2][2];
	int i,j;
	char p[10];
	float d,dx,dy,cx,cy,tx,ty;
	switch(message)
	{
		case WM_INITDIALOG:
				for(i=0;i<6;i++)
					SetDlgItemText(hdwnd,1000+i,"");
				SetDlgItemText(hdwnd,X_RESULT,"");
				SetDlgItemText(hdwnd,Y_RESULT,"");
			return 1;
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case IDCANCEL:
					for(i=0;i<6;i++)
						SetDlgItemText(hdwnd,1000+i,"");
					SetDlgItemText(hdwnd,X_RESULT,"");
					SetDlgItemText(hdwnd,Y_RESULT,"");
					return 1;
				case IDOK:
					for(j=0;j<2;j++)
						for(i=0;i<2;i++)
						{
							GetDlgItemText(hdwnd,1000+j*2+i,p,10);
							sscanf(p,"%g",&array[i][j]);
						}
					GetDlgItemText(hdwnd,IDC_EDIT6,p,10);
					sscanf(p,"%g",&cx);
					GetDlgItemText(hdwnd,IDC_EDIT5,p,10);
					sscanf(p,"%g",&cy);
					d=getanswer(array);
					tx=array[0][0];
					ty=array[0][1];
					array[0][0]=cx;
					array[0][1]=cy;
					dx=getanswer(array);
					array[0][0]=tx;
					array[0][1]=ty;
					array[1][0]=cx;
					array[1][1]=cy;
					dy=getanswer(array);
					if(d)
					{
						sprintf(p,"%g",dx/d);
						SetDlgItemText(hdwnd,X_RESULT,p);
						sprintf(p,"%g",dy/d);
						SetDlgItemText(hdwnd,Y_RESULT,p);
					}
					else
					{
						if(dx || dy)
							MessageBox(hdwnd,"此方程组无解","结果",MB_OK);
						else
						{
							for(j=0;j<2;j++)
								for(i=0;i<2;i++)
									if(array[i][j])
									{
										MessageBox(hdwnd,"此方程组有无穷多个解","结果",MB_OK);
										return 1;
									}
							if(cx || cy)
								MessageBox(hdwnd,"此方程组无解","结果",MB_OK);
							else
								MessageBox(hdwnd,"此方程组有无穷多个解","结果",MB_OK);
						}
					}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -