弹出对话框函数MessageBox()的原型如下:
int MessageBox(
HWND hWnd, // handle to owner window
LPCTSTR lpText, // text in message box
LPCTSTR lpCaption, // message box title
UINT uType // message box style
);
第一个参数 HWND hwnd,表示窗口的句柄,一般为NULL;
第二个参数LPCTSTR lpText,表示对话框里的文本内容;
第三个参数LPCTRSTR lpCaption,表示对话框的标题名称;
第四个参数UINT uType,表示按钮的风格与个数,比如MB_OK表示有一个“确定”按钮;MB_OKCANCEL表示有2个按钮,一个为”确定”,另一个为“取消”;MB_YESNOCANCEL表示有3个按钮,分别为”是”、“否”、“取消”。
在VC6.0下,新建一个win32的工程,类型是“A simple Win32 Application”,名称为:LocalTime3
在LocalTime3.cpp输入如下代码:
//LocalTime3.cpp
#include "stdafx.h"
#include <shlwapi.h>
#include <stdio.h>
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
SYSTEMTIME time;
::GetLocalTime(&time);
float h=0,m=0,s=0;
h=time.wHour; m=time.wMinute; s=time.wSecond;
char str1[10],str2[10],str3[10];
char myStr[50]="";
sprintf(str1,"%.f:",h);
sprintf(str2,"%.f:",m);
sprintf(str3,"%.f",s);
StrCat(myStr,"现在时间为: ");
StrCat(myStr,str1);
StrCat(myStr,str2);
StrCat(myStr,str3);
//printf(" 当前时间为:%.2d:%.2d:%.2d \n", time.wHour, time.wMinute, time.wSecond);
MessageBox(NULL,myStr,"时间",MB_OK);
return 0;
}
效果如下: