vcxproj 文件是vc++的主项目文件
filters 是筛选器文件
项目名.h 是应用程序的主头文件
项目名.cpp是主应用程序的源文件
atlimage.h 是CImage类的头文件,用于文件的打开,显示,保存,最好包含在stdafx.h文件里面
Overridables 重写虚函数
2017-5-18:第一个windows程序:简单的计算器
#include "resource.h"
#include <Windows.h>
//资源总管
INT_PTR CALLBACK theProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
int left = GetDlgItemInt(hwndDlg, IDC_EDIT1, NULL, TRUE);
int right = GetDlgItemInt(hwndDlg, IDC_EDIT2, NULL, TRUE);
SetDlgItemInt(hwndDlg, IDC_EDIT3, left + right, TRUE);
MessageBox(hwndDlg, "你点击了ok", "瓜皮须知", 0);
}
if (LOWORD(wParam) == IDC_EXIT)
{
EndDialog(hwndDlg, IDC_close);
}
if (LOWORD(wParam) == IDC_close)
{
EndDialog(hwndDlg, IDC_close);
}
if (LOWORD(wParam) == IDCANCEL)
{
MessageBox(hwndDlg, "你个瓜皮","linshi", 0);
EndDialog(hwndDlg, IDCANCEL);
}
break;
}
//消息回调函数Umsg是消息的种类,消息是事件回调的返回值,各种消息种类都在此汇总
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmd, int nCmdShow)
{
//messageBox FindWindow
DialogBox(hInstance, (LPCTSTR)kele, NULL, theProc);
return 0;
}
#resource.h里面包含的是所有资源的id,也控制许多常量的id,再是喊不支持输入
四则运算计算器,支持除数为0报错 #include "resource.h" #include <Windows.h> #include <stdio.h>
//资源总管
double GetDlgItemDouble(HWND hwnd, UINT nID)
{
char s[256];
GetDlgItemText(hwnd, nID, s, sizeof(s));
return atof(s);
}
//atof atoi
//itoa ftoa???
//sprintf 数字》》字符串 格式化函数
void SetDlgItemDouble(HWND hwnd, UINT nID, double db)
{
char s[256];
SetDlgItemText(hwnd, nID, s);
}
INT_PTR CALLBACK theProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
int left = GetDlgItemInt(hwndDlg, IDC_EDIT1, NULL, TRUE);
int right = GetDlgItemInt(hwndDlg, IDC_EDIT2, NULL, TRUE);
SetDlgItemInt(hwndDlg, IDC_EDIT3, left + right, TRUE);
left = GetDlgItemInt(hwndDlg, IDC_EDIT4, NULL, TRUE);
right = GetDlgItemInt(hwndDlg, IDC_EDIT5, NULL, TRUE);
SetDlgItemInt(hwndDlg, IDC_EDIT6, left - right, TRUE);
MessageBox(hwndDlg, "你点击了ok", "瓜皮须知", 0);
left = GetDlgItemInt(hwndDlg, IDC_EDIT7, NULL, TRUE);
right = GetDlgItemInt(hwndDlg, IDC_EDIT8, NULL, TRUE);
SetDlgItemInt(hwndDlg, IDC_EDIT9, left * right, TRUE);
left = GetDlgItemInt(hwndDlg, IDC_EDIT10, NULL, TRUE);
right = GetDlgItemInt(hwndDlg, IDC_EDIT11, NULL, TRUE);
if (right == 0)
{
MessageBox(hwndDlg, "兄弟讲道理啊", "你是瓜皮", 0);
break;
}
SetDlgItemInt(hwndDlg, IDC_EDIT12, left/right, TRUE);
}
if (LOWORD(wParam) == IDC_EXIT)
{
EndDialog(hwndDlg, IDC_close);
}
if (LOWORD(wParam) == IDC_close)
{
MessageBox(hwndDlg, "gua", "hello", 0);
EndDialog(hwndDlg, IDC_close);
}
if (LOWORD(wParam) == IDCANCEL)
{
MessageBox(hwndDlg, "你个瓜皮","linshi", 0);
EndDialog(hwndDlg, IDCANCEL);
}
if (LOWORD(wParam) == ID_EXIT)
{
EndDialog(hwndDlg, ID_EXIT);
}
break;
}
//消息回调函数Umsg是消息的种类,消息是事件回调的返回值,各种消息种类都在此汇总
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmd, int nCmdShow)
{
//messageBox FindWindow
DialogBox(hInstance, (LPCTSTR)kele, NULL, theProc);
return 0;
}
//double版计算器
#include "resource.h"
#include <Windows.h>
#include <stdio.h>
//资源总管
double GetDlgItemDouble(HWND hwnd, UINT nID)
{
char s[256];
GetDlgItemText(hwnd, nID, s, sizeof(s));
return atof(s);
}
//atof atoi
//itoa ftoa???
//sprintf 数字》》字符串 格式化函数
void SetDlgItemDouble(HWND hwnd, UINT nID, double db)
{
char s[256];
sprintf(s, "%lf", db);
SetDlgItemText(hwnd, nID, s);
}
INT_PTR CALLBACK theProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
double left = GetDlgItemDouble(hwndDlg, IDC_EDIT1);
double right = GetDlgItemDouble(hwndDlg, IDC_EDIT2);
SetDlgItemDouble(hwndDlg, IDC_EDIT3, left + right);
left = GetDlgItemDouble(hwndDlg, IDC_EDIT4);
right = GetDlgItemDouble(hwndDlg, IDC_EDIT5);
SetDlgItemDouble(hwndDlg, IDC_EDIT6, left - right);
left = GetDlgItemDouble(hwndDlg, IDC_EDIT7);
right = GetDlgItemDouble(hwndDlg, IDC_EDIT8);
SetDlgItemDouble(hwndDlg, IDC_EDIT9, left * right);
left = GetDlgItemDouble(hwndDlg, IDC_EDIT10);
right = GetDlgItemDouble(hwndDlg, IDC_EDIT11);
if (right == 0)
{
MessageBox(hwndDlg, "不要这样,先生", "给瓜皮的一份信", 0);
break;
}
SetDlgItemDouble(hwndDlg, IDC_EDIT12, left / right);
}
if (LOWORD(wParam) == IDC_EXIT)
{
EndDialog(hwndDlg, IDC_close);
}
if (LOWORD(wParam) == IDC_close)
{
MessageBox(hwndDlg, "gua", "hello", 0);
EndDialog(hwndDlg, IDC_close);
}
if (LOWORD(wParam) == IDCANCEL)
{
MessageBox(hwndDlg, "你个瓜皮","linshi", 0);
EndDialog(hwndDlg, IDCANCEL);
}
if (LOWORD(wParam) == ID_EXIT)
{
EndDialog(hwndDlg, ID_EXIT);
}
break;
}
//消息回调函数Umsg是消息的种类,消息是事件回调的返回值,各种消息种类都在此汇总
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmd, int nCmdShow)
{
//messageBox FindWindow
DialogBox(hInstance, (LPCTSTR)kele, NULL, theProc);
return 0;
}