如何使用 DrawText() 在已知句柄的给定窗口中写入文本? [英] how to use DrawText() to write text in a given window whose handle is known?
问题描述
我想知道如何使用 Windows API 在特定窗口上从窗口中的给定位置开始写入文本.
I want to know how to write text on a particular window starting at a given location in the window using the Windows API.
例如,如果要写入文本的窗口内的坐标是 (x,y) = (40,10) 那么我需要做什么才能将一行文本写入该位置的特定窗口在窗口?
For example if the coordinates within the window where the text is to be written are (x,y) = (40,10) then what do I need to do to write a line of text to a particular window at that location in the window?
推荐答案
假设您的窗口名称是hwnd",并且您想在该窗口上以 x,y 坐标写入的文本存储在消息"中,其中
Suppose your window name is "hwnd" and the text which u want to write on that window at x,y coordinate is say stored in "message" where
LPCWSTR message=L"My First Window";
then
RECT rect;
HDC wdc = GetWindowDC(hwnd);
GetClientRect (bgHandle, &rect) ;
SetTextColor(wdc, 0x00000000);
SetBkMode(wdc,TRANSPARENT);
rect.left=40;
rect.top=10;
DrawText( wdc, message, -1, &rect, DT_SINGLELINE | DT_NOCLIP ) ;
DeleteDC(wdc);
就是这样......记住这只是一个例子.
Thats it.. remember this is just one example.
这篇关于如何使用 DrawText() 在已知句柄的给定窗口中写入文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!