[英]how to set text from edit control to a window
I am trying to grab text from an edit control that I create at runtime and print the text from it onto the parent window (not the title bar) that I also create at runtime. 我试图从运行时创建的编辑控件中获取文本,然后将其从文本打印到也在运行时创建的父窗口(而不是标题栏)上。 How do I do this?
我该怎么做呢?
const int bufferSize = 1024;
char textBuffer[bufferSize] = "";
HWND Editbox = FindWindowEx(hWnd, NULL, "Edit", NULL);
SendMessage(Editbox, WM_GETTEXT,
(WPARAM)bufferSize, (LPARAM)textBuffer);
HWND Picbox = FindWindowEx(hWnd, NULL, "Picbox", NULL);
RECT Picbox_Rect;
GetClientRect(Picbox,&Picbox_Rect);
Picbox_Rect.top = 3;
Picbox_Rect.left = 3;
hdc = GetDC (Picbox) ;
HFONT fnt = CreateFont(14,0,0,0,FW_DONTCARE,
FALSE,FALSE,FALSE,DEFAULT_CHARSET,
OUT_OUTLINE_PRECIS,CLIP_DEFAULT_PRECIS,
0, VARIABLE_PITCH,TEXT("Verdana"));
SelectObject(hdc, fnt);
SetTextColor(hdc,RGB(0,0,255));
SetBkMode(hdc, TRANSPARENT);
DrawText(hdc, textBuffer, strlen (textBuffer),
&Picbox_Rect, DT_LEFT);
ReleaseDC (Picbox, hdc) ;
DeleteObject(fnt);
//InvalidateRect(Picbox, NULL, TRUE);
您可以使用GetWindowText从编辑控件中获取文本,并使用DrawText或TextOut编写文本。
如果直接使用Windows API,只需使用GetWindowText()
从文本框中获取文本,然后使用SetWindowText()
将文本写入另一个窗口或控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.