Better way of changing window title and icon at run-time?
-
Hi, I have written an app that controls another application - it basically packs its files, allows customisation of its window title and icon, adds an alternative splash screen and various other features specific to the app. The application my app controls is third-party, so I have no access to its code. Everything is working fine, but I was wondering if there is a better way of changing the icon and window name at run-time than the methods I am currently using. (Incidentally, I am using the straight Windows API with _no_ MFC.) To change the window title, I have written this loop:
//this loop finds the third party app window: while(thirdParty_hWnd == 0) //loop until window is found { //app was started using ShellExecuteEx - check it is still running: if(WaitForSingleObject(thirdPartyApp.hProcess,0)==WAIT_TIMEOUT) { thirdParty_hWnd = FindWindow("thirdpartyappclass_mainwin",NULL); SetWindowText(thirdParty_hWnd, "New Win Title"); //rename window if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } } else {break;} //3rd party app has closed }
The problem here is that the window title of the third party app does not appear in the window immediately, so my code sets the title before the app does. This means that the title is changed back a second or less after this code has been executed, meaning that I have to check the window title again in my next loop and change it back if necessary, like this:char title_str[MAX_PATH]; //this loop handles the main stuff now that the window has been found: while(thirdParty_hWnd!=0) { if(WaitForSingleObject(thirdPartyApp.hProcess,0)==WAIT_TIMEOUT) { //set window text: GetWindowText(thirdParty_hWnd,title_str,MAX_PATH); if(strcmp(title_str,"New Win Title")!=0) { SetWindowText(thirdParty_hWnd,"New Win Title); } //message loop here } }
Although this works, the main problem is that this means the window title is set to what I want ("New Win Title" in the example) at first, then it reverts to the default app title briefly before getting changed back to, for instance, "New Win Title". Does anybody know of a better way of doing this, so that the original app title would never show at all? (Also, please bear in mind that I a relative novice, so feel free to tell me where my code is shoddy and suggest improvements.) To change the icon, I use the following code:SendMessage(thirdParty_hWnd, WM_SETICON,(WPAR