如何使用Mouse Down事件在C ++中绘制

时间:2012-12-29 20:15:30

标签: c++ drawing mouseevent paint

我想用鼠标绘制一些像素,我想用C ++做,就像在Paint中一样,但到目前为止,我无法让它工作。

我做了什么:

// NewPaint.cpp : main project file.
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <conio.h>
#include <dos.h>
#include <Winuser.h>

int main()
{
    SetConsoleTitle(L"PaintER"); // Set text of the console so you can find the window
    HWND hWnd = GetConsoleWindow(); // Get the HWND
    HDC hdc = GetDC(hWnd); // Get the DC from that HWND
    textbackgroundcolor(WHITE); // Background color
    textcolor(BLACK); // Text color
    POINT p; // Pointer
    while(1) // Smt like  mouse button 1 
    {
        if (ScreenToClient(hWnd, &p)) // Mouse position
        {
            SetPixel(hdc, p.x, p.y, RGB(0,0,0)); // Draw black pixels
        }
    }
    ReleaseDC(hWnd, hdc); // Release the DC
    DeleteDC(hdc); // Delete the DC
    system("pause");
    return 0;
}

我正在使用Visual Studio 2010并使用Windows 7.我听说这些可能是重要信息..

我没有我只有GDI +参考文献,所以如果您知道如何使用它,请告诉我。

我需要编码示例和解释,就像我在代码中给出的那样。

0 个答案:

没有答案