Click here to Skip to main content
15,907,392 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted

Use the CreateProcess API to start the application.
In the STARTUPINFO structure passed into CreateProcess, hide the window using the STARTF_USESHOWWINDOW and SW_HIDE flags.
After CreateProcess succeeds, you will get the handle to the main thread in the PROCESS_INFORMATION structure.
Use this thread id in the EnumThreadWindows function to get the window handle of the process just created.
Now you can use SetWindowText on this window handle.
Finally use ShowWindow on the window handle to make the window visible.
 
Share this answer
 
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 hope it will help you

god with you my pal
 
Share this answer
 
Comments
SVPro 6-Mar-13 21:16pm    
Hi man,

When you use FindWindow, that means you wait a Window appear on desktop, and then Set title by SetWindowText. It's not satisfied my requirement (Set text before window appear).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900