在MessageBox()里输出时间

245 篇文章 8 订阅
84 篇文章 0 订阅

   弹出对话框函数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;
}

效果如下:

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sanqima

一键三连,多多益善

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值