简体   繁体   English

C ++ WM_NCCALCSIZE未发送

[英]C++ WM_NCCALCSIZE not being sent

I'm trying to center the text in a edit control vertically, after some research I found I have to process the WM_NCCALCSIZE message. 经过一番研究,我发现我必须处理WM_NCCALCSIZE消息,因此尝试将文本垂直放置在编辑控件中。 So i've subclassed my edit control, but the WM_NCCALCSIZE message is never sent. 因此,我已经将我的编辑控件子类化了,但是WM_NCCALCSIZE消息从未发送过。

Am I doing something wrong? 难道我做错了什么?

EDIT: 编辑:

So i'm processing the WM_NCCALCSIZE message fine, and I have a 3d border created by passing WS_EX_CLIENTEDGE to CreateWindowEx . 因此,我正在正常处理WM_NCCALCSIZE消息,并且通过将WS_EX_CLIENTEDGE传递给CreateWindowEx创建了3d边框。 But if I disable windows themes by killing the theme service, the border goes away on the control thats processing the WM_NCCALCSIZE message. 但是,如果我通过终止主题服务来禁用Windows主题,则处理WM_NCCALCSIZE消息的控件上的边框会消失。 Another control that doesnt process the WM_NCCALCSIZE message still has the border like normal. 另一个不处理WM_NCCALCSIZE消息的WM_NCCALCSIZE仍然具有正常边框。

So i'm assuming I'm supposed to be doing somethign in WM_NCCALCSIZE that allows me to keep the border? 所以我假设我应该在WM_NCCALCSIZE中WM_NCCALCSIZE什么使我能够保持边界? If so what? 如果可以的话? if not any way to get the border back? 如果没有任何办法使边界恢复原状?

Instead of tinkering with WM_NCCALCSIZE (a very difficult message to manage), why not just reposition your edit control vertically so that the text is at the vertical position you prefer? 而不是修改WM_NCCALCSIZE (这是一条很难管理的消息),为什么不直接将编辑控件垂直放置,以使文本位于您希望的垂直位置? You can put it inside a white box to provide the white space around it. 您可以将其放在白色框中,以提供周围的空白。 Alternatively, you can use EM_SETRECT to put the text exactly where you want it. 或者,您可以使用EM_SETRECT将文本准确地放置在所需的位置。

Figured it out, WM_NCCALCSIZE is sent before the edit control is subclassed. 弄清楚了,在子类化编辑控件之前发送WM_NCCALCSIZE
So i had to superclass the EDIT class. 所以我不得不超类EDIT类。

EDIT: 编辑:
Another solution I just thought of would be to subclass it, then call SetWindowPos with SWP_FRAMECHANGED , this causes it to send the WM_NCCALCSIZE message. 我刚刚想到的另一个解决方案是将其子类化,然后使用SWP_FRAMECHANGED调用SetWindowPos ,这将导致它发送WM_NCCALCSIZE消息。

If anyone has any opinions why one method would be better then the other, please comment :) 如果有人对为什么一种方法优于另一种方法有任何意见,请评论:)

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

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