我有以下代码在整个表单上绘制线条:
/* Create GridLines */
bool CreateGridLines()
{
RECT rcTabControl;
GetWindowRect(hwndTabControl, &rcTabControl);
app_scale_x = (float)((rcTabControl.right - rcTabControl.left) / 96.0);
app_scale_y = (float)((rcTabControl.bottom - rcTabControl.top) / 96.0);
/* Get desktop DPI.
HDC screen = GetDC(0);
app_scale_x = (float)(GetDeviceCaps(screen, LOGPIXELSX) / 96.0);
app_scale_y = (float)(GetDeviceCaps(screen, LOGPIXELSX) / 96.0);
ReleaseDC(0, screen);*/
d3d_object = Direct3DCreate9(D3D_SDK_VERSION);
/* Fill out the presentation parameters for the D3D device... windowed mode. */
D3DPRESENT_PARAMETERS present;
fill_out_present(&present, hwnd);
UINT AdapterToUse = D3DADAPTER_DEFAULT;
D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
d3d_object->CreateDevice(AdapterToUse, DeviceType, hwnd,
D3DCREATE_FPU_PRESERVE | D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&present, &d3d_device);
if (!d3d_device) return false;
return true;
}
问题是如何在面板索引0中绘制这条线?我从以下网址获得了这个源代码脚本:
http://braid-game.com/news/wp-content/uploads/2009/01/proof.cpp
我定义并初始化了这样的面板:
HWND hwndTabControl;
/* CreateTabControl */
HWND CreateTabControl(HWND hwndParent)
{
RECT rcClient;
INITCOMMONCONTROLSEX icex;
HBITMAP bmpMain;
HIMAGELIST hwndImageList;
TCITEM tie;
/* Initialize common controls */
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icex);
/* Create a TabControl of child window size */
GetClientRect(hwndParent, &rcClient);
hwndTabControl = CreateWindowEx (
0,
WC_TABCONTROL,
"",
WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
0, 0, rcClient.right, rcClient.bottom,
hwndParent, NULL, hInstance, NULL);
if (hwndTabControl == NULL)
{
return NULL;
};
/* Create ImageList */
hwndImageList = ImageList_Create(12, 9, ILC_COLOR24 | ILC_MASK, 0, 1);
bmpMain =(HBITMAP) LoadImage(NULL, "0.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
ImageList_AddMasked(hwndImageList, bmpMain, RGB(255, 255, 255));
/* Add Tabs to panel */
tie.mask = TCIF_TEXT | TCIF_IMAGE;
tie.iImage = 0;
tie.pszText = "Untitled";
if ((TabCtrl_InsertItem(hwndTabControl, 0, &tie) == -1) || (TabCtrl_SetImageList(hwndTabControl, hwndImageList)))
{
DestroyWindow(hwndTabControl);
return NULL;
}
/* PanelTab Default font */
SendMessage(hwndTabControl, WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(1,0));
return hwndTabControl;
}
我刚改变了:
fill_out_present(&present, hwnd);
到
fill_out_present(&present, hwndTabControl);
但是网格是在整个表单窗口上绘制的......我希望它在面板选项卡索引0中...我想我需要在哪些行需要绘制索引...我在左边得到这个我需要在正确的图片上得到这个。
答案 0 :(得分:0)
在对宽度/高度和线起点/终点进行计算之前,使用TabCtrl_AdjustRect将客户矩形调整为实际显示区域:
RECT rc;
GetClientRect(hwndTabControl, &rc); // rc will be set to the client area of the tab control
TabCtrl_AdjustRect(hwndTabControl, FALSE, &rc); // rc will be adjusted to the actual display area of the tab control
当前,选项卡控件的客户端矩形从0,0开始,而您实际上希望它从实际显示区域开始的偏移处开始。这就是你在整个表格上画画的原因。