Today, I maked a video about rotate computer screen with C/C++, but I can not push my code in Bilibili, so I am pushing my code in here. Note:You should including “windows.h” and “math.h”, defining a constant called PI and its value is “acos(-1.0)”.
First : Upper-Left
First, the screen rotates around the vertex in the upper-left corner. Below is the code about rotating clockwise:
Fourth,the screen rotates around the vertex in the bottom-right corner. Below is the code about rotating clockwise:
1 2 3 4
POINT pos[3]; pos[0].x = w - (cos(a) * w - sin(a) * h), pos[0].y = h - (cos(a) * h + sin(a) * w); pos[1].x = w + (sin(a) * h), pos[1].y = h - (cos(a) * h); pos[2].x = w - (cos(a) * w), pos[2].y = h - (sin(a) * w);
Below is the code for counterclockwise rotation:
1 2 3 4
POINT pos[3]; pos[0].x = w - (cos(a) * w + sin(a) * h), pos[0].y = h - (cos(a) * h - sin(a) * w); pos[1].x = w - (sin(a) * h), pos[1].y = h - (cos(a) * h); pos[2].x = w - (cos(a) * w), pos[2].y = h + (sin(a) * w);
Usage
So how to use this code in our project? You should use the PlgBlt Function to draw the desired bitmap based on the coordinates:
1 2 3 4 5 6 7
HDC hdc = GetDC(0); int w = GetSystemMetrics(0), h = GetSystemMetrics(1); POINT pos[3]; //put you rotate coordinates code in here PlgBlt(hdc, pos, hdc, 0, 0, w, h, 0, 0, 0); ReleaseDC(0,hdc); DeleteObject(hdc);
Ending
So that’s it for today, I will push my code in this link, bye!