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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. User32 SetFocus not working - any ideas?

User32 SetFocus not working - any ideas?

Scheduled Pinned Locked Moved C#
questionlounge
5 Posts 2 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.
  • W Offline
    W Offline
    wbjohnson
    wrote on last edited by
    #1

    hey guys, ive wrote a little app that takes a given a IntPtr handle to a random application.... it when gets all childwindows and looks for the first EDIT (CEdit) class and then tries to set focus to it.. i know it seems pointless, but its part of a large plan! hehe anyway, its just not working! im calling SetFocus(IntPtr) to the Edit class and its just ignore me! (ive even tried bringing the parent application to te front - that works btw) any ideas why SetFocus isnt putting the cursor in the Edit class ready for user input?

    N 1 Reply Last reply
    0
    • W wbjohnson

      hey guys, ive wrote a little app that takes a given a IntPtr handle to a random application.... it when gets all childwindows and looks for the first EDIT (CEdit) class and then tries to set focus to it.. i know it seems pointless, but its part of a large plan! hehe anyway, its just not working! im calling SetFocus(IntPtr) to the Edit class and its just ignore me! (ive even tried bringing the parent application to te front - that works btw) any ideas why SetFocus isnt putting the cursor in the Edit class ready for user input?

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      Hello

      Quoted from MSDN:

      If the hWnd parameter is invalid or the window is not attached to the calling thread's message queue, the return value is NULL. To get extended error information, call GetLastError.

      Try to see the returned value, and GetLastError(). Also I suggest to SendMessage(WM_SETFOCUS) yourself, instead of calling SetFocu(hWnd).

      Regards:rose:

      W 1 Reply Last reply
      0
      • N Nader Elshehabi

        Hello

        Quoted from MSDN:

        If the hWnd parameter is invalid or the window is not attached to the calling thread's message queue, the return value is NULL. To get extended error information, call GetLastError.

        Try to see the returned value, and GetLastError(). Also I suggest to SendMessage(WM_SETFOCUS) yourself, instead of calling SetFocu(hWnd).

        Regards:rose:

        W Offline
        W Offline
        wbjohnson
        wrote on last edited by
        #3

        hi there, when i use SetFocus(), it doesnt work and i get this last error message: 1008 An attempt was made to reference a token that does not exist. ERROR_NO_TOKEN (i looked up the message on google) however - if i do what u suggested it works :D do you know why this way works and the other one doesnt?

        N 1 Reply Last reply
        0
        • W wbjohnson

          hi there, when i use SetFocus(), it doesnt work and i get this last error message: 1008 An attempt was made to reference a token that does not exist. ERROR_NO_TOKEN (i looked up the message on google) however - if i do what u suggested it works :D do you know why this way works and the other one doesnt?

          N Offline
          N Offline
          Nader Elshehabi
          wrote on last edited by
          #4

          Hello I'm glad that it works now.:) If you revise the qoute I posted from MSDN, you'd notice that SetFocus() function, sends the message to the current message queue. You are sending WM_SETFOCUS message to another application with another message queue. That's why you need to explicitly send the message yourself.

          Regards:rose:

          W 1 Reply Last reply
          0
          • N Nader Elshehabi

            Hello I'm glad that it works now.:) If you revise the qoute I posted from MSDN, you'd notice that SetFocus() function, sends the message to the current message queue. You are sending WM_SETFOCUS message to another application with another message queue. That's why you need to explicitly send the message yourself.

            Regards:rose:

            W Offline
            W Offline
            wbjohnson
            wrote on last edited by
            #5

            ahhhhh thats excellent!! i understand it now! thanks ever so much for your help this evening, its much appriciated! Regards, Will

            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