vc++6.0 的各个新建文件是啥意思
//ShowArticle(显示文章)#include<windows.h>
#include<stdio.h>
#include<stdlib.h>
#include"resource.h"
//因为要播放音乐 , 所以要导入这个库文件
#pragma comment(lib, "winmm.lib")
//重新定义一个窗口风格,不能改变窗口大小
#define WS_NORESIZEWINDOW (WS_OVERLAPPED | \
WS_CAPTION | \
WS_SYSMENU | \
WS_MINIMIZEBOX)
//定义计时器的ID
#define ID_TIMER 0
//为了避免函数的参数设定太多,显得冗余,因此设定一下变量为全局
FILE *fp = NULL;//文件指针
TCHAR word[2];//字符数组 , 保存读取的一个字
int row, col;//标记行号和列号
int cxChar, cyChar;//系统字符的size 分别是字符的平均宽度、字符的高度
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int ShowWord(HDC);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
static TCHAR szAppName[] = TEXT("ShowArticle");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
int cxScreen, cyScreen;//屏幕的长宽
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 = szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("This program requires Windows NT!"),
szAppName, MB_ICONERROR);
return 0;
}
//获取屏幕的长宽
cxScreen = GetSystemMetrics(SM_CXSCREEN);
cyScreen = GetSystemMetrics(SM_CYSCREEN);
hwnd = CreateWindow(szAppName,
TEXT("ShowArticle Demo"),
WS_NORESIZEWINDOW,
cxScreen / 4,//居中显示窗口(相对屏幕而言)
cyScreen / 8 - 7,
cxScreen / 2,
cyScreen * 3 / 4 + 15,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, iCmdShow);
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)
{
static HBITMAP hBitmap; //位图句柄 标示位图
static int cxBitmap, cyBitmap; //位图的长宽
BITMAP bitmap;
HDC hdc, hdcMem;
HINSTANCE hInstance;
PAINTSTRUCT ps;
TEXTMETRIC tm;
switch(message)
{
case WM_CREATE:
//开始播放音乐
PlaySound("爱尔兰风笛.wav", NULL, SND_FILENAME | SND_ASYNC);
/*************************加载位图***********************/
hInstance = ((LPCREATESTRUCT)lParam)->hInstance; //获取窗口的实例句柄
hBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_BITMAP1)); //将位图加载到内存中
GetObject(hBitmap, sizeof(BITMAP), &bitmap);
cxBitmap = bitmap.bmWidth;//获取位图的长
cyBitmap = bitmap.bmHeight;//获取位图的宽
/**********************获取系统文本参数*************************/
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight;
ReleaseDC(hwnd, hdc);
//设定计时器
SetTimer(hwnd, ID_TIMER, 420, NULL);
return 0 ;
case WM_PAINT:
//绘制背景
hdc = BeginPaint(hwnd, &ps);
hdcMem = CreateCompatibleDC(hdc);//创建一个兼容于hdc设备环境描述表的hdcMem 主要是用于在内存中截图
SelectObject(hdcMem, hBitmap); //将位图选到hdcMem中
BitBlt(hdc, -1, -1, cxBitmap, cyBitmap, hdcMem, 0, 0, SRCCOPY);//绘制bmp位图
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
Sleep(2500);//为了让文字显示和音乐播放同步 , 这里睡眠2.5s
return 0;
case WM_TIMER:
hdc = GetDC(hwnd);
//设定文本颜色
SetTextColor(hdc, RGB(rand()%255, rand()%255, rand()%255));
SetBkMode(hdc,TRANSPARENT);//设定文本的背景透明
//如果文件读取完了 , 计时器也应该关闭 , 免得浪费资源
if(ShowWord(hdc) == EOF)
{
KillTimer(hwnd, ID_TIMER);
}
ReleaseDC(hwnd, hdc);
return 0;
case WM_DESTROY:
DeleteObject(hBitmap);//删除位图资源,归还内存
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
//显示一个字
int ShowWord(HDC hdc)
{
TCHAR c;
if(fp == NULL)
{
if((fp = fopen("Poem.txt", "r")) == NULL)
{
exit(1);
}
}
if(fscanf(fp, "%c", &c) != EOF)
{
if(c == '\n')
{
row++;
col = 0;
/*
如果遇到'\n',说明需要换行,换行后,下一行首字
要和上一行首字对齐,因此要将列标col置零*/
}
else
{
word[0] = c;
fscanf(fp, "%c", &c);
word[1] = c;
col++;
/*
因为在ASC码中,一个字符一个字节,一个汉字两个字节,
因此汉字的宽度应该是英文字符的2倍,加上汉字之间要
有一定的空隙(+3),且尽量居中显示(+230),故x坐标应该
是: col * (2 * cxChar + 3) + 230
汉字的高度和字符的高度默认相同 , 因此只需要简单的乘上row就行了
*/
TextOut(hdc, col * (2 * cxChar + 3) + 225, row * cyChar + 5, word, 2);
}
return 0;
}
return EOF;
}
建立哪个文件才能运行以上程序?我想给我朋友准备生日礼物,怎样把歌曲弄成生日歌,还有些祝福语怎么改