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. Is there a similar functio to SetWindowActive to do this ??

Is there a similar functio to SetWindowActive to do this ??

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
7 Posts 5 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.
  • S Offline
    S Offline
    Still learning how to code
    wrote on last edited by
    #1

    In the MSVC documentation, SetActivateWindow() activates a window - however this must be associated with the calling thread's message queue. Is there a way that I can pass control from my program to another app's main window knowing it's handle ?? (I have got the handle using EnumWindows() and checking the window title). Appreciate any help:confused: Doug

    L M P 3 Replies Last reply
    0
    • S Still learning how to code

      In the MSVC documentation, SetActivateWindow() activates a window - however this must be associated with the calling thread's message queue. Is there a way that I can pass control from my program to another app's main window knowing it's handle ?? (I have got the handle using EnumWindows() and checking the window title). Appreciate any help:confused: Doug

      L Offline
      L Offline
      l a u r e n
      wrote on last edited by
      #2

      ummmm this might be dumb but cant you send a mouse click message to its message queue ... that would make the whole thing happen as if the user clicked it just a thought


      "... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away"
      sonork: 100.18128   8028finder.com

      1 Reply Last reply
      0
      • S Still learning how to code

        In the MSVC documentation, SetActivateWindow() activates a window - however this must be associated with the calling thread's message queue. Is there a way that I can pass control from my program to another app's main window knowing it's handle ?? (I have got the handle using EnumWindows() and checking the window title). Appreciate any help:confused: Doug

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        Use SetForegroundWindow() instead. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

        L 1 Reply Last reply
        0
        • M Michael Dunn

          Use SetForegroundWindow() instead. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm

          L Offline
          L Offline
          l a u r e n
          wrote on last edited by
          #4

          doh! i knew there would be an easy way i was too lazy to squizz thru the msdn stuff sorry :-O


          "... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away"
          sonork: 100.18128   8028finder.com

          N 1 Reply Last reply
          0
          • S Still learning how to code

            In the MSVC documentation, SetActivateWindow() activates a window - however this must be associated with the calling thread's message queue. Is there a way that I can pass control from my program to another app's main window knowing it's handle ?? (I have got the handle using EnumWindows() and checking the window title). Appreciate any help:confused: Doug

            P Offline
            P Offline
            Peter Occil
            wrote on last edited by
            #5

            Before calling SetActiveWindow, use the AttachThreadInput function to attach the input states of the calling thread and the thread with the desired window:

            DWORD tidThis,tidOther;
            tidThis=GetCurrentThreadId();
            tidOther=GetWindowThreadProcessId(hwnd,NULL);
            if(tidThis!=tidOther)
            AttachThreadInput(tidThis,tidOther,TRUE);
            SetActiveWindow(hwnd); // or SetForegroundWindow
            if(tidThis!=tidOther)
            AttachThreadInput(tidThis,tidOther,FALSE);

            Peter O.

            S 1 Reply Last reply
            0
            • L l a u r e n

              doh! i knew there would be an easy way i was too lazy to squizz thru the msdn stuff sorry :-O


              "... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away"
              sonork: 100.18128   8028finder.com

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #6

              lauren wrote: i knew there would be an easy way Sadly under 2K and XP, it won't actually make it foreground :-( It'll just flash the taskbar icon thrice. Unless you change this setting using Powertoys. Something about preventing apps from stealing focus. Nish


              Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]

              1 Reply Last reply
              0
              • P Peter Occil

                Before calling SetActiveWindow, use the AttachThreadInput function to attach the input states of the calling thread and the thread with the desired window:

                DWORD tidThis,tidOther;
                tidThis=GetCurrentThreadId();
                tidOther=GetWindowThreadProcessId(hwnd,NULL);
                if(tidThis!=tidOther)
                AttachThreadInput(tidThis,tidOther,TRUE);
                SetActiveWindow(hwnd); // or SetForegroundWindow
                if(tidThis!=tidOther)
                AttachThreadInput(tidThis,tidOther,FALSE);

                Peter O.

                S Offline
                S Offline
                Still learning how to code
                wrote on last edited by
                #7

                Peter, that code works a treat !! Many thanks for your help - I've learnt something ! Thanks also to all the others who contributed to this thread. :):):) Doug

                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