C ++绘制像素问题 [英] C++ drawing pixels question

查看:274
本文介绍了C ++绘制像素问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何使窗口,或更像剪切区域,我将能够绘制像素?
它可能使用WinApi,但我不想让我的项目看起来像winapi一样,所以它会有


How to make window, or more like clipping region , where I'll be able to draw pixels? It might use WinApi, however I don't want my project to look like winapi one, so it will have

int main(){}

而不是

int WINAPI WinMain(HINSTANCE ...

找到了一个例子,我可以在控制台窗口中绘制

I have found an example, where I'm able to draw in console window

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

    for( int i = 0 ; i < 50 ; i++ )
    {
    SetPixel(hdc, 5+i, 12, color); // SetPixel(HDC hdc, int x, int y, COLORREF color)
    }
        ReleaseDC(hwnd, hdc); // Release the DC
    DeleteDC(hdc); // Delete the DC
    system("pause");
    return(0);
}

但是我想在我选择的区域绘制,保持焦点(当用户点击它时,等等)。

but instead of console, I want to draw on my selected region, which will hold focus ( when user clicks on it, etc ).

这将是很好的能够处理简单的键盘/鼠标事件这个程序,

It would be also great to be able to handle simple keyboard/mouse events for this program, but it isn't my primary target here, maybe some other third party libraries will help with it.

我希望我已经清楚地解释了我想做什么,但是英语不是我的主要目标我的母语,所以我很抱歉任何误会。

I hope I've explained clearly what I want to do, but English isn't my native language, so I'm very sorry for any missunderstandings.

我将非常感谢任何帮助。

I will be thankfull for any help.

由于我第一次使用此网站,对于垃圾邮件或邮件在错误的地方,我不知道在哪里发布我的下一条消息:-)
所以我想写,是:

As I'm using this site first time, I'm sorry for little spam or messages in wrong places, as I'm not sure where to post my next messages :-) So what i wanted to write, is:


否则,如何是否Allegro / SDL创建窗口?他们使用汇编器调用或shell?我会更快乐,当我能够从头创建窗口,无论它需要多少工作:)

" Otherwise, how does Allegro/SDL create window? They use assembler calls or shell ones? I'll be much happier, when I'll be able to create window from scratch, no matter how much work does it take :) "

推荐答案

你不会喜欢这个 - 在Windows中,你必须创建一个窗口,然后覆盖WM_PAINT消息,当你从系统中调用时必须绘制。

You won't like this - in Windows, you have to create a window, then override WM_PAINT message, then draw what you have to draw when you are called from the system. That's old-school way of doing things, and it isn't so bad.

一些有趣的相关链接:

http://www.winprog.org/tutorial/bitmaps.html

http://www.codeproject.com/Articles/66250/BeginPaint-EndPaint-or-GetDC-ReleaseDC.aspx

如果你真的进入避免所有这些,请尝试 popcap 。学习曲线涉及的可能更陡峭,所以你可能真的想坚持使用GDI和HWND,无论它多么困难和困惑它可能看起来在开始。

If you are really into avoiding all that, try popcap. Learning curve involved there maybe steeper, so you probably really want to stick with GDI and HWND no matter how hard and confusing it might look in the beginning.

这篇关于C ++绘制像素问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆