Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Better way of changing window title and icon at run-time?

Better way of changing window title and icon at run-time?

Scheduled Pinned Locked Moved C / C++ / MFC
c++cssjsonhelptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kayembi
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups