简体   繁体   English

C ++ Win32在按钮上无法对齐文本

[英]C++ Win32 Having Trouble Aligning Text on a Pushbutton

This should be fairly simple, but I cannot for the life of me figure out why its not working. 这应该很简单,但是我无法一生找出它为什么不起作用的原因。 I did a lot of googling and MSDN and couldn't find anything more useful. 我做了很多谷歌搜索和MSDN,找不到更多有用的东西。

    SendMessage(GetDlgItem(hwnd, IDC_ANCIENT), BM_SETSTYLE, (WPARAM)(BS_LEFTTEXT), (LPARAM)TRUE);
    Button_SetStyle(GetDlgItem(hwnd, IDC_ANCIENT), BS_LEFTTEXT, TRUE);

That's what I have. 那就是我所拥有的。 The parameters are right, I tested the style BS_3STATE, and it worked. 参数正确,我测试了BS_3STATE样式,并且该样式有效。 I have it set to redraw. 我准备重绘。 I have those lines within the WM_INITDIALOG message of the dialog. 我在对话框的WM_INITDIALOG消息中包含这些行。

The dialog and everything on it is contained in my resource files. 该对话框及其上的所有内容都包含在我的资源文件中。

Any ideas? 有任何想法吗?

Thanks. 谢谢。

http://imageshack.us/a/img153/6594/rydv.jpg http://imageshack.us/a/img153/6594/rydv.jpg

The BS_LEFTTEXT doesn't work for buttons. BS_LEFTTEXT对按钮不起作用。 From MSDN (emphasis added): MSDN (添加重点):

BS_LEFTTEXT Places text on the left side of the radio button or check box when combined with a radio button or check box style . BS_LEFTTEXT 与单选按钮或复选框样式结合使用时 ,在单选按钮或复选框的左侧放置文本。 Same as the BS_RIGHTBUTTON style. 与BS_RIGHTBUTTON样式相同。

For what you want you probably need to do an owner-draw control. 对于您想要的内容,您可能需要执行所有者绘制控件。 Check out the BS_OWNERDRAW style on that same link. 在同一链接上查看BS_OWNERDRAW样式。

I downloaded a resource file editor and found the solution. 我下载了一个资源文件编辑器,并找到了解决方案。

           DEFPUSHBUTTON      "Ancient Crystal [Click]",IDC_ANCIENT,15,292,140,12, BS_LEFT 

If you put the BS_LEFT style in the resource file it will align the text left. 如果将BS_LEFT样式放在资源文件中,它将使文本左对齐。

EDIT: Final Note I was trying to change the font alignnment within a Procedure that did not have the proper handle to the dialog. 编辑:最后的说明,我试图在没有适当对话框对话框的过程中更改字体对齐方式。 I was handing the procedure the handle to the main window. 我把程序的句柄交给了主窗口。

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

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