使用visualc++在桌面上绘制
draw on desktop using visual c++
我正在编写一个opencv应用程序,使用visual studio vc++控制台应用程序绘制激光束。我想在桌面上画直线。我知道绘图功能在GDI32.dll中可用,但对如何将GDI32.dll与我的vc代码集成感到困惑。你能提出一些好的解决办法吗?
下面的代码在桌面上绘制一个蓝色矩形。
#include <iostream>
#include <Windows.h>
int main() {
/* hide console window */
ShowWindow(FindWindowA("ConsoleWindowClass", NULL), false);
/* Calling GetDC with argument 0 retrieves the desktop's DC */
HDC hDC_Desktop = GetDC(0);
/* Draw a simple blue rectangle on the desktop */
RECT rect = { 20, 20, 200, 200 };
HBRUSH blueBrush=CreateSolidBrush(RGB(0,0,255));
FillRect(hDC_Desktop, &rect, blueBrush);
Sleep(10);
return 0;
}
只是为了好玩。直接在桌面上绘制的曼德布洛特分形。
#define MAGNITUDE_CUTOFF 100
#define NUMCOLOURS 256
#define WIDTH 640
#define HEIGHT 200
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define SPACE 32
#define ENTER 13
#define ESCAPE 27
#define TAB 9
#define INSERT 82
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <iostream>
using namespace std;
int col(int x, int y);
void fract(void);
char op;
int ch,max_iterations;
double xmin = -2.10, xmax = 0.85, ymin = -1.5 , ymax = 1.5;
double width_fact, height_fact;
int main(){
COLORREF color = RGB(255,0,0); // COLORREF to hold the color info
SetConsoleTitle("Pixel In Console!"); // Set text of the console so you can find the window
HWND hwnd = FindWindow(NULL, "Pixel In Console?"); // Get the HWND
HDC hdc = GetDC(hwnd); // Get the DC from that HWND
width_fact = (xmax-xmin)/WIDTH;
height_fact = (ymax-ymin)/HEIGHT;
for( int x = 0 ; x < 640 ; x++ ){
for (int y = 0;y < 480; y++ ){
int blue = (col(x,y) & 0x0f) << 4;
int green = (col(x,y) & 0xf0) << 0;
int red = (col(x,y) & 0xf00) >> 4;
SetPixel(hdc, x,y, RGB(red,green,blue));
}
}
system("pause");
ReleaseDC(hwnd, hdc); // Release the DC
DeleteDC(hdc); // Delete the DC
return(0);
}
void fract(){
int x,y,icount=0;
width_fact = (xmax-xmin)/WIDTH;
height_fact = (ymax-ymin)/HEIGHT;
for (y=0;y<HEIGHT;y++){
for (x=0;x<WIDTH;x++){
// setcolor(col(x,y));
// gotoxy(x+3,y+3);printf("Û");
}
}
//setcolor(15);
}
int col( int x, int y){
int n,icount=0;
float p,q,r,i,prev_r,prev_i;
p= (( (float)x ) * width_fact) + (float)xmin;
q= (( (float)y ) * height_fact) +(float)ymin;
prev_i = 0;
prev_r = 0;
for (n=0; n <= NUMCOLOURS; n++){
r = (prev_r * prev_r) - (prev_i * prev_i) +p;
i = 2 * (prev_r * prev_i) +q;
if (( r*r + i*i) < MAGNITUDE_CUTOFF ){
prev_r = r;
prev_i = i;
}
else {
return n;
}
}
return n;
}
相关文章:
- 试图在visual studio上用C++创建一个桌面应用程序
- QuadTree只在窗口的右上角绘制
- 绘制旋转的三角形
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 如何在QT中的自定义视频小工具t上绘制矩形
- 如何在Visual Basic中使用矩形函数OpenGL绘制矩形
- 无法使用VAO和EBO(openGL)绘制多个对象
- 为什么我的点没有在 OpenGL 中绘制鼠标所在的位置?
- 绘制顺时针三角形,重新排序点
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- SFML 文本未绘制在窗口上
- 如何在桌面C++上使用 WinApi 画线
- 如何在快板的屏幕中显示子位图的绘制?
- Linux绘制文本模式(无GUI,桌面)
- FreeGrot(类似于OpenGL)正在拍摄我的桌面而不是绘制形状
- 如何使用 GDI API 在 Windows 桌面上绘制
- Gdiplus DrawString 在远程桌面上绘制透明文本
- 通过注入绘制到桌面
- 使用visualc++在桌面上绘制
- 在(桌面)屏幕上绘制变形对象