程序可以设置其他程序的窗口标题 [英] A Program can set window title of other programs
本文介绍了程序可以设置其他程序的窗口标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想写一个程序可以在打开之前设置其他程序的Windows标题。例如:我使用我的程序选择记事本并打开它,当它打开时,记事本的标题被更改。
我怎么能用C / Win32 / API?
我知道SetWindowText可以更改标题,但只有存在窗口才会改变。
谢谢
Hi all,
I want to write a program can set windows title of other programs before it''s opened. For ex: I used my program to selects Notepad and open it, when it opened, notepad''s title was changed.
how can I do it with C/Win32/API?
I knew that SetWindowText can change title, but it only change if there is an exist windows.
Thank you
推荐答案
使用CreateProcess
API启动应用程序。
在STARTUPINFO
结构传递到CreateProcess
,使用STARTF_USESHOWWINDOW
隐藏窗口,SW_HIDE
flags。
CreateProcess
成功后,您将获得主线程的句柄在PROCESS_INFORMATION
结构中。
在EnumThreadWindows
函数中使用此线程ID来获取刚刚创建的进程的窗口句柄。
现在你可以在这个窗口句柄上使用SetWindowText
。
最后使用的ShowWindow 窗口句柄上的code>,使窗口可见。
Use theCreateProcess
API to start the application.
In theSTARTUPINFO
structure passed intoCreateProcess
, hide the window using theSTARTF_USESHOWWINDOW
andSW_HIDE
flags.
AfterCreateProcess
succeeds, you will get the handle to the main thread in thePROCESS_INFORMATION
structure.
Use this thread id in theEnumThreadWindows
function to get the window handle of the process just created.
Now you can useSetWindowText
on this window handle.
Finally useShowWindow
on the window handle to make the window visible.
嗨亲爱的朋友
好主意
它很容易做到
i知道这个算法用visual c ++(MFC)
首先你必须确定打开记事本程序的时间。
这样做你必须使用Timer对象或event.add这个事件进入你的项目,并在OnInitial()事件你必须运行它:
hi my dear friend
good idea
it''s easy to do
i know this algorithm with visual c++ (MFC)
at first you have to determine when the notepad program is opened.
to do this you have to use Timer object or event.add this event into your project, and in the OnInitial() event you have to run it:
void CMyClass::OnInitial(...){
...
SetTimer(1,10,0);
}
void CMyClass::OnTimer(...){
CWnd *w=FindWindow(0,_T("Untitled - notepad"));
if(IsWindow(w->GetSafeHwnd())){
KillTimer(1);
w->SetWindowText(_T("My Text"));
}
}
i希望它能帮到你
上帝和你我的朋友
i hope it will help you
god with you my pal
这篇关于程序可以设置其他程序的窗口标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文