vc++的MessageBox的问题

输出1元2次方程的根··本来是TextOut(hdc,10,90,str,strlen(str));可以,现在想改成弹出对话框输出,,怎么运行不对··怎么改···#inc... 输出1元2次方程的根··本来是TextOut(hdc,10,90,str,strlen(str));可以,现在想改成弹出对话框输出,,怎么运行不对··
怎么改···
#include<windows.h>
#include<math.h>
#include<stdio.h>
int GetRoot(float a,float b,float c,double *root)
{double delta,deltasqrt;
delta=b*b-4.0*a*c;
if(delta<0.0)return 0;
deltasqrt=sqrt(delta);
if(a!=0){
root[0]=(-b+deltasqrt)/(2.0*a);
root[1]=(-b-deltasqrt)/(2.0*a);
}
else
if(b!=0)root[0]=root[1]=-c/b;
else return 0;
if(root[0]==root[1])return 1;
else return 2;
}
char str[80];
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style =CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc =WndProc;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hInstance =hInstance;
wndclass.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName =NULL;
wndclass.lpszClassName ="HelloWin";
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,"窗口注册失败!","HelloWin",0);
return 0;
}
hwnd=CreateWindow("HelloWin",
"我的窗口",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{ HDC hdc;
PAINTSTRUCT ps;
static HWND hwndButton,hwndEdit[3];
char strEdit[80];
float a[3];
double root[2];
int i;

switch(message){
case WM_CREATE:
hwndEdit[0]=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,10,60,100,25,hwnd,NULL,NULL,NULL);
hwndEdit[1]=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,120,60,100,25,hwnd,NULL,NULL,NULL);
hwndEdit[2]=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,230,60,100,25,hwnd,NULL,NULL,NULL);
hwndButton=CreateWindow("button","Show",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,340,60,80,25,hwnd,NULL,NULL,NULL);

return 0;
case WM_COMMAND:
if(((HWND)lParam==hwndButton)&&(HIWORD(wParam)==BN_CLICKED))
{for(i=0;i<3;i++){
GetWindowText(hwndEdit[i],strEdit,80);
a[i]=(float)atof(strEdit);
}
int n=GetRoot(a[0],a[1],a[2],root);
if(n<1) strcpy(str,"NO");
else sprintf(str,"fsaf:%f,%f",root[0],root[1]);
InvalidateRect(hwnd,NULL,TRUE);
}
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
MessageBox(NULL,str,"show",0);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
展开
 我来答
chimmy869
推荐于2016-10-22 · 超过63用户采纳过TA的回答
知道答主
回答量:183
采纳率:0%
帮助的人:191万
展开全部
是可以显示的。不过窗口形成时出现了重绘,把空的字符给重绘出来了。。
所以加个判断就行了
if (strlen(str) != 0)
{
MessageBox(NULL,str,"show", MB_OK);
}
改后完整程序如下。
#include<windows.h>
#include<math.h>
#include<stdio.h>
int GetRoot(float a,float b,float c,double *root)
{
double delta,deltasqrt;
delta=b*b-4.0*a*c;
if(delta<0.0)return 0;
deltasqrt=sqrt(delta);
if(a!=0){
root[0]=(-b+deltasqrt)/(2.0*a);
root[1]=(-b-deltasqrt)/(2.0*a);
}
else
if(b!=0)root[0]=root[1]=-c/b;
else return 0;
if(root[0]==root[1])return 1;
else return 2;
}
char str[80];
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style =CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc =WndProc;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra =0;
wndclass.hInstance =hInstance;
wndclass.hIcon =LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor =LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName =NULL;
wndclass.lpszClassName ="HelloWin";
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,"窗口注册失败!","HelloWin",0);
return 0;
}
hwnd=CreateWindow("HelloWin",
"我的窗口",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{ HDC hdc;
PAINTSTRUCT ps;
static HWND hwndButton,hwndEdit[3];
char strEdit[80];
float a[3];
double root[2];
int i;

switch(message){
case WM_CREATE:
hwndEdit[0]=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,10,60,100,25,hwnd,NULL,NULL,NULL);
hwndEdit[1]=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,120,60,100,25,hwnd,NULL,NULL,NULL);
hwndEdit[2]=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,230,60,100,25,hwnd,NULL,NULL,NULL);
hwndButton=CreateWindow("button","Show",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,340,60,80,25,hwnd,NULL,NULL,NULL);

return 0;
case WM_COMMAND:
if(((HWND)lParam==hwndButton)&&(HIWORD(wParam)==BN_CLICKED))
{for(i=0;i<3;i++){
GetWindowText(hwndEdit[i],strEdit,80);
a[i]=(float)atof(strEdit);
}
int n=GetRoot(a[0],a[1],a[2],root);
if(n<1) strcpy(str,"NO");
else sprintf(str,"fsaf:%f,%f",root[0],root[1]);

InvalidateRect(hwnd,NULL,TRUE);
}
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
if (strlen(str) != 0)
{
MessageBox(NULL,str,"show", MB_OK);
}
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
微测检测5.10
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇... 点击进入详情页
本回答由微测检测5.10提供
仁斯实嘉泽
2020-05-21 · TA获得超过3686个赞
知道大有可为答主
回答量:3076
采纳率:29%
帮助的人:167万
展开全部
if(messagebox("选择是否执行",null,mb_yesno)==idyes)
{
afxmessagebox("ss");
//这里写你要执行的代码
}
----------------------------------------------
例子:要引入头文件windows.h
#include<iostream.h>
#include<windows.h>
void
main(){
if(messagebox(null,"是否打印?","choose",mb_yesno)==idyes)
{
cout<<"sss";
}
}
--------------------------------
当然也可以用mfc做。。由于生成的文件较多,就不贴了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
庆育舒平惠
2020-03-04 · TA获得超过3810个赞
知道大有可为答主
回答量:3142
采纳率:33%
帮助的人:183万
展开全部
从VC2005开始,默认是Unicode,
你要改成MessageBox(_T("Message"),_T("Title"),MB_ICONINFORMATION|MB_OK);
或者MessageBox(L("Message"),L("Title"),MB_ICONINFORMATION|MB_OK);
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式