简体   繁体   English

C ++ WINAPI-绘制无边界的ListView

[英]C++ WINAPI - Draw ListView without borders

I'm having a little trouble. 我有点麻烦

For parent window I used dimensions 920x570. 对于父窗口,我使用了920x570尺寸。 For ListView 900x500. 对于ListView 900x500。

Viewing at this dimensions, one would say there are quite some borders, however it is not like that in reality. 从这个角度看,人们会说有很多边界,但实际上并非如此。 If I use exactly the same dimensions I get quite a big part of ListView cuted off. 如果使用完全相同的尺寸,则会截断ListView的很大一部分。 Well I could try to find exact values which will give me "borderless" ListView, but even when I do so thing is slightly different in Windows XP (we are talking about 5-10 pixels). 好吧,我可以尝试找到确切的值,这些值将为我提供“无边界”的ListView,但是即使这样做,Windows XP中的情况还是有些不同(我们谈论的是5-10像素)。

Is there right way to draw ListView "borderless" natively to work on all platforms? 有没有正确的方法来本地绘制ListView以在所有平台上正常工作?

They say picture is worth a thousands of words... so here it goes 他们说图片值得一千个字...就这样

Picture 图片

You have to distinguish between window size and client size. 您必须区分窗口大小和客户端大小。 If your parent window is 920x570, then these are its outer dimensions. 如果您的父窗口是920x570,则这些是其外部尺寸。 Client area is smaller and that's what you need to set your listview's dimension to to make it fit nicely in the entire area. 客户区域较小,这就是您需要设置列表视图的尺寸以使其完全适合整个区域的原因。

Have a look at GetClientRect function. 看看GetClientRect函数。 You need to set ListView's dimensions to those you get using this funcion. 您需要将ListView的尺寸设置为使用此功能获得的尺寸。

EDIT 编辑

Your code could look as follows 您的代码可能如下所示

HWND outerWnd = CreateWindowEx(...);
RECT clientRect;
GetClientRect(outerWnd, &clientRect);
HWND listView = CreateWindowEx(..., WC_LISTVIEW, "", WS_CHILD|..., 0, 0, clientRect.right, clientRect.bottom, outerWnd, NULL, hInstance, NULL);

With GetClientRect , right and bottom members of RECT struct are width and height of the window, respectively. 使用GetClientRect ,RECT结构的右成员和下成员分别是窗口的宽度和高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM