簡體   English   中英

win32 c++ 我想在 STATIC label 的 TEXT 之后直接插入一個 EDIT 控件

[英]win32 c++ I want to insert an EDIT control straight after the TEXT of the STATIC label

要制作 STATIC label,我可以使用:

            HWND hwnd_ques=CreateWindow(
                TEXT("STATIC"),
                TEXT("Yao happy swallow is"),
                WS_VISIBLE | WS_CHILD,
                10,
                70,
                180,
                30,
                hwnd,
                NULL,
                (HINSTANCE)GetWindowLongPtr(hwnd, GWL_HINSTANCE),
                NULL);

調用CreateWindow后,我使用WM_SETFONT msg 設置標簽的字體和字體大小(成功):

            SendMessage(hwnd_ques, WM_SETFONT, (WPARAM)font1, static_cast<LPARAM>(MAKELONG(TRUE, 0)));

//definition of font1 is not shown here but it worked successfully

However, I want to insert an EDIT control straight after the TEXT of the STATIC label, that is, I will make the label width fit its text width and assign the X POSITION of the EDIT according to the label position and width. 如果我手動指定 label 寬度,則無法確保label 寬度恰好適合文本寬度,因為我實際上並不知道該 label 的文本寬度

我想知道如何使 label 寬度恰好適合其文本寬度 因為知道文本內容、字體和字體大小,也許我可以得到文本寬度 獲得文本寬度后,我可以回頭設置標簽的寬度。

-

目的

我想在 STATIC label 的TEXT之后直接插入一個 EDIT 控件

-

編輯

在互聯網上搜索,它說使用GetTextExtentPoint32

SIZE textSize;
GetTextExtentPoint32(GetDC(hwnd), text, strlen(text), &textSize);

但是我在哪里可以在這個 function 中指定字體/字體大小?

通過使用 function GetTextExtentPoint32如下:

SIZE textSize;
GetTextExtentPoint32(GetDC(hwnd), text, strlen(text), &textSize);

並且通過之前使用SelectFont來指定字體,這個問題就解決了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM