本文目录一览:
C语言。。messagebox用法
窗体上放置三个TextBox,分别输入a,b,c的值,控件命名:tbA,tbB,tbC 再放一个Button,设置Text为:求解,其单击后台代码如下:
private void button1_Click(object sender, EventArgs e)
{
double a = 0;
double b = 0;
double c = 0;
try
{
if (tbA.Text.Length == 0)
{
MessageBox.Show("请输入a的值", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
a = Convert.ToDouble(tbA.Text);
}
catch
{
MessageBox.Show("您输入的a的值不是一个数字,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
tbA.Focus();
return;
}
try
{
if (tbB.Text.Length == 0)
{
MessageBox.Show("请输入b的值", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
b = Convert.ToDouble(tbB.Text);
}
catch
{
MessageBox.Show("您输入的b的值不是一个数字,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
tbB.Focus();
return;
}
try
{
if (tbC.Text.Length == 0)
{
MessageBox.Show("请输入c的值", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
c = Convert.ToDouble(tbC.Text);
}
catch
{
MessageBox.Show("您输入的c的值不是一个数字,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
tbC.Focus();
return;
}
if (a == 0)
{
if (b == 0)
{
if (c == 0)
{
MessageBox.Show(string.Format("方程{0}x^2+{1}x+{2}=0的解为 x={3}", a, b, c, "任意实数"), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show(string.Format("方程{0}x^2+{1}x+{2}=0无实数解", a, b, c), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
MessageBox.Show(string.Format("方程{0}x^2+{1}x+{2}=0的解为 x={3}", a, b, c, -c / b), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
double delta = b * b - 4 * a * c;
if (delta < 0)
{
MessageBox.Show(string.Format("方程{0}x^2+{1}x+{2}=0无实数解", a, b, c), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show(string.Format("方程{0}x^2+{1}x+{2}=0的解为 x1={3} , x2={4}", a, b, c, (-b + System.Math.Sqrt(delta)) / 2 / a, (-b - System.Math.Sqrt(delta)) / 2 / a), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
用c语言如何实现弹除对话框
#include <windows.h>
#include <commdlg.h>
#include <stdio.h>
// 返回值: 成功 1, 失败 0
// 通过 path 返回获取的路径
int FileDialog(char *path)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); // 结构大小
ofn.lpstrFile = path; // 路径
ofn.nMaxFile = MAX_PATH; // 路径大小
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0"; // 文件类型
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
return GetOpenFileName(&ofn);
}
int main(int argc, char *argv[])
{
char szFile[MAX_PATH] = {0};
if(FileDialog(szFile))
{
puts(szFile);
}
getchar();
return 0;
}
WINDOWS程序MessagBox
#include <stdio.h>
#include <assert.h>
#include <string.h>
void analyze_string( char *string ); // Prototype
int main( void )
{
char test1[] = "abc", *test2 = NULL, test3[] = "";
printf ( "Analyzing string '%s'\n", test1 ); fflush( stdout );
analyze_string( test1 );
printf ( "Analyzing string '%s'\n", test2 ); fflush( stdout );
analyze_string( test2 );
printf ( "Analyzing string '%s'\n", test3 ); fflush( stdout );
analyze_string( test3 );
}
// Tests a string to see if it is NULL,
// empty, or longer than 0 characters.
void analyze_string( char * string )
{
assert( string != NULL ); // Cannot be NULL
assert( *string != '\0' ); // Cannot be empty
assert( strlen( string ) > 2 ); // Length must exceed 2
}
C语言中messagebox的用法
消息框的函数原型:
int MessageBox(HWND hwnd, LPCTSTR lpsztext, LPCSTR lpsztitle, UINT ustyle);
消息框函数有4个参数:
- 第1个参数是父窗口的句柄。为NULL,说明消息框没有父窗口。
- 第2个参数就是一个指向要显示字符串的指针。
- 第3个参数是消息框本身的标题。
- 第4个参数是指定消息框的内容和行为(即该消息框有几个按钮、文本对齐等状态,可以在20多个属性值中进行组合)。
MessageBox
的第4个参数可以是在WINUSER.H
中定义的一组前缀以MB_
开始的常数组合。 可以使用C语言的"或"(|
)运算符将下面显示的三组中各选一个常数组合起来指定消息框的内容和行为:
显示哪些按钮:
#define MB_OK 0X00000000L
#define MB_OKCANCEL 0X00000001L
#define MB_ABORTRERYGNORE 0X00000002L
#define MB_YESNOCANCEL 0X00000003L
#define MB_YESNO 0X00000004L
#define RERYCANCEL 0X00000005L
焦点在哪个按钮上:
#define MB_DEFBUTTON1 0X00000000L
#define MB_DEFBUTTON2 0X00000100L
#define MB_DEFBUTTON3 0X00000200L
#define MB_DEFBUTTON4 0X00000300L
图示的外观:
#define MB_ICONHAND 0x00000010L
#define MB_ICONQUESTION 0x00000020L
#define MB_ICONEXCLAMATION 0x00000030L
#define MB_ICONASTERISK 0x00000040L
图示的某些有替代名称:
#define MB_ICONWARNING MB_ICONEXCLAMATION
#define MB_ICONERROR MB_ICONHAND
#define MB_ICONINFORMATION MB_ICONASTERISK
#define MB_ICONSTOP MB_ICONHAND
示例:
MessageBox(NULL, "Hello, Windows!", "hello", MB_OK);
MessageBox(NULL, "Hello, Windows!", "HelloMsg", MB_YESNO | MB_ICONEXCLAMATION);
MessageBox(NULL, "Hello, Windows!", "HelloMsg", MB_YESNO | MB_DEFBUTTON1); // 表示窗口出来后焦点 focus落在Yes(第一个)按钮上