简体   繁体   中英

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.

    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. I have it set to redraw. I have those lines within the WM_INITDIALOG message of the dialog.

The dialog and everything on it is contained in my resource files.

Any ideas?

Thanks.

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

The BS_LEFTTEXT doesn't work for buttons. From MSDN (emphasis added):

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 . Same as the BS_RIGHTBUTTON style.

For what you want you probably need to do an owner-draw control. Check out the BS_OWNERDRAW style on that same link.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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