一个简单的win32应用程序

写一个简单的win32应用程序,要求有2个文本框,一个按钮,点击按钮后,计算2个文本框内容之和,直接用TextOut输出。win32的HelloWorld我会写,应加入什... 写一个简单的win32应用程序,要求有2个文本框,一个按钮,点击按钮后,计算2个文本框内容之和,直接用TextOut输出。win32的Hello World我会写,应加入什么代码呢?不要用MFC,那个暂时搞不懂。。 展开
 我来答
匿名用户
2013-09-08
展开全部
#include<windows.h>
#include<stdio.h>
#define IDC_EDIT1 1
#define IDC_EDIT2 2
#define IDC_STATIC 3
#define IDC_BTN 4
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
HINSTANCE hinst;
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
TCHAR* classname="test";
hinst=hInstance;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)::GetStockObject(DKGRAY_BRUSH);
wndclass.hCursor=::LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=::LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WindowProc;
wndclass.lpszClassName=classname;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
::RegisterClass(&wndclass);

HWND hwnd=::CreateWindow(classname,TEXT("ADD"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
250,120,NULL,NULL,hInstance,0);

::ShowWindow(hwnd,nCmdShow);
::UpdateWindow(hwnd);

MSG msg;
while(::GetMessage(&msg,NULL,0,0)){
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static double sum;
int c=01011;
static char a[20],b[20],s[40];
switch(uMsg)
{
case WM_CREATE:
{
::CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|ES_LEFT|ES_NUMBER,10,10,60,20,hwnd,(HMENU)IDC_EDIT1,hinst,0);
::CreateWindow("STATIC","+",WS_CHILD|WS_VISIBLE|SS_CENTER,70,10,30,20,hwnd,(HMENU)IDC_STATIC,hinst,0);
::CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|ES_LEFT|ES_NUMBER,100,10,60,20,hwnd,(HMENU)IDC_EDIT2,hinst,0);
::CreateWindow("BUTTON","=",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,170,10,60,20,hwnd,(HMENU)IDC_BTN,hinst,0);
}break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_BTN:
{
::GetDlgItemText(hwnd,IDC_EDIT1,a,20);
::GetDlgItemText(hwnd,IDC_EDIT2,b,20);
sum=atof(a)+atof(b);
sprintf(s,"%s+%s=%lf",a,b,sum);
HDC hdc=::GetDC(hwnd);
::TextOut(hdc,10,40,s,strlen(s));
::ReleaseDC(hwnd,hdc);
}break;
}
}break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc=::BeginPaint(hwnd,&ps);
::TextOut(hdc,10,40,s,strlen(s));
::EndPaint(hwnd,&ps);
}break;
case WM_DESTROY:
::PostQuitMessage(0);
break;
default:
return ::DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
神话梦碎
2017-06-19 · TA获得超过8797个赞
知道大有可为答主
回答量:6699
采纳率:0%
帮助的人:3175万
展开全部
#include<windows.h>
#include<stdio.h>
#define IDC_EDIT1 1
#define IDC_EDIT2 2
#define IDC_STATIC 3
#define IDC_BTN 4
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
HINSTANCE hinst;
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
TCHAR* classname="test";
hinst=hInstance;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)::GetStockObject(DKGRAY_BRUSH);
wndclass.hCursor=::LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=::LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WindowProc;
wndclass.lpszClassName=classname;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
::RegisterClass(&wndclass);

HWND hwnd=::CreateWindow(classname,TEXT("ADD"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
250,120,NULL,NULL,hInstance,0);

::ShowWindow(hwnd,nCmdShow);
::UpdateWindow(hwnd);

MSG msg;
while(::GetMessage(&msg,NULL,0,0)){
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static double sum;
int c=01011;
static char a[20],b[20],s[40];
switch(uMsg)
{
case WM_CREATE:
{
::CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|ES_LEFT|ES_NUMBER,10,10,60,20,hwnd,(HMENU)IDC_EDIT1,hinst,0);
::CreateWindow("STATIC","+",WS_CHILD|WS_VISIBLE|SS_CENTER,70,10,30,20,hwnd,(HMENU)IDC_STATIC,hinst,0);
::CreateWindow("EDIT","",WS_CHILD|WS_VISIBLE|ES_LEFT|ES_NUMBER,100,10,60,20,hwnd,(HMENU)IDC_EDIT2,hinst,0);
::CreateWindow("BUTTON","=",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,170,10,60,20,hwnd,(HMENU)IDC_BTN,hinst,0);
}break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_BTN:
{
::GetDlgItemText(hwnd,IDC_EDIT1,a,20);
::GetDlgItemText(hwnd,IDC_EDIT2,b,20);
sum=atof(a)+atof(b);
sprintf(s,"%s+%s=%lf",a,b,sum);
HDC hdc=::GetDC(hwnd);
::TextOut(hdc,10,40,s,strlen(s));
::ReleaseDC(hwnd,hdc);
}break;
}
}break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc=::BeginPaint(hwnd,&ps);
::TextOut(hdc,10,40,s,strlen(s));
::EndPaint(hwnd,&ps);
}break;
case WM_DESTROY:
::PostQuitMessage(0);
break;
default:
return ::DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式