展开全部
自动运行截屏程序 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);
}
编译命令: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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream.h>
#include <stdlib.h>
main(){
cout<<hello world<<endl;
system("pause");
}
自己运行截屏。
#include <stdlib.h>
main(){
cout<<hello world<<endl;
system("pause");
}
自己运行截屏。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询