Click here to Skip to main content
15,915,319 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Reading/Writing XP registry files Pin
David Crow19-Sep-03 7:40
David Crow19-Sep-03 7:40 
GeneralRe: Reading/Writing XP registry files Pin
skaanji19-Sep-03 8:21
skaanji19-Sep-03 8:21 
GeneralRe: Reading/Writing XP registry files Pin
David Crow19-Sep-03 8:26
David Crow19-Sep-03 8:26 
GeneralRe: Reading/Writing XP registry files Pin
ZoogieZork19-Sep-03 8:56
ZoogieZork19-Sep-03 8:56 
GeneralRe: Reading/Writing XP registry files Pin
skaanji19-Sep-03 9:39
skaanji19-Sep-03 9:39 
QuestionHow to save the structure of a tree view? Pin
Kayembi19-Sep-03 6:34
Kayembi19-Sep-03 6:34 
AnswerRe: How to save the structure of a tree view? Pin
l a u r e n20-Sep-03 6:04
l a u r e n20-Sep-03 6:04 
QuestionBetter way of changing window title and icon at run-time? Pin
Kayembi19-Sep-03 6:21
Kayembi19-Sep-03 6:21 
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:

<br />
//this loop finds the third party app window:<br />
while(thirdParty_hWnd == 0)	//loop until window is found<br />
{<br />
	//app was started using ShellExecuteEx - check it is still running:<br />
	if(WaitForSingleObject(thirdPartyApp.hProcess,0)==WAIT_TIMEOUT)<br />
	{		<br />
		thirdParty_hWnd = FindWindow("thirdpartyappclass_mainwin",NULL);<br />
<br />
		SetWindowText(thirdParty_hWnd, "New Win Title");	//rename window<br />
	<br />
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))<br />
		{<br />
			TranslateMessage(&msg);<br />
			DispatchMessage(&msg);<br />
		}<br />
	}<br />
	else<br />
	{break;}	//3rd party app has closed<br />
}<br />


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:

<br />
char title_str[MAX_PATH];<br />
<br />
//this loop handles the main stuff now that the window has been found:<br />
while(thirdParty_hWnd!=0)<br />
{<br />
	if(WaitForSingleObject(thirdPartyApp.hProcess,0)==WAIT_TIMEOUT)<br />
	{<br />
		//set window text:<br />
		GetWindowText(thirdParty_hWnd,title_str,MAX_PATH);<br />
		if(strcmp(title_str,"New Win Title")!=0)<br />
		{<br />
			SetWindowText(thirdParty_hWnd,"New Win Title);<br />
		}<br />
<br />
		//message loop here<br />
	}<br />
}<br />


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:

<br />
SendMessage(thirdParty_hWnd, WM_SETICON,(WPARAM)ICON_BIG, (LPARAM)(HICON)NewIconBig);<br />
SendMessage(thirdParty_hWnd, WM_SETICON,(WPARAM)ICON_SMALL, (LPARAM)(HICON)NewIconSmall);<br />


(where NewIconBig and NewIconSmall are HICONs that point to an .ico file.

The only problem is that for this to work, the above code has to be contained in a while() loop (otherwise the icon is lost when you alt-tab etc). Although this works fine, looks good, and I have not noticed any slowdown, I am aware that this is probably not good practice to have a message sent to another window constantly. Is there anyway I can change the icon without having to continually tell the other window? (Note that in this case I cannot use an icon changer as the third party app has a built in checker that will cause the program to crash if any of its resources are changed.)

Any suggestions for improvements to my current methods would be much appreciated.
Many thanks,
KB
GeneralTool Tip Appearance Time Pin
Marty1020304019-Sep-03 6:11
Marty1020304019-Sep-03 6:11 
Generalmail verifier Pin
Max Santos19-Sep-03 5:53
Max Santos19-Sep-03 5:53 
GeneralInstallshield DLL Problem Pin
Anonymous19-Sep-03 5:42
Anonymous19-Sep-03 5:42 
GeneralInstallshield Pin
Anonymous19-Sep-03 5:36
Anonymous19-Sep-03 5:36 
QuestionHow to create a VC program to read text Pin
harshsingh19-Sep-03 5:13
harshsingh19-Sep-03 5:13 
AnswerRe: How to create a VC program to read text Pin
keegan19-Sep-03 5:41
keegan19-Sep-03 5:41 
GeneralRe: How to create a VC program to read text Pin
harshsingh21-Sep-03 18:24
harshsingh21-Sep-03 18:24 
GeneralRe: How to create a VC program to read text Pin
keegan21-Sep-03 20:58
keegan21-Sep-03 20:58 
AnswerRe: How to create a VC program to read text Pin
PremL19-Sep-03 5:48
PremL19-Sep-03 5:48 
GeneralModal dialog does not come to the foreground Pin
Salvador Dali19-Sep-03 5:07
Salvador Dali19-Sep-03 5:07 
GeneralRe: Modal dialog does not come to the foreground Pin
JWood19-Sep-03 5:17
JWood19-Sep-03 5:17 
Generaladd code to standard Save Pin
doctorpi19-Sep-03 4:51
doctorpi19-Sep-03 4:51 
GeneralRe: add code to standard Save Pin
JWood19-Sep-03 5:24
JWood19-Sep-03 5:24 
GeneralRe: add code to standard Save Pin
Dangleberry19-Sep-03 5:25
sussDangleberry19-Sep-03 5:25 
GeneralRe: add code to standard Save Pin
Dangleberry19-Sep-03 5:29
sussDangleberry19-Sep-03 5:29 
GeneralRe: add code to standard Save Pin
doctorpi19-Sep-03 5:32
doctorpi19-Sep-03 5:32 
GeneralRe: add code to standard Save Pin
doctorpi19-Sep-03 5:42
doctorpi19-Sep-03 5:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.