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. How to change a caption of any window

How to change a caption of any window

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestionlearning
16 Posts 4 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.
  • D Dody_DK

    Hey every one... I have read and tested some stuff with "SetWindowText" and when i use SetWindowText i can change the caption of my appelcation, but I think it is possible to change window's caption of other programs.... i am not sure if it is SetWindowText(hWnd,"My Text"); but i used it and it gave me an eroor... so any help? thanks alot I am still a beginner ;)

    D Offline
    D Offline
    David Crow
    wrote on last edited by
    #3

    Dody_DK wrote: ...but i used it and it gave me an eroor... My telepathy powers are weak today. Can you tell us what the error is?


    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

    D 1 Reply Last reply
    0
    • D David Crow

      Dody_DK wrote: ...but i used it and it gave me an eroor... My telepathy powers are weak today. Can you tell us what the error is?


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      D Offline
      D Offline
      Dody_DK
      wrote on last edited by
      #4

      It will give me this error error C2065: 'hWnd' : undeclared identifier :sigh: hope you can help...

      D 1 Reply Last reply
      0
      • D Dody_DK

        It will give me this error error C2065: 'hWnd' : undeclared identifier :sigh: hope you can help...

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #5

        From where and how are you calling SetWindowText()?


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        D 1 Reply Last reply
        0
        • D David Crow

          From where and how are you calling SetWindowText()?


          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          D Offline
          D Offline
          Dody_DK
          wrote on last edited by
          #6

          I creat a button, and from the classwizard I chose BN_Clicked and I add function. then I click edit code and write SetWindowText(hWnd,"My Text");... so it will be void CAdfadfhgDlg::OnButton1() { SetWindowText(hWnd,"My Text"); } I think i am doing something wrong... right?

          D 1 Reply Last reply
          0
          • D Dody_DK

            I creat a button, and from the classwizard I chose BN_Clicked and I add function. then I click edit code and write SetWindowText(hWnd,"My Text");... so it will be void CAdfadfhgDlg::OnButton1() { SetWindowText(hWnd,"My Text"); } I think i am doing something wrong... right?

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #7

            Dody_DK wrote: I think i am doing something wrong... right? Right, you are doing something wrong. Simply remove the hWnd parameter. It's not needed since you are already in the context of the dialog. That will fix that particular compiler error.


            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            D 1 Reply Last reply
            0
            • D David Crow

              Dody_DK wrote: I think i am doing something wrong... right? Right, you are doing something wrong. Simply remove the hWnd parameter. It's not needed since you are already in the context of the dialog. That will fix that particular compiler error.


              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              D Offline
              D Offline
              Dody_DK
              wrote on last edited by
              #8

              Yeah I did that also, but this will change my applecation's Caption not the other applecation's caption... and this is what I want to change the Window title of other applecation.... is it possible?

              D 1 Reply Last reply
              0
              • D Dody_DK

                Yeah I did that also, but this will change my applecation's Caption not the other applecation's caption... and this is what I want to change the Window title of other applecation.... is it possible?

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #9

                Dody_DK wrote: is it possible? Yes, just call FindWindow() as has already been mentioned.


                "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                D 1 Reply Last reply
                0
                • D David Crow

                  Dody_DK wrote: is it possible? Yes, just call FindWindow() as has already been mentioned.


                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                  D Offline
                  D Offline
                  Dody_DK
                  wrote on last edited by
                  #10

                  I did that also, but the same problem, only my applecation's caption will be changed, not others... void CAdfadfhgDlg::OnButton1() { HWND hwnd = ::FindWindow(NULL, "Title of program"); if (hwnd) { ::ShowWindow(hwnd, SW_SHOWDEFAULT); ::BringWindowToTop(hwnd); SetWindowText(hWnd,"My Text"); } hmm is there any thing wrong i am doing? thanks alot ;)

                  D 1 Reply Last reply
                  0
                  • D Dody_DK

                    I did that also, but the same problem, only my applecation's caption will be changed, not others... void CAdfadfhgDlg::OnButton1() { HWND hwnd = ::FindWindow(NULL, "Title of program"); if (hwnd) { ::ShowWindow(hwnd, SW_SHOWDEFAULT); ::BringWindowToTop(hwnd); SetWindowText(hWnd,"My Text"); } hmm is there any thing wrong i am doing? thanks alot ;)

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #11

                    Unless the title of CAdfadfhgDlg is "Title of program", the code you have should work. Dody_DK wrote: SetWindowText(hWnd,"My Text"); I assume that hWnd is supposed to be hwnd. Yes?


                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                    D 1 Reply Last reply
                    0
                    • D David Crow

                      Unless the title of CAdfadfhgDlg is "Title of program", the code you have should work. Dody_DK wrote: SetWindowText(hWnd,"My Text"); I assume that hWnd is supposed to be hwnd. Yes?


                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                      D Offline
                      D Offline
                      Dody_DK
                      wrote on last edited by
                      #12

                      Yes hWnd = hwnd, but i deleted it also as you said and used SetWindowText("My Text"); I have tried to do it with many programs.... but it didn't work...hmmmm I hope that you have other selution... thanks alot ;)

                      D 1 Reply Last reply
                      0
                      • D Dody_DK

                        Yes hWnd = hwnd, but i deleted it also as you said and used SetWindowText("My Text"); I have tried to do it with many programs.... but it didn't work...hmmmm I hope that you have other selution... thanks alot ;)

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #13

                        Dody_DK wrote: SetWindowText("My Text"); This is obviously not going to work as the function is being called in the context of your dialog. The net result being that your dialog's caption gets changed. Perhaps you should explain what you are actually trying to do. If we knew the whole story, we could make more informed suggestions.


                        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                        D 1 Reply Last reply
                        0
                        • D David Crow

                          Dody_DK wrote: SetWindowText("My Text"); This is obviously not going to work as the function is being called in the context of your dialog. The net result being that your dialog's caption gets changed. Perhaps you should explain what you are actually trying to do. If we knew the whole story, we could make more informed suggestions.


                          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

                          D Offline
                          D Offline
                          Dody_DK
                          wrote on last edited by
                          #14

                          What I want to do is: A small change the caption of a specific program like MSN Messenger or yahoo or any thing else.... this is the whole story :) I am very thankful for your support and help ;)

                          T 1 Reply Last reply
                          0
                          • D Dody_DK

                            What I want to do is: A small change the caption of a specific program like MSN Messenger or yahoo or any thing else.... this is the whole story :) I am very thankful for your support and help ;)

                            T Offline
                            T Offline
                            ThatsAlok
                            wrote on last edited by
                            #15

                            Dody_DK wrote: A small change the caption of a specific program like MSN Messenger or yahoo or any thing else.... this is the whole story I Think this little Code Will help for chanfing yahoo or msn Messenger ! HWND hYahooWnd=::FindWindow("YahooBuddyMain",NULL); if(hYahooWnd) { ::SetWindowText(hYahooWnd,"alok Gupta"); } HWND hMSNWnd=::FindWindow("MSBLClass",NULL); if(hYahooWnd) { ::SetWindowText(hMSNWnd,"alok Gupta"); } ----------------------------- "I Think It Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

                            D 1 Reply Last reply
                            0
                            • T ThatsAlok

                              Dody_DK wrote: A small change the caption of a specific program like MSN Messenger or yahoo or any thing else.... this is the whole story I Think this little Code Will help for chanfing yahoo or msn Messenger ! HWND hYahooWnd=::FindWindow("YahooBuddyMain",NULL); if(hYahooWnd) { ::SetWindowText(hYahooWnd,"alok Gupta"); } HWND hMSNWnd=::FindWindow("MSBLClass",NULL); if(hYahooWnd) { ::SetWindowText(hMSNWnd,"alok Gupta"); } ----------------------------- "I Think It Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

                              D Offline
                              D Offline
                              Dody_DK
                              wrote on last edited by
                              #16

                              It works perfectly... thanks alot man ;) thanks for every one helped here... ;) Peace

                              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