派生Cbutton控件重载drawitem时会用到 lpDrawItemStruct这个结构体,而这个结构体中的rcitem与通过getclientrect取得的客户区域的大小却并不相同,这样我很困惑
1、我清楚combobox的item代表着不同的选项,为什么Cbutton也有这个lpDrawItemStruct->rcitem
呢?lpDrawItemStruct->rcitem究竟指的是哪个区域?
2、如果在某个函数中我要用到这个lpDrawItemStruct->rcitem值,我又该如何获得呢?困惑,望高手帮忙,感谢!
1、我清楚combobox的item代表着不同的选项,为什么Cbutton也有这个lpDrawItemStruct->rcitem
呢?lpDrawItemStruct->rcitem究竟指的是哪个区域?
2、如果在某个函数中我要用到这个lpDrawItemStruct->rcitem值,我又该如何获得呢?困惑,望高手帮忙,感谢!
getwindowrect 和getclientrect取得的数据一样,但跟lpDrawItemStruct->rcitem
却不同anyway, thanks all the same
getwindowrect返回的是window坐标
DrawItemStruct是0,0起始坐标
老师你好,可以而把源码发一份给我嘛,我邮箱:[email protected]
顺便请教一个问题:windows消息太多,我已经被折磨快疯了就事论事, 楼主想自绘按钮, 有这么几个消息共楼主选择:wm_ctlcolorwm_paint以上是sdk的
mfc的话,又会多一个虚函数DrawItem(并非wm_drawitem)绘制控件,顾名思义,用wm_ctlcolor
为什么你要用wm_drawtiem呢?
#include <windows.h>
#include <stdio.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("test buttons") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, TEXT ("button"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
200, 200,
NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndButton;
switch (message)
{
case WM_CREATE:
hwndButton=CreateWindow(TEXT("button"),TEXT("test"),
WS_CHILD | WS_VISIBLE|BS_OWNERDRAW,30,30,50,30,hwnd,0,
((LPCREATESTRUCT) lParam)->hInstance, NULL);
return 0;
case WM_DRAWITEM :
{
LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) lParam;
char str[100];
sprintf(str,"%d,%d,%d,%d",lpdis->rcItem.left,lpdis->rcItem.top,
lpdis->rcItem.right,lpdis->rcItem.bottom);
MessageBox(NULL,str,"rect",MB_OK);
RECT rect;
GetWindowRect(hwndButton,&rect);
sprintf(str,"%d,%d,%d,%d",rect.left,rect.top,
rect.right,rect.bottom);
MessageBox(NULL,str,"rect",MB_OK);
}
break;
case WM_PAINT:
break;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}