使用GDI或控件填充矩形区域的简单方法 [英] simple way to fill a rectangular area either using GDI or controls

查看:338
本文介绍了使用GDI或控件填充矩形区域的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用鼠标移动获得鼠标下方的像素颜色,并希望使用gdi将该颜色填充为静态控件背景颜色或矩形。



我不是常规的win32程序员。



我搜索并获得其他来源的所有回复以使用消息WM_CTLCOLOREDIT。



但是我的情况是动态的。



我刚试过以下但是没有用......



 HWND hwnd,cbox; 
COLORREF cboxcolor;

cbox = CreateWindow( STATIC ds,WS_CHILD | WS_VISIBLE, 10 50 50 50 ,hwnd, 0 ,GetModuleHandle( 0 ), 0 );

cboxhdc = GetDC(cbox);
cboxcolor = RGB( 255 2 255 );
SetBkColor(cboxhdc,cboxcolor);





当我检查GD功能时,我认为需要创建画笔..那么多......

太多的线条认为设置颜色应该简单直接而不是懒得去做。但是...它有太多的选择...



因此想到使用ExtTextOut ......还没有使用它。



想要确定哪条路可走?



以下哪一项涉及的处理较少或因其他原因而有所好处.. 。



1.创建静态控件并在鼠标移动时更改背景颜色。如果可能的话

2.创建一个有界区域并填充颜色。我觉得很乏味。

3.使用ExtTextOut ...









过了一会儿,我找到了一个解决方案,回答了我自己的问题。如果有人想在这里添加更多或更正我的话请继续...

解决方案

在浏览网站和文档后我发现ExtTextOut是我提到的所有其他选项中最快的。



现在经过一些试验和错误后,我使用setbkcolor和settextcolor来处理exttextout。



我没想到setbkcolor和settextcolor的行为就像Borland的旧16bit C图形功能一样。



现在而不是使用像vb6.0着色静态控件的方式我使用ExtTextOut函数与ETO_OPAQUE应用背景颜色我需要的矩形。



我不知道上面的代码(在我的原始问题中)是否有效但下面的代码是否有效。



正如我在问题中所说的,我的需求是选择鼠标指针下方的颜色并填充矩形。所有我很困惑的是如何设置背景颜色,现在我明白了。这是...



<前lang =c ++> HDC hdc = GetDC(hwnd); // 主窗口的直流
SetTextColor(hdc,RGB( 0 200 200 ));
SetBkColor(hdc,RGB( 0 0 200 ));
ExtTextOut(hdc, 110 110 ,ETO_OPAQUE,& rect, hehehaha 8 0 );





它与setcolor相同,后跟setbkcolor,后跟Turbo C中的outtextxy ... hhhmmm ... phew ..不知何故忘记了旧式。 :)



如果有人想在这里纠正我的话请继续......


I wanted to get the pixel color beneath the mouse using mouse move and wanted to fill that color into a static controls background color or a rectangle using gdi.

I am not a regular win32 programmer.

I searched and got all the replies form others sources to use the message WM_CTLCOLOREDIT.

But my case is dynamic.

I just tried the following but it did not work...

HWND hwnd, cbox;
COLORREF cboxcolor;

cbox = CreateWindow("STATIC", "ds", WS_CHILD|WS_VISIBLE, 10, 50, 50, 50, hwnd, 0, GetModuleHandle(0), 0);

cboxhdc = GetDC(cbox);
cboxcolor = RGB(255,2,255);
SetBkColor(cboxhdc, cboxcolor);



and when i checked GD functions i assume that brushes needed to be created ... so and so...
that was too many lines thinking that setting a color should be simple and straight forward yet not lazy to do it. but... its like too many options...

So thought of using ExtTextOut... haven't used it.

Want to make sure which way to go?

Which one of the following involves less processing or good for what ever other reason...

1. Create a static control and change the background color on mouse move. if possible
2. Create a bounded area and fill color. which i feel tedious.
3. using ExtTextOut...

?


After a while i found a solution and had replied to my own question. if anybody would like to add more or correct me of anything here then please go on...

解决方案

After exploring websites and documentations i found that ExtTextOut is the fastest among all other options i had mentioned.

Now after few trial and errors i made the setbkcolor and settextcolor to work with exttextout.

I didn't assume the behavior of setbkcolor and settextcolor would be like the old 16bit C graphics functions from Borland.

Now instead of using like the vb6.0 way of coloring a static control i am using the ExtTextOut function with ETO_OPAQUE to apply a background color the the rectangle i needed.

I don't know whether the above code(in my original question) works or not but the following code worked.

As i had said in the question that my need is to pick the color beneath the mouse pointer and to fill a rectangle. all i was confusing was how to setbackground color and now i got it. here it is...

HDC hdc = GetDC(hwnd); //Main Window's dc
SetTextColor(hdc,RGB(0,200,200));
SetBkColor(hdc, RGB(0,0,200));
ExtTextOut(hdc,110,110,ETO_OPAQUE,&rect,"hehehaha",8,0);



it is the same like setcolor followed by setbkcolor followed by outtextxy in Turbo C. hhhmmm... phew... somehow forgot the old style. :)

If anybody would like to correct me of anything here then please go on...


这篇关于使用GDI或控件填充矩形区域的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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