Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Assuming you are writing this in Visual Studio as a C project, and you have a dialog with a child edit called IDC_TEXT, and hwnd is your dialog handle:</p> <pre><code>// Declarations long lRet = 0; wchar_t *wszText = NULL; // Retrieve the length of the edit text lRet = SendDlgItemMessageW(hwnd, IDC_TEXT, WM_GETTEXTLENGTH, 0, 0); // Assign memory based on retrieved length wszText = (wchar_t *)malloc(((lRet + 1) * sizeof(wchar_t))); // Check that memory allocation succeeded if (wszText != NULL) { // Retrive the text from edit lRet = SendDlgItemMessageW(hwnd, IDC_TEXT, WM_GETTEXT, (long)(lRet+1), (long)wszText); // Check that text is not NULL if (wszText == NULL) { MessageBoxW(hwnd, L"Failed to retrieve text!", L"Error", MB_OK | MB_ICONERROR); } else { MessageBoxW(hwnd, wszText, L"Edit Contents", MB_OK); } } else { MessageBoxW(hwnd, L"Failed to assign memory!", L"Error", MB_OK | MB_ICONERROR); } </code></pre> <p>Note that the code uses SendDlgItemMessageW and that your dialog box must be created with DialogBoxW. If you are using an older Visual Studio, you must select Unicode build so the program gets built using the wide APIs.</p> <p>Not sure why you say you want to create a UTF8 edit box in your post. Windows uses UTF16 to represent characters natively, so it can only create a UTF16 edit box. If you need to convert between UTF8 and UTF16 or vice versa, take a look at the MultiByteToWideChar and WideCharToMultiByte APIs.</p> <p>Edit: Corrected UTF16/UCS2 issue per David's comment below.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload