Windows API Painter header file

WinKey.hpp

#include
#include
#include

#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
//检测按键是否被按下

//MOUSE_MOVED   鼠标左键
//MOUSE_EVENT   鼠标右键
//MOUSE_WHEELED 鼠标滑轮

HWND hwnd=GetForegroundWindow();//当前控制台的窗口
bool HWND_STATE=1;//默认窗口是被显示的

inline void ChangeWindowShowState(){//改变窗口的显示状态 
    HWND_STATE=!HWND_STATE;
    ShowWindow(hwnd,HWND_STATE);
}

inline void SetWindowShowState(bool NEW_STATE){//设置窗口的显示状态 
    if(NEW_STATE!=HWND_STATE){
        ChangeWindowShowState();
    }
}

inline POINT GetCursorPos(){//得到鼠标的坐标 
    POINT p;GetCursorPos(&p);return p;
}

//SetCursorPos(int X,int Y) //设置鼠标的位置 

POINT point(int X,int Y){//声明一个点 
    POINT p={X,Y};return p;
}

POINT WaitKeyDown(int KEY){//等待鼠标单击事件 
    while(!KEY_DOWN(KEY));//一直等到单击KEY为止
    return GetCursorPos();
}

void gotoxy(int y,int x){//改变输出光标位置 
    COORD pos;pos.X=x;pos.Y=y;    
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);   
}

void Click(){//模拟鼠标单击 
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);  
    Sleep(10);
    mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); 
}

void Click(POINT p){
    SetCursorPos(p.x,p.y);
    Click();
}

void Click(int x,int y){
    SetCursorPos(x,y);
    Click();
}

Painter.cpp

#include"WinKey.hpp"
#include
#include
using namespace std;

//10,165  1250,710

namespace full_func{
    #define r_in(A,B,C) ((A)<=(B) && (B)<=(C))

    void PrintDot(int X, int Y){
        printf("Func: PrintDot\n");
        if(r_in(10,X,1250) && r_in(165,Y,710)){
            Click(X, Y);
            printf(">>> Print at (%4d,%4d)\n",X,Y);
        }
    }

    void Pause(){
        printf("Press Enter to continue...\n");
        while(!KEY_DOWN(13));//Wait until enter
        Sleep(200);
    }

    inline double _sqr(double x){return x*x;}

    int dlen(POINT a,POINT b){
        return sqrt(_sqr(a.x-b.x)+_sqr(a.y-b.y))+0.5;
    }

    #define ENTER_BREAK  if(KEY_DOWN(13)){Sleep(200);return;}

    void __PrintCircle(int X,int Y,int R){
        for(int i=X-R;i<=X+R;i++){
            for(int j=Y-R;j<=Y+R;j++){
                if(dlen(point(i,j),point(X,Y))==R)
                    PrintDot(i, j);
                ENTER_BREAK;
            }
        }
    }

    void _PrintCircle(int X,int Y,int R,double dtheta=0.01){
        double S=0.0,L=2*M_PI;
        double d = dtheta;
        for(double theta=S; theta <= S+L; theta+=d){
            PrintDot(X+R*cos(theta),Y+R*sin(theta));
            ENTER_BREAK;
        }
    }

    #define GET_BRUSH  Click(356,73)
    #define GET_PENCIL Click(268,78)
    #define GET_PAINT  Click(297,78)

    #define GET_COLOR1 Click(699,75)
    #define GET_COLOR2 Click(741,69)

    #define GET_RED    Click(839,64)
    #define GET_ORANGE Click(860,64)
    #define GET_BLUE   Click(950,63)
    #define GET_GREEN  Click(909,64)

    #define GET_BROWN  Click(815,63)
    #define GET_PINK   Click(838,87)
    #define GET_PURPLE Click(969,64)
    #define GET_CYAN   Click(925,63)

    #define GET_GRAY   Click(794,63)
    #define GET_BLACK  Click(773,64)
    #define GET_WHITE  Click(770,84)

    void PrintCircle(int X,int Y,int R){
        GET_BRUSH;
        double dtheta=min(0.01,1.0/R);
        _PrintCircle(X,Y,R,dtheta);
    }

    void __PrintLine(int dx,int dy,int X,int Y,double dt=0.01){
        for(double t=0.0; t<=1.0; t+=dt){
            PrintDot(X+dx*t,Y+dy*t);
            ENTER_BREAK;
        }
    }

    void PrintLine(int XS,int YS,int XT,int YT){
        GET_BRUSH;
        double dt=min(0.01,min(1.0/abs(XS-XT),1.0/abs(YS-YT)));
        __PrintLine(XT-XS,YT-YS,XS,YS,dt);
    }

    void PrintDotLine(int XS,int YS,int dx,int dy,int cnt){
        GET_BRUSH;
        for(int i=1;i<=cnt;i++){
            PrintDot(XS+dx*i,YS+dy*i);
            ENTER_BREAK;
        }
    }

    void PrintFunc(double (*f)(double),POINT (*trans)(double,double),double XS,double XT,double step=0.01){
        GET_BRUSH;
        for(double x=XS; x<=XT; x+=step){
            PrintDot(trans(x,f(x)).x, trans(x,f(x)).y);
            ENTER_BREAK;
        }
    }

    #define USE_TOOL(NAME,COLOR) GET_##NAME;GET_COLOR1;GET_##COLOR;
    #define SET_COLOR(COLOR) GET_COLOR1;GET_##COLOR;

    int X_BASE = 600, Y_BASE = 430, LEN_BASE = 50;
    POINT trans(double x, double y){
        POINT p={int(LEN_BASE*x+X_BASE),int(-LEN_BASE*y+Y_BASE)};
        return p;
    }

    POINT _trans(double x,double y){
        POINT p={int(LEN_BASE*y+X_BASE),int(-LEN_BASE*x+Y_BASE)};
        return p;
    }

    double __id(double x){return 0;}
    double _id(double x){return x;}

    void _PrintCoord(){
        GET_BRUSH;
        PrintFunc(__id,trans,-50,50);
        PrintFunc(__id,_trans,-50,50);  
    }

    double CirR = 2.0, CirX, CirY;
    double Cir(double x){
        return sqrt(CirR*CirR - (x-CirX)*(x-CirX))+CirY;
    }
    double _Cir(double x){
        return -sqrt(CirR*CirR - (x-CirX)*(x-CirX))+CirY;
    }

    void PrintPolFunc(double (*PolFunc)(double),POINT (*trans)(double,double),double TheS,double TheT){
        GET_BRUSH;
        for(double Theta=TheS; Theta<=TheT; Theta+=0.01/2){
            double R=PolFunc(Theta);
            double X=R*cos(Theta), Y=R*sin(Theta);
            POINT p=trans(X,Y);
            PrintDot(p.x,p.y);
            ENTER_BREAK;
        }
    }

    double _Heart(double theta){
        return sqrt((1.0-sin(theta))/2.0)+exp(-10*abs(theta-1.5*M_PI)-1.8);
    }

    double HeartT = 4;
    double Heart(double Theta){
        return _Heart(Theta) * HeartT;
    }

    double _Down2(double x){
        return _id(x)-2.0;
    }

    void _th2(){
        SET_COLOR(PINK);
        PrintPolFunc(Heart,trans,0.0,2*M_PI);
        X_BASE -= 50; Y_BASE += 50;
        SET_COLOR(RED);
        PrintPolFunc(Heart,trans,0.0,2*M_PI);
        SET_COLOR(PURPLE);
        PrintFunc(_Down2,trans,-4,4);
    }

    #undef r_in
}

namespace print_func{
    void PrintDot   (int X, int Y     ){full_func::PrintDot(X, Y);}
    void Pause      (                 ){full_func::Pause();}
    void PrintCircle(int X,int Y,int R){full_func::PrintCircle(X,Y,R);}

    void PrintLine(int XS,int YS,int XT,int YT){full_func::PrintLine(XS,YS,XT,YT);}
    void PrintDotLine(int XS,int YS,int dx,int dy,int cnt){
        full_func::PrintDotLine(XS,YS,dx,dy,cnt);
    }
    void PrintFunc(double (*f)(double),POINT (*trans)(double,double),double XS,double XT,double step=0.01){
        full_func::PrintFunc(f,trans,XS,XT,step);
    }
    void PrintPolFunc(double (*PolFunc)(double),POINT (*trans)(double,double),double TheS,double TheT){
        full_func::PrintPolFunc(PolFunc,trans,TheS,TheT);
    }

    typedef double (*MathFunc)(double);
    typedef void   (*Procedure)();

    Procedure PrintTwoHeart = full_func::_th2;
    //though put a complex function here is not allowed in this namespace style,
    //I would like to put my function "_th2" here for you, my old friend FYF.
    //- GGN 2018.1.27     I'm so capricious as this.
}

namespace value_func{
    typedef print_func::MathFunc MathFunc;

    int& X_BASE   = full_func::X_BASE;
    int& Y_BASE   = full_func::Y_BASE;
    int& LEN_BASE = full_func::LEN_BASE;

    POINT trans(double x, double y){return full_func::trans(x,y);}
    POINT itrans(double x,double y){return full_func::_trans(x,y);}

    double& HeartT=full_func::HeartT;
    MathFunc Heart  = full_func::Heart;
    MathFunc Id     = full_func::_id;
    MathFunc Uno    = full_func::__id;

    double& CirR = full_func::CirR;
    double& CirX = full_func::CirX;
    double& CirY = full_func::CirY;

    MathFunc Cir    = full_func::Cir;
    MathFunc iCir   = full_func::_Cir;
    MathFunc NormHeart = full_func::_Heart;
}

//program start here...
int main(){
    print_func::Pause();
    print_func::PrintTwoHeart();
    return 0;
}

你可能感兴趣的:(其他,Windows,API,画图软件)