用c++编写一个程序输出 hello world 运行截屏

要带截屏的

我用VC++编一个吧,你可以试试

#include "stdafx.h"

#include <iostream>   //使用iostream库,这行也必不可少。

#include <stdio.h>

using namespace std;  //使用标准名称空间std,这行必不可少,因为cout使用的是这个标准名称空间

void main()  //必须为main方法指定一个反回类型,否则会出错。

{  

 cout<<"hello world"<<endl;  //使用cout流输出字符。

 cin.ignore();   //使程序暂停,如果不要这一行,则输出的结果会在屏幕上闪一下就消失了。

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-03-03

#include<iostream>

using namespace std;

int main()

{

    cout<<"hello world"<<endl;

    return 0;

}

第2个回答  2010-03-03

希望能帮到你~

第3个回答  2010-03-05
自动运行截屏程序 a.c 来了。

编译命令:cl a.c user32.lib Gdi32.lib

运行后,截屏在 hello_tmp.bmp 文件里。用能看BMP的图像软件都可以看。
#include <Windows.h>
#include <Winuser.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <time.h>
#define DEBUG 1
void snapwin_2_clipboard();
void wait ( int m_seconds);
int GetBytesPerPixel(int depth);
int GetBytesPerRow(int width, int depth);
int GetBitmapBytes(int width, int height, int depth);
void save_clipboard_img_to_bmp();
FILE *fout;

void main(int argc, char * argv[])
{
int i=0,j=0;
int px,py;
time_t now;
unsigned char action;
char buf[256];

system("CLS"); //清屏幕
printf("Hello World !"); //显示字
(void) snapwin_2_clipboard(); //截屏
(void) wait(1000); //等1秒
(void) save_clipboard_img_to_bmp(); //转为BMP并存放
exit(0);
}

void wait ( int m_seconds )
{
clock_t endwait;
endwait = clock () + m_seconds ;
while (clock() < endwait) {}
}

void snapwin_2_clipboard()
{
keybd_event(VK_LMENU,0xA4,0,0);
keybd_event(VK_SNAPSHOT,0x2C,0,0);
keybd_event(VK_SNAPSHOT,0x2C,KEYEVENTF_KEYUP,0);
keybd_event(VK_LMENU,0xA4,KEYEVENTF_KEYUP,0);
}

int GetBytesPerPixel(int depth)
{ return (depth==32 ? 4 : 3);
}

int GetBytesPerRow(int width, int depth)
{
int bytesPerPixel = GetBytesPerPixel(depth);
int bytesPerRow = ((width * bytesPerPixel + 3) & ~3);
return bytesPerRow;
}

// bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight, bmi.bmiHeader.biBitCount
int GetBitmapBytes(int width, int height, int depth)
{
return height * GetBytesPerRow(width, depth);
}

void save_clipboard_img_to_bmp()
{
char nameout[80];
HANDLE h_bitmap,h_dib;
BITMAPINFO bmi;
HDC hDC;
int imageBytes;
BITMAPFILEHEADER hdr;
int scanLineCount;
unsigned char *img;
if (!OpenClipboard(NULL)) {
printf("Can not open clipboard\n");
exit(0);
};

h_bitmap = GetClipboardData(CF_BITMAP);
h_dib = GetClipboardData(CF_DIB);

memcpy(&bmi,h_dib,sizeof(bmi));
printf("%d x %d \n",bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight);
hDC = CreateCompatibleDC(NULL); // Gdi32.lib.
CloseClipboard();

bmi.bmiHeader.biCompression = BI_RGB;
imageBytes = GetBitmapBytes(bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight,

bmi.bmiHeader.biBitCount);
img = (char *) malloc(imageBytes);
if (!img) {
printf("No enought memory for img !\n"); exit(0);
}

hdr.bfType = ((WORD) ('M' << 8) | 'B');
hdr.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
+ (bmi.bmiHeader.biClrUsed * sizeof(RGBQUAD)) + bmi.bmiHeader.biSizeImage;
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
hdr.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)
+ (bmi.bmiHeader.biClrUsed * sizeof(RGBQUAD));
scanLineCount = GetDIBits(hDC,h_bitmap,0,bmi.bmiHeader.biHeight, img, &bmi, DIB_RGB_COLORS);
strcpy(nameout,"hello_tmp.bmp");
if ( (fout = fopen(nameout,"wb") ) == NULL ) {
printf("\007Cann't open output file: %s ", nameout);exit(1);
};
fwrite( &hdr, sizeof(BITMAPFILEHEADER ), 1, fout );
fwrite( &bmi, sizeof(BITMAPINFO), 1, fout );
fwrite( img, sizeof(unsigned char),imageBytes, fout );
fclose(fout);
printf("Output in %s\n",nameout);
}
第4个回答  2010-03-03
#include <iostream.h>
#include <stdlib.h>
main(){
cout<<hello world<<endl;
system("pause");
}

自己运行截屏。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网