我自己创建了一个画刷,比如是蓝色的,然后随便画了一条蓝色线段m1(50,60)m2(50,100),为什么我使用GetPixel(hdc,50,70)获取该线段上的颜色值本应是255,为什么却是4294967295。
部分代码如下:
hdc = GetDC(hwnd);
HPEN hpen = CreatePen(PS_SOLID,1,RGB(0,0,255));
HPEN old_hpen = (HPEN)SelectObject(hdc,hpen); // move to a postion
MoveToEx(hdc, 50,60, NULL); // draw a line
LineTo(hdc,50, 100);
COLORREF color1=GetPixel(hdc,50,70);//调试时得不到正确结果
// now delete the pen
SelectObject(hdc,old_hpen);
DeleteObject(hpen);
// release the device context
ReleaseDC(hwnd,hdc);
请问我应该怎样准确获得该线段上像素点的颜色值?多谢!
部分代码如下:
hdc = GetDC(hwnd);
HPEN hpen = CreatePen(PS_SOLID,1,RGB(0,0,255));
HPEN old_hpen = (HPEN)SelectObject(hdc,hpen); // move to a postion
MoveToEx(hdc, 50,60, NULL); // draw a line
LineTo(hdc,50, 100);
COLORREF color1=GetPixel(hdc,50,70);//调试时得不到正确结果
// now delete the pen
SelectObject(hdc,old_hpen);
DeleteObject(hpen);
// release the device context
ReleaseDC(hwnd,hdc);
请问我应该怎样准确获得该线段上像素点的颜色值?多谢!
解决方案 »
- 为何删除GetClientRect(&rect);就好用了呢
- 求助,想做一个类似dreamwaver里面的网页框架设计器
- CBN_SETFOCUS这个消息映射什么意思啊?
- 如何设置MessageBox()中按钮的确定,取消为英文的OK,CANCEL
- 多线程计时的问题
- WM_CREATE(及其他常用的消息)对应的UINT是几?
- 关于全局函数
- 怎样把View设成黑色?
- 600分 求IBM公司于94年4月推出的TCP/IP for DOS V2.1.1提供的开发软件包Programmer's Tool Kit
- 如何学习ActiveX scripting? 让我过一个好年把.
- (求助)怎么在对话框内显示sdi窗体内的组件的数据信息
- 求助:关于COM的2个问题
请问你的断点是设置在哪里的,尝试设置在SelectObject(hdc,old_hpen);这里试试,前面的断点都去掉。
2.是否需要lptodp?
我的断点是设在SelectObject(hdc,old_hpen),可是得到的color1的值却是4292967295,即0xffffffff。
bobob:
GetPixel()和LineTo()都使用逻辑坐标,就不需要转换了。
请大伙再帮我想一想,这是怎么回事,怎样解决?非常感谢!
Help!
// INCLUDES ///////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN // just say no to MFC
#include <windows.h> // include all the windows headers
#include <windowsx.h> // include useful macros
#include <stdio.h>
#include <stdlib.h>
// defines for windows
#define WINDOW_CLASS_NAME "WINCLASS1"
#define WINDOW_WIDTH 400
#define WINDOW_HEIGHT 300// GLOBALS ////////////////////////////////////////////////
HWND main_window_handle = NULL; // globally track main window
HINSTANCE hinstance_app = NULL; // globally track hinstance
// FUNCTIONS //////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
// this is the main message handler of the system
HDC hdc; // handle to a device context// what is the message
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
} break;
default:break;
} // end switch// process any messages that we didn't take care of
return (DefWindowProc(hwnd, msg, wparam, lparam));
} // end WinProc// WINMAIN ////////////////////////////////////////////////
int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{WNDCLASSEX winclass; // this will hold the class we create
HWND hwnd; // generic window handle
MSG msg; // generic message
//HDC hdc; // graphics device context// first fill in the window class stucture
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);// save hinstance in global
hinstance_app = hinstance;// register the window class
if (!RegisterClassEx(&winclass))
return(0);
// create the window
if (!(hwnd = CreateWindowEx(NULL, // extended style
WINDOW_CLASS_NAME, // class
"Drawing Line Demo", // title
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0, // initial x,y
WINDOW_WIDTH, // initial width
WINDOW_HEIGHT,// initial height
NULL, // handle to parent
NULL, // handle to menu
hinstance,// instance of this application
NULL))) // extra creation parms
return(0);// save main window handle
main_window_handle = hwnd;
while(GetMessage(&msg,NULL,0,0))
{
// translate any accelerator keys
TranslateMessage(&msg);
// send the message to the window proc
DispatchMessage(&msg);
// get the graphics device context
HDC hdc = GetDC(hwnd);
HPEN hpen = CreatePen(PS_SOLID,1,RGB(0,0,255));
HPEN old_hpen = (HPEN)SelectObject(hdc,hpen);
// move to a postion
MoveToEx(hdc, 50,60, NULL);
// draw a line
LineTo(hdc,50, 100);
COLORREF color1=GetPixel(hdc,50,70);//调试时得不到正确结果
// now delete the pen
SelectObject(hdc,old_hpen);
DeleteObject(hpen);
// release the device context
ReleaseDC(hwnd,hdc);} // end while
// return to Windows like this
return(msg.wParam);
} // end WinMain
红色 unsigned char red=0x00ff0000 & color1;
蓝色 unsigned char blue=0x0000ff00 & color1;
绿色 unsigned char green=0x000000ff & color1;
你那做法是获取颜色值的R、G、B分量。跟我的问题没关系。
Mackz:
我不放在WM_PAINT消息处理中一样可以绘制一条线段。问题不是出在绘制的地方 。
上面我给出了完整代码,好心人就帮我调试找找症结所在!