Allora:
.h
#ifndef UTILITY_H
#define UTILITY_H
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <stdio.h>
#include <unistd.h>
#define DELAY 1000
#define SX 0
#define DX 1
COORD Click_Mouse(BOOL *flag);
#endif // UTILITY_H
.c
#include "Utility.h"
static POINT Mouse_XY_Pixel(void){
POINT p;
HWND hWnd=GetConsoleWindow();
GetCursorPos(&p);
ScreenToClient(hWnd,&p);
return p;
}
COORD Click_Mouse(BOOL *flag){
POINT pt;
CONSOLE_FONT_INFO cfi;
HANDLE hStdout=GetStdHandle(STD_OUTPUT_HANDLE);
while(1){
usleep(DELAY);
if(GetAsyncKeyState(VK_LBUTTON)){
pt=Mouse_XY_Pixel();
if(GetCurrentConsoleFont(hStdout,0,&cfi)){
cfi.dwFontSize.X=pt.x/cfi.dwFontSize.X;
cfi.dwFontSize.Y=pt.y/cfi.dwFontSize.Y;
*flag=SX;
break;
}
}
else if(GetAsyncKeyState(VK_RBUTTON)){
pt=Mouse_XY_Pixel();
if(GetCurrentConsoleFont(hStdout,0,&cfi)){
cfi.dwFontSize.X=pt.x/cfi.dwFontSize.X;
cfi.dwFontSize.Y=pt.y/cfi.dwFontSize.Y;
*flag=DX;
break;
}
}
}
return cfi.dwFontSize;
}
main
#include <stdio.h>
#include <stdlib.h>
#include "Utility.h"
int main(){
BOOL flag;
COORD a;
int i;
a=Click_Mouse(&flag);
for(i=0;i<a.Y;i++)
printf("\n");
for(i=0;i<a.X;i++)
printf(" ");
printf("X");
return 0;
}
Compilazione:
mingw32-gcc.exe -Wall -g -c C:\Users\Nanni\Desktop\rge\main.c -o obj\Debug\main.o
mingw32-gcc.exe -Wall -g -c C:\Users\Nanni\Desktop\rge\Utility.c -o obj\Debug\Utility.o
C:\Users\Nanni\Desktop\rge\Utility.c: In function 'Click_Mouse':
C:\Users\Nanni\Desktop\rge\Utility.c:19:13: warning: implicit declaration of function 'GetCurrentConsoleFont' [-Wimplicit-function-declaration]
mingw32-g++.exe -o bin\Debug\rge.exe obj\Debug\main.o obj\Debug\Utility.o
obj\Debug\Utility.o: In function `Click_Mouse':
C:/Users/Nanni/Desktop/rge/Utility.c:19: undefined reference to `GetCurrentConsoleFont'
C:/Users/Nanni/Desktop/rge/Utility.c:29: undefined reference to `GetCurrentConsoleFont'
collect2.exe: error: ld returned 1 exit status