求一个80行C语言程序
5个回答
展开全部
这是我从前写的键盘模拟程序。具体功能见里面的英文说明。
下面主函数 调用 只是 一个模拟 例子, 执行了抓取频幕,
并存放为 keyb_tmp.bmp
其它例子 注解掉了。去掉 // 就可执行。
编译器 MS VC++ 6.0
完整含说明,详细程序。(哦,字数超出,不让贴,不得不删去 一点说明)
/* ================================================*
* simu_keyboard.c
* Ji Zhang Jun-27-2006
* ---------------------------------------------------
* Function Syntax
* ---------------------------------------------------
* something can be done by such tech
* Send Screen_Capture, Window_Capture to clipboard.
* GetDIBits() can chose begin and end row number
* get mouse location on Desk Top ?
* ---------------------------------------------------
* Short-Cut key simulations:
* minimize all windows "windows + D" or "windows + M"
* cancel minimize windows "shift + window + M
* Alt+Backspace or CTRL+Z cancel previous op
* Alt+Shift+Backspace re-do the canceled op
* Alt+ESC active next window
* ===============================
void keybd_event(BYTE bVirtualKey, BYTE bScanCode,
DWORD dwFlags, DWORD dwExtraInfo);
bVirtualKey:
VK_NUMPAD7 0x67 VK_BACK 0x08
VK_NUMPAD8 0x68 VK_TAB 0x09
VK_NUMPAD9 0x69 VK_RETURN 0x0D
VK_MULTIPLY 0x6A VK_SHIFT 0x10
VK_ADD 0x6B VK_CONTROL 0x11
VK_SEPARATOR 0x6C VK_MENU 0x12
VK_SUBTRACT 0x6D VK_PAUSE 0x13
VK_DECIMAL 0x6E VK_CAPITAL 0x14
VK_DIVIDE 0x6F VK_ESCAPE 0x1B
VK_F1 0x70 VK_SPACE 0x20
VK_F2 0x71 VK_END 0x23
VK_F3 0x72 VK_HOME 0x24
VK_F4 0x73 VK_LEFT 0x25
VK_F5 0x74 VK_UP 0x26
VK_F6 0x75 VK_RIGHT 0x27
VK_F7 0x76 VK_DOWN 0x28
VK_F8 0x77 VK_PRINT 0x2A
VK_F9 0x78 VK_SNAPSHOT 0x2C
VK_F10 0x79 VK_INSERT 0x2D
VK_F11 0x7A VK_DELETE 0x2E
VK_F12 0x7B VK_LWIN 0x5B
VK_NUMLOCK 0x90 VK_RWIN 0x5C
VK_SCROLL 0x91 VK_NUMPAD0 0x60
VK_LSHIFT 0xA0 VK_NUMPAD1 0x61
VK_RSHIFT 0xA1 VK_NUMPAD2 0x62
VK_LCONTROL 0xA2 VK_NUMPAD3 0x63
VK_RCONTROL 0xA3 VK_NUMPAD4 0x64
VK_LMENU 0xA4 VK_NUMPAD5 0x65
VK_RMENU 0xA5 VK_NUMPAD6 0x66
================
bScanCode (use break code):
// Simulating a Alt+Tab keystroke
keybd_event(VK_MENU,0xb8,0 , 0); //Alt Press
keybd_event(VK_TAB,0x8f,0 , 0); // Tab Press
keybd_event(VK_TAB,0x8f, KEYEVENTF_KEYUP,0); // Tab Release
keybd_event(VK_MENU,0xb8,KEYEVENTF_KEYUP,0); // Alt Release
* ---------------------------------------------------
* SendInput() may do the same work
* ==============================================*/
#include <Windows.h>
#include <Winuser.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <time.h>
#define DEBUG 1
#pragma comment (lib, "User32.lib")
#pragma comment (lib, "Gdi32.lib")
void snapscreen_2_clipboard();
void snapwin_2_clipboard();
int get_mousebt_status();
void wait ( int m_seconds);
void simu_notepad();
void do_action(unsigned char action);
// dib functions
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;
main(int argc, char * argv[])
{
int i=0,j=0;
int px,py;
time_t now;
unsigned char action;
char buf[256];
// (void) do_action(0x44);
// following 3 calls for screen capture and save to bmp
(void) snapscreen_2_clipboard();
(void) wait(1000);
(void) save_clipboard_img_to_bmp();
// show exploer: (void) do_action(0x45); // works
// show file finder: (void) do_action(0x46); //works
// minimize all windows: (void) do_action(0x4d); // good
// show run command: (void) do_action(0x52); // Start->Run
// show start menu: (void) do_action(0x5B); // left mouse press Start
// show windows help: (void) do_action(0x70); // display "help center"
// Go on Standby: (void) do_action(0x5e); // do nothing
// simu_notepad();
/* -------------------------------------------------------
test mouse
press and release a BT, return the location and BT id
1 = Left 2=Right 3=Mid, [px,py] screen coords
* -------------------------------------------------------*/
/*---
while (i < 40 ) {
j = get_mousebt_status(&px,&py);
if (j > 0) while (get_mousebt_status(&px,&py) !=0 ) {};
if ( j > 0) {
printf("%d: x=%d y=%d at ",j,px,py );
time(&now);
printf("%s",ctime(&now));
};
i = i + j;
};
*---*/
exit(0);
}
/* ------------------------------------------------ *
* void do_action(unsigned char action)
* action can be 0x45 0x46 0x4d 0x52 0x5b 0x70 0x5e
* -------------------------------------------------*/
void do_action(unsigned char action){
keybd_event(VK_LWIN,0,0,0);
keybd_event(action,0,0,0);
keybd_event(VK_LWIN,0,KEYEVENTF_KEYUP,0);
}
/* -------------------------------
* similar to system("notepad");
* typing letters
* ------------------------------*/
void simu_notepad()
{
/*
keybd_event(VkKeyScan('N'),1,0,0); keybd_event(VkKeyScan('N'),1,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('O'),0x98,0,0); keybd_event(VkKeyScan('O'),0x98,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('T'),0x94,0,0); keybd_event(VkKeyScan('T'),0x94,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('E'),0x92,0,0); keybd_event(VkKeyScan('E'),0x92,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('P'),0x99,0,0); keybd_event(VkKeyScan('P'),0x99,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('A'),0x9E,0,0); keybd_event(VkKeyScan('A'),0x9E,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('D'),0xA0,0,0); keybd_event(VkKeyScan('D'),0xA0,KEYEVENTF_KEYUP,0);
keybd_event(VK_RETURN,1,0,0);
keybd_event(VK_RETURN,1,KEYEVENTF_KEYUP,0);
*/
// keybd_event(VkKeyScan('C'),1,0,0); keybd_event(VkKeyScan('C'),1,KEYEVENTF_KEYUP,0);
// keybd_event(VkKeyScan('M'),1,0,0); keybd_event(VkKeyScan('M'),1,KEYEVENTF_KEYUP,0);
// keybd_event(VkKeyScan('D'),1,0,0); keybd_event(VkKeyScan('D'),1,KEYEVENTF_KEYUP,0);
// keybd_event(VK_RETURN,1,0,0);
// keybd_event(VK_RETURN,1,KEYEVENTF_KEYUP,0);
}
/* ------------------------------------------
* get mouse left and right button status
* if left down = 1
* if right down = 2
* else 0 -- up
* if GetAsyncKeyState(VK_RBUTTON) == 0 then UP
* if GetAsyncKeyState(VK_RBUTTON) != 0 then down
* down: ffff8000
* cmd catchs the left button !
* this can catch mouse outside of current window
BOOL GetCursorPos( LPPOINT lpPoint // cursor position );
POINT pt; GetCursorPos(&pt);
return mouse BT status:
Left-down=1,right-down=2,mid-down=3,up=0;
return mouse position on Desk Top: [x,y]
* ------------------------------------------*/
int get_mousebt_status(int *x, int *y ){
int st;
short int b1,b2,b3;
POINT pt;
GetCursorPos(&pt); // always to get mouse position
*x = pt.x; *y = pt.y; // return mouse position
st = b1 = b2 = b3 = 0;
b1 = 0x8000 & GetAsyncKeyState(VK_LBUTTON);
b2 = 0x8000 & GetAsyncKeyState(VK_RBUTTON);
b3 = 0x8000 & GetAsyncKeyState(VK_MBUTTON);
if ( b1 != 0 ) st = 1; // if left button down, return 1
if ( b2 != 0 ) st = 2; // if right button down, return 2
if ( b3 != 0 ) st = 3; // if mid button down, return 3
return st;
}
void wait ( int m_seconds )
{
clock_t endwait;
endwait = clock () + m_seconds ; // * CLK_TCK
while (clock() < endwait) {}
}
/* ----------------------------------
simulation of Alt-PrintScreen
to get current Window image in clipboard
Ji Zhang 2006-May-23
* -----------------------------------*/
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);
}
/* ----------------------------------
simulation of PrintScreen
to get current Desk Top image in clipboard
Ji Zhang 2006-May-23
* -----------------------------------*/
void snapscreen_2_clipboard()
{
keybd_event(VK_SNAPSHOT,0x2C,0,0);
keybd_event(VK_SNAPSHOT,0x2C,KEYEVENTF_KEYUP,0);
}
/* --------------------------------------------------------------
* 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 -------------------- */
下面主函数 调用 只是 一个模拟 例子, 执行了抓取频幕,
并存放为 keyb_tmp.bmp
其它例子 注解掉了。去掉 // 就可执行。
编译器 MS VC++ 6.0
完整含说明,详细程序。(哦,字数超出,不让贴,不得不删去 一点说明)
/* ================================================*
* simu_keyboard.c
* Ji Zhang Jun-27-2006
* ---------------------------------------------------
* Function Syntax
* ---------------------------------------------------
* something can be done by such tech
* Send Screen_Capture, Window_Capture to clipboard.
* GetDIBits() can chose begin and end row number
* get mouse location on Desk Top ?
* ---------------------------------------------------
* Short-Cut key simulations:
* minimize all windows "windows + D" or "windows + M"
* cancel minimize windows "shift + window + M
* Alt+Backspace or CTRL+Z cancel previous op
* Alt+Shift+Backspace re-do the canceled op
* Alt+ESC active next window
* ===============================
void keybd_event(BYTE bVirtualKey, BYTE bScanCode,
DWORD dwFlags, DWORD dwExtraInfo);
bVirtualKey:
VK_NUMPAD7 0x67 VK_BACK 0x08
VK_NUMPAD8 0x68 VK_TAB 0x09
VK_NUMPAD9 0x69 VK_RETURN 0x0D
VK_MULTIPLY 0x6A VK_SHIFT 0x10
VK_ADD 0x6B VK_CONTROL 0x11
VK_SEPARATOR 0x6C VK_MENU 0x12
VK_SUBTRACT 0x6D VK_PAUSE 0x13
VK_DECIMAL 0x6E VK_CAPITAL 0x14
VK_DIVIDE 0x6F VK_ESCAPE 0x1B
VK_F1 0x70 VK_SPACE 0x20
VK_F2 0x71 VK_END 0x23
VK_F3 0x72 VK_HOME 0x24
VK_F4 0x73 VK_LEFT 0x25
VK_F5 0x74 VK_UP 0x26
VK_F6 0x75 VK_RIGHT 0x27
VK_F7 0x76 VK_DOWN 0x28
VK_F8 0x77 VK_PRINT 0x2A
VK_F9 0x78 VK_SNAPSHOT 0x2C
VK_F10 0x79 VK_INSERT 0x2D
VK_F11 0x7A VK_DELETE 0x2E
VK_F12 0x7B VK_LWIN 0x5B
VK_NUMLOCK 0x90 VK_RWIN 0x5C
VK_SCROLL 0x91 VK_NUMPAD0 0x60
VK_LSHIFT 0xA0 VK_NUMPAD1 0x61
VK_RSHIFT 0xA1 VK_NUMPAD2 0x62
VK_LCONTROL 0xA2 VK_NUMPAD3 0x63
VK_RCONTROL 0xA3 VK_NUMPAD4 0x64
VK_LMENU 0xA4 VK_NUMPAD5 0x65
VK_RMENU 0xA5 VK_NUMPAD6 0x66
================
bScanCode (use break code):
// Simulating a Alt+Tab keystroke
keybd_event(VK_MENU,0xb8,0 , 0); //Alt Press
keybd_event(VK_TAB,0x8f,0 , 0); // Tab Press
keybd_event(VK_TAB,0x8f, KEYEVENTF_KEYUP,0); // Tab Release
keybd_event(VK_MENU,0xb8,KEYEVENTF_KEYUP,0); // Alt Release
* ---------------------------------------------------
* SendInput() may do the same work
* ==============================================*/
#include <Windows.h>
#include <Winuser.h>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <time.h>
#define DEBUG 1
#pragma comment (lib, "User32.lib")
#pragma comment (lib, "Gdi32.lib")
void snapscreen_2_clipboard();
void snapwin_2_clipboard();
int get_mousebt_status();
void wait ( int m_seconds);
void simu_notepad();
void do_action(unsigned char action);
// dib functions
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;
main(int argc, char * argv[])
{
int i=0,j=0;
int px,py;
time_t now;
unsigned char action;
char buf[256];
// (void) do_action(0x44);
// following 3 calls for screen capture and save to bmp
(void) snapscreen_2_clipboard();
(void) wait(1000);
(void) save_clipboard_img_to_bmp();
// show exploer: (void) do_action(0x45); // works
// show file finder: (void) do_action(0x46); //works
// minimize all windows: (void) do_action(0x4d); // good
// show run command: (void) do_action(0x52); // Start->Run
// show start menu: (void) do_action(0x5B); // left mouse press Start
// show windows help: (void) do_action(0x70); // display "help center"
// Go on Standby: (void) do_action(0x5e); // do nothing
// simu_notepad();
/* -------------------------------------------------------
test mouse
press and release a BT, return the location and BT id
1 = Left 2=Right 3=Mid, [px,py] screen coords
* -------------------------------------------------------*/
/*---
while (i < 40 ) {
j = get_mousebt_status(&px,&py);
if (j > 0) while (get_mousebt_status(&px,&py) !=0 ) {};
if ( j > 0) {
printf("%d: x=%d y=%d at ",j,px,py );
time(&now);
printf("%s",ctime(&now));
};
i = i + j;
};
*---*/
exit(0);
}
/* ------------------------------------------------ *
* void do_action(unsigned char action)
* action can be 0x45 0x46 0x4d 0x52 0x5b 0x70 0x5e
* -------------------------------------------------*/
void do_action(unsigned char action){
keybd_event(VK_LWIN,0,0,0);
keybd_event(action,0,0,0);
keybd_event(VK_LWIN,0,KEYEVENTF_KEYUP,0);
}
/* -------------------------------
* similar to system("notepad");
* typing letters
* ------------------------------*/
void simu_notepad()
{
/*
keybd_event(VkKeyScan('N'),1,0,0); keybd_event(VkKeyScan('N'),1,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('O'),0x98,0,0); keybd_event(VkKeyScan('O'),0x98,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('T'),0x94,0,0); keybd_event(VkKeyScan('T'),0x94,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('E'),0x92,0,0); keybd_event(VkKeyScan('E'),0x92,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('P'),0x99,0,0); keybd_event(VkKeyScan('P'),0x99,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('A'),0x9E,0,0); keybd_event(VkKeyScan('A'),0x9E,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('D'),0xA0,0,0); keybd_event(VkKeyScan('D'),0xA0,KEYEVENTF_KEYUP,0);
keybd_event(VK_RETURN,1,0,0);
keybd_event(VK_RETURN,1,KEYEVENTF_KEYUP,0);
*/
// keybd_event(VkKeyScan('C'),1,0,0); keybd_event(VkKeyScan('C'),1,KEYEVENTF_KEYUP,0);
// keybd_event(VkKeyScan('M'),1,0,0); keybd_event(VkKeyScan('M'),1,KEYEVENTF_KEYUP,0);
// keybd_event(VkKeyScan('D'),1,0,0); keybd_event(VkKeyScan('D'),1,KEYEVENTF_KEYUP,0);
// keybd_event(VK_RETURN,1,0,0);
// keybd_event(VK_RETURN,1,KEYEVENTF_KEYUP,0);
}
/* ------------------------------------------
* get mouse left and right button status
* if left down = 1
* if right down = 2
* else 0 -- up
* if GetAsyncKeyState(VK_RBUTTON) == 0 then UP
* if GetAsyncKeyState(VK_RBUTTON) != 0 then down
* down: ffff8000
* cmd catchs the left button !
* this can catch mouse outside of current window
BOOL GetCursorPos( LPPOINT lpPoint // cursor position );
POINT pt; GetCursorPos(&pt);
return mouse BT status:
Left-down=1,right-down=2,mid-down=3,up=0;
return mouse position on Desk Top: [x,y]
* ------------------------------------------*/
int get_mousebt_status(int *x, int *y ){
int st;
short int b1,b2,b3;
POINT pt;
GetCursorPos(&pt); // always to get mouse position
*x = pt.x; *y = pt.y; // return mouse position
st = b1 = b2 = b3 = 0;
b1 = 0x8000 & GetAsyncKeyState(VK_LBUTTON);
b2 = 0x8000 & GetAsyncKeyState(VK_RBUTTON);
b3 = 0x8000 & GetAsyncKeyState(VK_MBUTTON);
if ( b1 != 0 ) st = 1; // if left button down, return 1
if ( b2 != 0 ) st = 2; // if right button down, return 2
if ( b3 != 0 ) st = 3; // if mid button down, return 3
return st;
}
void wait ( int m_seconds )
{
clock_t endwait;
endwait = clock () + m_seconds ; // * CLK_TCK
while (clock() < endwait) {}
}
/* ----------------------------------
simulation of Alt-PrintScreen
to get current Window image in clipboard
Ji Zhang 2006-May-23
* -----------------------------------*/
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);
}
/* ----------------------------------
simulation of PrintScreen
to get current Desk Top image in clipboard
Ji Zhang 2006-May-23
* -----------------------------------*/
void snapscreen_2_clipboard()
{
keybd_event(VK_SNAPSHOT,0x2C,0,0);
keybd_event(VK_SNAPSHOT,0x2C,KEYEVENTF_KEYUP,0);
}
/* --------------------------------------------------------------
* 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 -------------------- */
展开全部
#include "time.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
main()
{
char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf("do you want to play it.('y' or 'n') \n");
loop:
while((c=getchar())=='y')
{
i=rand()%100;
printf("\nplease input number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{
if(guess>i)
{
printf("please input a little smaller.\n");
scanf("%d",&guess);
}
else
{
printf("please input a little bigger.\n");
scanf("%d",&guess);
}
}
end=clock();
b=time(NULL);
printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);
printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));
if(var<15)
printf("\1\1 You are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n\n");
else
printf("\1\1 you are stupid! \1\1\n\n");
printf("\1\1 Congradulations \1\1\n\n");
printf("The number you guess is %d",i);
}
printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
if((c=getch())=='y')
goto loop;
}
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
main()
{
char c;
clock_t start,end;
time_t a,b;
double var;
int i,guess;
srand(time(NULL));
printf("do you want to play it.('y' or 'n') \n");
loop:
while((c=getchar())=='y')
{
i=rand()%100;
printf("\nplease input number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while(guess!=i)
{
if(guess>i)
{
printf("please input a little smaller.\n");
scanf("%d",&guess);
}
else
{
printf("please input a little bigger.\n");
scanf("%d",&guess);
}
}
end=clock();
b=time(NULL);
printf("\1: It took you %6.3f seconds\n",var=(double)(end-start)/18.2);
printf("\1: it took you %6.3f seconds\n\n",difftime(b,a));
if(var<15)
printf("\1\1 You are very clever! \1\1\n\n");
else if(var<25)
printf("\1\1 you are normal! \1\1\n\n");
else
printf("\1\1 you are stupid! \1\1\n\n");
printf("\1\1 Congradulations \1\1\n\n");
printf("The number you guess is %d",i);
}
printf("\ndo you want to try it again?(\"yy\".or.\"n\")\n");
if((c=getch())=='y')
goto loop;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我这有个简单的日历估计有几百行,我自己写的,要不要?
追问
谢谢啦!我已经写好了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
网上有很多的,去去找找吧
追问
嗯嗯
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你用来干什么的?你只说80行,谁知道啊
更多追问追答
追问
C语言作业,内容不限
C语言作业,内容不限
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询