简体   繁体   中英

Adding Basic Text to Win32 App, c++

So i am making a tic tac toe game (I am a just barely beginning, and this is my first ever attempt to do anything windows), and i want to have a section where the game can keep score. I can't figure out how to add simple text to the window, like the word "SCORE" so i can put the score underneath it in a fancy little table. I have figured out how to make a text window using the following code:

    CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT("PLAYER 1"), WS_CHILD|WS_VISIBLE, 20,250,100,25,hWnd,HMENU(NULL),GetModuleHandle(NULL), NULL);
    CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT("PLAYER 2"), WS_CHILD|WS_VISIBLE, 130,250,100,25,hWnd,HMENU(NULL),GetModuleHandle(NULL), NULL);

That is useful to me for the names because the players can go in and edit the text boxes to put in their own names (if there is a better way to do this i would appreciate any tips here too). But really my question is can i make a window like this to display text that CAN'T be edited by the user?

The "EDIT" class name is for edit controls. You're looking for more of a label, and that is offered through the "STATIC" class name, along with support for an icon or bitmap rather than text.

As for the later question of how to centre it, it's one of the many static-control-specific styles you can use. The one in particular you're looking for is SS_CENTER , which can be bitwise-ORed with your two WS_* styles.

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