- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当使用 win32 api 调整大小时,我想将 ListView 中的标题宽度设置为其 ListView 控件的宽度。所以我使用 ListView_SetColumnWidth()
将其宽度设置为其控件的宽度宽度,但它不起作用。
这是 WinMain()
中的代码:
InitCommonControls();
hwndList1 = CreateWindow(WC_LISTVIEW , L"" , WS_VISIBLE | WS_CHILD | LVS_REPORT | WS_BORDER | WS_VSCROLL, 10 , 10 , width , height, hwnd, NULL, GetModuleHandle(NULL), 0);
//Sub classing the list control
SetWindowSubclass(hwndList1 ,ListProc,0 ,NULL);
SendMessage(hwndList1,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT,LVS_EX_FULLROWSELECT);
hHeader1=ListView_GetHeader(hwndList1);
GetClientRect(hwndList1 , &rect1);
CreateColumn(hwndList1 , 0 , (char*)L"MASTER" , rect1.right );
//enable arrows
EnableScrollBar(hwndList1 , SB_VERT , ESB_ENABLE_BOTH);
//scroll down
SendMessage(hwndList1, WM_VSCROLL, SB_BOTTOM, 0L);
这是ListProc()
:
//the list proc
LRESULT CALLBACK ListProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,UINT_PTR, DWORD_PTR ){
switch(msg)
{
case WM_NOTIFY :
if (((LPNMHDR) lp)->code == NM_CUSTOMDRAW)
{
LPNMCUSTOMDRAW lpcd = (LPNMCUSTOMDRAW)lp;
switch(lpcd->dwDrawStage)
{
case CDDS_PREPAINT :
return CDRF_NOTIFYITEMDRAW;
case CDDS_ITEMPREPAINT:
{
SetBkColor(lpcd->hdc, RGB(0, 135, 234));
SetTextColor(lpcd->hdc, RGB(255, 255, 245));
return CDRF_NEWFONT;
}
break;
}
}
break;
case WM_NCPAINT:
{
RECT rc;
GetWindowRect(hwnd, &rc);
OffsetRect(&rc, -rc.left, -rc.top);
auto hdc = GetWindowDC(hwnd);
auto hpen = CreatePen(PS_SOLID, 1, RGB(201, 201, 201));
auto oldpen = SelectObject(hdc, hpen);
SelectObject(hdc, GetStockObject(NULL_BRUSH));
Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
SelectObject(hdc, oldpen);
DeleteObject(oldpen);
ReleaseDC(hwnd, hdc);
return 0;
}
case WM_NCDESTROY:
RemoveWindowSubclass(hwnd, ListProc, 0);
break;
}
return DefSubclassProc(hwnd, msg, wp, lp);
}
下面的代码是父窗口过程的WndProc()
:
//The window procedure
LRESULT CALLBACK WndProc( HWND hwnd , UINT msg , WPARAM wParam , LPARAM lParam){
switch(msg){
case WM_SIZE:{
int nHeight , nWidth;
width =(int)((nWidth /2) * 0.8);
height =(int)((nHeight/2) * 0.7);
if( wParam == SIZE_RESTORED ){
SetWindowPos(hwndList1, 0 , 10, 10 , width, height,SWP_NOZORDER|SWP_NOMOVE);
RECT Rc;
GetClientRect(hwndList1, &Rc);
ListView_SetColumnWidth(hwndList1, 0, Rc.right - Rc.left);
}
else if ( wParam == SIZE_MAXIMIZED )
{
SetWindowPos(hwndList1, 0 , 20, 20, width, height,0);
RECT Rc;
GetClientRect(hwndList1, &Rc);
ListView_SetColumnWidth(hwndList1, 0, Rc.right - Rc.left);//
}
}
break;
case WM_NOTIFY:
if(((LPNMHDR)lParam)->code == NM_CUSTOMDRAW) {
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
switch(lplvcd->nmcd.dwDrawStage) {
case CDDS_PREPAINT:
return CDRF_NOTIFYITEMDRAW;
case CDDS_ITEMPREPAINT:
if (((int)lplvcd->nmcd.dwItemSpec%2)==0) {
lplvcd->clrText = RGB(0,0,0);
lplvcd->clrTextBk = RGB(255, 255, 255);
} else {
lplvcd->clrText = RGB(0,0,0);
lplvcd->clrTextBk = RGB(255,255,255);
}
return CDRF_NEWFONT;
}
}
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)){
case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE , 0 , 0);
break;
case ID_ABOUT:
{
int ret=DialogBox( GetModuleHandle(NULL) , MAKEINTRESOURCE(ID_ABOUT) , hwnd , AboutDlgProc );
}
break;
}
break;
case WM_CLOSE:
DestroyWindow( hwnd );
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc( hwnd , msg , wParam , lParam );
}
return 0;
}
我错过了什么?还有其他方法吗?
谢谢!
最佳答案
使用 GetClientRect
找到控件的内部矩形。示例:
case WM_SIZE:
{
//resize the listview control first
//calculate width/height
SetWindowPos(hwndList1, NULL, 0, 0, width, height, SWP_NOZORDER|SWP_NOMOVE);
RECT rc;
GetClientRect(hwndList1, &rc);
ListView_SetColumnWidth(hwndList1, 0, rc.right - rc.left);//rc.left is zero
break;
}
客户端矩形可以比窗口矩形小一点。
您可以使用宽度/高度通过 SetWindowPos
或 MoveWindow
设置 ListView 控件的大小。这将对应于 GetWindowRect
。但是您想要列宽的客户端矩形。
您还可以子类化 listview 控件并响应 listview_proc
中的 WM_SIZE
。
WM_SIZE
在用户调整主窗口大小时发送。窗口首次打开时默认不触发。首次初始化窗口时,您可能必须调用 ListView_SetColumnWidth
。
ListProc
中处理自定义绘制。您必须从
ListProc
中删除
WM_NOTIFY
部分,仅将其添加到
WndProc
。
建议修改:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_SIZE:
{
int nWidth = LOWORD(lParam);
int nHeight = HIWORD(lParam);
int width = (int)((nWidth / 2) * 0.8);
int height = (int)((nHeight / 2) * 0.7);
SetWindowPos(hwndList1, 0, 20, 20, width, height, SWP_NOZORDER);
RECT rc;
GetClientRect(hwndList1, &rc);
ListView_SetColumnWidth(hwndList1, 0, rc.right - rc.left);
}
break;
case WM_NOTIFY:
if(((LPNMHDR)lParam)->code == NM_CUSTOMDRAW)
{
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
return CDRF_NOTIFYITEMDRAW;
case CDDS_ITEMPREPAINT:
lplvcd->clrText = RGB(255, 0, 0);
lplvcd->clrTextBk = RGB(255, 255, 0);
return CDRF_NEWFONT;
}
}
break;
...
}
关于c++ - 调整 ListView 大小时如何将标题宽度设置为其 ListView 控件宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57645381/
我附上了一个我尝试使用 html/css 实现的示例(如果您看不到图像:名字和姓氏,然后第二行是职位描述)。我希望所有文本(两行)在一个 div 中强制对齐(左和右),但我不确定这是否可能。我尝试了一
我想使两个 h1 元素成为 div 上的标题/页眉。所以每个都在特定的 div 之上。 Youtube Achievements
我想让每个 EditText 对象都有自己的标题,就像 Pure Android 指南中那样 (screenshot) 这个东西有原生支持吗?我想他们也可能会使用带有部分的 ListView ,但这对
是否可以像 UITableView headerView 一样创建 UICollectionView 标题 View ?我的意思是整个集合 View 的标题 View ,而不是每个部分的重复 View
我一直在遵循有关排版的 Google 官方 Material 设计指南 (http://www.google.com/design/spec/style/typography.html),但我发现它们
我目前正在尝试找到可以帮助我从视频文件中提取元数据或信息的 python 库,例如 [ mp4, Mkv, Avi, WebM, mpg ] 格式为例。 我主要从视频文件中提取的主要数据是 [标题、描
你好, 这是我正在尝试做的: 将每个缩略图的内容(img + 标题)居中。我的 img 必须是 span3,标题必须是 span4。 这是我的问题: 我可以获取内容中心,或者标题 float 在 im
我有一个带有导航栏的应用程序,可以从一个 View Controller 导航到下一个 View Controller 。在某些模拟器和设备上导航到下一个 View Controller 时,后退按钮
我遇到了一些非常酷的 t-sql,可以从一个 t-sql 查询中的选定行生成一个逗号分隔的列值列表: SELECT @MyList = ISNULL(@MyList,'') + Title + ',
请确保将 HTML heading 标签只用于标题。不要仅仅是为了生成粗体或的文本而使用标题。 搜索引擎使用标题为您的网页的结构和内容编制索引。 因为用户可以通过标题来快速浏览您的网页,所以用标
我正在使用 wkhtmltopdf 将 html 转换为 pdf。 我想在每个页面中添加标题,但它只显示在第一页(目录)中。 我使用的命令是 "C:\Program Files\wkhtmltopdf
如何使用 ggplot2 显示观察的方向(标题)?有没有办法调整shape=17 (三角形)以便它“指向”下一次观察? 示例代码 library(ggplot2) dat % pivot_wide
我尝试在 cocoa 应用程序中显示/隐藏标题栏。我使用以下代码: if ([window styleMask]==NSResizableWindowMask) { [wind
我有这样的 HTML 标题 http://s1.postimg.org/4ebyk3qwv/image.png 当我编写这段代码时: document.getElementById("TL85_1_
我叫麦克。谢谢你的帮助。 在Wordpress中,我们已经设计了我们的网站,以便在Facebook调试器中og数据尽可能接近youtube。尽管如此,在Facebook上共享视频的方式还是不同的。尽管
从 web 应用程序的客户端,我点击了服务器端路由,它只是第三方 API 的包装器。使用分派(dispatch),我试图让服务器端请求返回 exact header 和第三方 API 对客户端 AJA
从 web 应用程序的客户端,我点击了服务器端路由,它只是第三方 API 的包装器。使用分派(dispatch),我试图让服务器端请求返回 exact header 和第三方 API 对客户端 AJA
我是 SAPUI5 的新手,在导航、侧边栏和标题方面遇到一些问题。我想开发一个带有标题和侧边栏的应用程序。我为此使用“ToolPage”。每个页面都包含工具页,如下所示:
我最近在为客户做的项目中被介绍给Go。他们已经建立了代码库,需要进行一些更改。 我注意到所有的方法,结构等等都有一些奇怪的类似于标题的注释,如下所示: // SomeType ... type Som
我创建了一个采用整个屏幕布局的标题布局(xml 文件)... 我还创建了一个 listView 并将此 header_layout 添加到 listView 中: LayoutInflater inf
我是一名优秀的程序员,十分优秀!