3个回答
2013-08-16
展开全部
MS VC++ 的 c 程序可以实现。
方法哗哗:
(1)用键盘按键程序模拟法,把图像发送到clipboard
(2)把clipboard图像存入.bmp 图像文件(或别的格式)。
编译:
cl simu_keyboard.c user32.lib Gdi32.lib
特殊头文件:
#include <Windows.h>
#include <Winuser.h>
#include <memory.h>
提示:
(1)按键程序模拟子程序:
void snapscreen_2_clipboard()
{
keybd_event(VK_SNAPSHOT,0x2C,0,0);
keybd_event(VK_SNAPSHOT,0x2C,KEYEVENTF_KEYUP,0);
}
(2)clipboard图像存入.bmp 图像乱桐行文件
FILE *fout;
/* --------------------------------------------------------------
* dib
int GetBytesPerPixel(int depth);
int GetBytesPerRow(int width, int depth);
int GetBitmapBytes(int width, int height, int depth);
* --------------------------------------------------------------*/
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);
};
if (DEBUG ==1) printf("pass open clipboard\n");
// HANDLE GetClipboardData(UINT uFormat);
h_bitmap = GetClipboardData(CF_BITMAP);
h_dib = GetClipboardData(CF_DIB);
if (h_bitmap ==NULL || h_dib ==NULL){
printf("I got NULL bitmap: ");
} else { printf("I got bitmap: ");};
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;
// possible to use part of imgage with img_w,img_h
imageBytes = GetBitmapBytes(bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight, bmi.bmiHeader.biBitCount);
printf("pass GetBitmapBytes=%d \n",imageBytes);
img = (char *) malloc(imageBytes);
if (!img) {
printf("No enought memory for img !\n"); exit(0);
}
// BITMAPFILEHEADER hdr;
hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM"
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,"keyb_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);
}
/* -------end dib and bmp ----- */
方法哗哗:
(1)用键盘按键程序模拟法,把图像发送到clipboard
(2)把clipboard图像存入.bmp 图像文件(或别的格式)。
编译:
cl simu_keyboard.c user32.lib Gdi32.lib
特殊头文件:
#include <Windows.h>
#include <Winuser.h>
#include <memory.h>
提示:
(1)按键程序模拟子程序:
void snapscreen_2_clipboard()
{
keybd_event(VK_SNAPSHOT,0x2C,0,0);
keybd_event(VK_SNAPSHOT,0x2C,KEYEVENTF_KEYUP,0);
}
(2)clipboard图像存入.bmp 图像乱桐行文件
FILE *fout;
/* --------------------------------------------------------------
* dib
int GetBytesPerPixel(int depth);
int GetBytesPerRow(int width, int depth);
int GetBitmapBytes(int width, int height, int depth);
* --------------------------------------------------------------*/
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);
};
if (DEBUG ==1) printf("pass open clipboard\n");
// HANDLE GetClipboardData(UINT uFormat);
h_bitmap = GetClipboardData(CF_BITMAP);
h_dib = GetClipboardData(CF_DIB);
if (h_bitmap ==NULL || h_dib ==NULL){
printf("I got NULL bitmap: ");
} else { printf("I got bitmap: ");};
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;
// possible to use part of imgage with img_w,img_h
imageBytes = GetBitmapBytes(bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight, bmi.bmiHeader.biBitCount);
printf("pass GetBitmapBytes=%d \n",imageBytes);
img = (char *) malloc(imageBytes);
if (!img) {
printf("No enought memory for img !\n"); exit(0);
}
// BITMAPFILEHEADER hdr;
hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM"
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,"keyb_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);
}
/* -------end dib and bmp ----- */
2013-08-16
展开全部
利用SetWindowsHookEx 设置钩子.版本 2 m_hook = SetWindowsHookEx (3, 到整数 (&GetMsgProc), hMod, 0)
.版本 2.子程序 GetMsgProc, 整数型
.参数逗锋键 nCode, 整数型
.参数 wParam, 整山巧数型
.参数 lParam, 整数型
CopyMemory (pMsg, lParam, 20)
result = CallNextHookEx (m_hook, nCode, wParam, lParam)
返回(result) 卸载钩基物子 用 .版本 2 UnhookWindowsHookEx (m_hook)
.版本 2.子程序 GetMsgProc, 整数型
.参数逗锋键 nCode, 整数型
.参数 wParam, 整山巧数型
.参数 lParam, 整数型
CopyMemory (pMsg, lParam, 20)
result = CallNextHookEx (m_hook, nCode, wParam, lParam)
返回(result) 卸载钩基物子 用 .版本 2 UnhookWindowsHookEx (m_hook)
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-16
展开全部
你要干坏事吧···
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询