Author | Topic: SetFocus() Windows API | |
---|---|---|
Roger Donnay | SetFocus() Windows API on Mon, 30 Mar 2009 09:03:24 -0600 I am trying to use the Windows API function SetFocus() to set focus to a control by its handle. I can't get it to work. No errors. Just nothing. I need this when working with CodeJock because they don't have an equivalent to Xbase++ SetAppFocus(). Any ideas? | |
Pablo Botella | Re: SetFocus() Windows API on Tue, 31 Mar 2009 01:21:56 +0200 Hi Roger, SetFocus() can only be used within the same thread where the window was created but you can subclass the control if belong to your process or install a hook in this thread if run in a separate process and post a registered intermediate message to call SetFocus() in the same thread that was create the control. Regards, Pablo Botella | |
Roger Donnay | Re: SetFocus() Windows API on Mon, 30 Mar 2009 20:09:24 -0600 Hi Pablo - I am testing this is a single-threaded small test application. I create a few XbpPushbutton() objects, then try to set focus as follows: SetFocus(oButton1:getHwnd()) Should that work? Roger DLLFUNCTION SetFocus(hWnd) USING STDCALL FROM user32.dll "Pablo Botella" <pb_no_spam_@_remove_all_betwen_underscores_xbwin.com> wrote in message news:77f7a75e$1ae98e85$c33@news.alaska-software.com... Hi Roger, SetFocus() can only be used within the same thread where the window was created but you can subclass the control if belong to your process or install a hook in this thread if run in a separate process and post a registered intermediate message to call SetFocus() in the same thread that was create the control. Regards, Pablo Botella | |
Pablo Botella | Re: SetFocus() Windows API on Tue, 31 Mar 2009 05:53:05 +0200 Hi Roger, > I create a few XbpPushbutton() objects, then try to set focus as follows: > SetFocus(oButton1:getHwnd()) > Should that work? No, because you have made a wrong asumption > I am testing this is a single-threaded small test application. Xbase++ GUI apps have at least 3 threads. The main thread : where you run your main function and following code The garbage collector thread: that release unused resources The GUI thread: that creates all windows in your app compile the attached sample Just a dialog with 3 push buttons oBtn1:activate:= {|| @user32:SetFocus(oBtn3:GetHWND()) } oBtn2:activate:= {|| Delegated_Eval( {|| @user32:SetFocus(oBtn1:GetHWND())}) } oBtn3:activate:= {|| @user32:SetFocus(oBtn2:GetHWND()) } You will see that oBtn1 and oBtn2 will do just nothing but oBtn2 will move the focus to oBtn1 Just the same API call, the diference is that oBtn2 executes the call in the GUI thread Regards, Pablo Botella TestFocus.zip | |
Roger Donnay | Re: SetFocus() Windows API on Tue, 31 Mar 2009 10:24:09 -0600 Pablo - It appears that I will need ot4xb to do this. Is this a free library that can be distributed with my XCodeJock product? XCodeJock is a new product of mine that makes it much easier to develop CodeJock applications. It is mostly targeted to eXpress++ users. Roger "Pablo Botella" <pb_no_spam_@_remove_all_betwen_underscores_xbwin.com> wrote in message news:7718735e$1c6dfe86$3fb@news.alaska-software.com... Hi Roger, > I create a few XbpPushbutton() objects, then try to set focus as follows: > SetFocus(oButton1:getHwnd()) > Should that work? No, because you have made a wrong asumption > I am testing this is a single-threaded small test application. Xbase++ GUI apps have at least 3 threads. The main thread : where you run your main function and following code The garbage collector thread: that release unused resources The GUI thread: that creates all windows in your app compile the attached sample Just a dialog with 3 push buttons oBtn1:activate:= {|| @user32:SetFocus(oBtn3:GetHWND()) } oBtn2:activate:= {|| Delegated_Eval( {|| @user32:SetFocus(oBtn1:GetHWND())}) } oBtn3:activate:= {|| @user32:SetFocus(oBtn2:GetHWND()) } You will see that oBtn1 and oBtn2 will do just nothing but oBtn2 will move the focus to oBtn1 Just the same API call, the diference is that oBtn2 executes the call in the GUI thread Regards, Pablo Botella | |
Pablo Botella | Re: SetFocus() Windows API on Tue, 31 Mar 2009 21:08:30 +0200 Hi, . > Is this a free library that can be distributed with my XCodeJock product? Yes you can redistribute it. Will be nice to put a link to my site but not required. Regards, Pablo Botella | |
Roger Donnay | Re: SetFocus() Windows API on Wed, 01 Apr 2009 08:02:04 -0600 Well of course I will put a link to your site. Thank you. "Pablo Botella" <pb_no_spam_@_remove_all_betwen_underscores_xbwin.com> wrote in message news:3e984d6$16e28ee3$df1@news.alaska-software.com... Hi, . > Is this a free library that can be distributed with my XCodeJock product? Yes you can redistribute it. Will be nice to put a link to my site but not required. Regards, Pablo Botella | |
Roger Donnay | Re: SetFocus() Windows API on Tue, 31 Mar 2009 12:54:29 -0600 That works great! Thank you very much. "Pablo Botella" <pb_no_spam_@_remove_all_betwen_underscores_xbwin.com> wrote in message news:7718735e$1c6dfe86$3fb@news.alaska-software.com... Hi Roger, > I create a few XbpPushbutton() objects, then try to set focus as follows: > SetFocus(oButton1:getHwnd()) > Should that work? No, because you have made a wrong asumption > I am testing this is a single-threaded small test application. Xbase++ GUI apps have at least 3 threads. The main thread : where you run your main function and following code The garbage collector thread: that release unused resources The GUI thread: that creates all windows in your app compile the attached sample Just a dialog with 3 push buttons oBtn1:activate:= {|| @user32:SetFocus(oBtn3:GetHWND()) } oBtn2:activate:= {|| Delegated_Eval( {|| @user32:SetFocus(oBtn1:GetHWND())}) } oBtn3:activate:= {|| @user32:SetFocus(oBtn2:GetHWND()) } You will see that oBtn1 and oBtn2 will do just nothing but oBtn2 will move the focus to oBtn1 Just the same API call, the diference is that oBtn2 executes the call in the GUI thread Regards, Pablo Botella | |
Michael | Re: SetFocus() Windows API on Tue, 31 Mar 2009 23:34:42 -0500 Hi Roger, As Pablo pointed out, SetFocus() has its limitations. Pablo has created a great tool in ot4xb. As an alternative, if you change your API call to SetForegroundWindow(), I believe it will work for you. I have modified Pablo's example to use SetForegroundWindow and it appears to function correctly. HTH, Michael "Pablo Botella" <pb_no_spam_@_remove_all_betwen_underscores_xbwin.com> wrote in message news:7718735e$1c6dfe86$3fb@news.alaska-software.com... Hi Roger, > I create a few XbpPushbutton() objects, then try to set focus as follows: > SetFocus(oButton1:getHwnd()) > Should that work? No, because you have made a wrong asumption > I am testing this is a single-threaded small test application. Xbase++ GUI apps have at least 3 threads. The main thread : where you run your main function and following code The garbage collector thread: that release unused resources The GUI thread: that creates all windows in your app compile the attached sample Just a dialog with 3 push buttons oBtn1:activate:= {|| @user32:SetFocus(oBtn3:GetHWND()) } oBtn2:activate:= {|| Delegated_Eval( {|| @user32:SetFocus(oBtn1:GetHWND())}) } oBtn3:activate:= {|| @user32:SetFocus(oBtn2:GetHWND()) } You will see that oBtn1 and oBtn2 will do just nothing but oBtn2 will move the focus to oBtn1 Just the same API call, the diference is that oBtn2 executes the call in the GUI thread Regards, Pablo Botella Test2.zip | |
Roger Donnay | Re: SetFocus() Windows API on Wed, 01 Apr 2009 08:03:07 -0600 Michael - Thank you for that info. I will give it a try. Roger "Michael" <Michael@Apareon.com> wrote in message news:6ce363ae$46171572$6292@news.alaska-software.com... > Hi Roger, > > As Pablo pointed out, SetFocus() has its limitations. > Pablo has created a great tool in ot4xb. > > As an alternative, if you change your API call to SetForegroundWindow(), I > believe it will work for you. > > I have modified Pablo's example to use SetForegroundWindow and it appears > to function correctly. > > HTH, > Michael > > > > > "Pablo Botella" <pb_no_spam_@_remove_all_betwen_underscores_xbwin.com> > wrote in message news:7718735e$1c6dfe86$3fb@news.alaska-software.com... > Hi Roger, > >> I create a few XbpPushbutton() objects, then try to set focus as follows: >> SetFocus(oButton1:getHwnd()) >> Should that work? > > No, because you have made a wrong asumption >> I am testing this is a single-threaded small test application. > > Xbase++ GUI apps have at least 3 threads. > The main thread : where you run your main function and following code > The garbage collector thread: that release unused resources > The GUI thread: that creates all windows in your app > > compile the attached sample > > Just a dialog with 3 push buttons > > oBtn1:activate:= {|| @user32:SetFocus(oBtn3:GetHWND()) } > oBtn2:activate:= {|| Delegated_Eval( {|| > @user32:SetFocus(oBtn1:GetHWND())}) } > oBtn3:activate:= {|| @user32:SetFocus(oBtn2:GetHWND()) } > > You will see that oBtn1 and oBtn2 will do just nothing > but oBtn2 will move the focus to oBtn1 > > Just the same API call, the diference is that oBtn2 executes the call in > the GUI thread > > Regards, > > Pablo Botella > > | |
Roger Donnay | Re: SetFocus() Windows API on Wed, 01 Apr 2009 08:20:23 -0600 That work excellently. Thank you. "Michael" <Michael@Apareon.com> wrote in message news:6ce363ae$46171572$6292@news.alaska-software.com... > Hi Roger, > > As Pablo pointed out, SetFocus() has its limitations. > Pablo has created a great tool in ot4xb. > > As an alternative, if you change your API call to SetForegroundWindow(), I > believe it will work for you. > > I have modified Pablo's example to use SetForegroundWindow and it appears > to function correctly. > > HTH, > Michael > > > > > "Pablo Botella" <pb_no_spam_@_remove_all_betwen_underscores_xbwin.com> > wrote in message news:7718735e$1c6dfe86$3fb@news.alaska-software.com... > Hi Roger, > >> I create a few XbpPushbutton() objects, then try to set focus as follows: >> SetFocus(oButton1:getHwnd()) >> Should that work? > > No, because you have made a wrong asumption >> I am testing this is a single-threaded small test application. > > Xbase++ GUI apps have at least 3 threads. > The main thread : where you run your main function and following code > The garbage collector thread: that release unused resources > The GUI thread: that creates all windows in your app > > compile the attached sample > > Just a dialog with 3 push buttons > > oBtn1:activate:= {|| @user32:SetFocus(oBtn3:GetHWND()) } > oBtn2:activate:= {|| Delegated_Eval( {|| > @user32:SetFocus(oBtn1:GetHWND())}) } > oBtn3:activate:= {|| @user32:SetFocus(oBtn2:GetHWND()) } > > You will see that oBtn1 and oBtn2 will do just nothing > but oBtn2 will move the focus to oBtn1 > > Just the same API call, the diference is that oBtn2 executes the call in > the GUI thread > > Regards, > > Pablo Botella > > |