Read Handle of any type Window ACTIVE

User avatar
ericmagaldi
Posts: 37
Joined: Tue Feb 20, 2007 9:26 am
Location: São Paulo - Brazil
Contact:

Read Handle of any type Window ACTIVE

Post by ericmagaldi »

Hello,

How to obtain Handle of the window it activates (REDEFINES, MDI, WINDOW, MDICHILD, etc) of APPS, how?

Example below, opens MDI, to press F3 to add MDICHILDs, F2 should obtain Handle.

Code: Select all

#include 'mxbase.ch' // FiveWin.ch, etc, etc
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
function Main()
local oWin

SETKEY(VK_F2, {||WinInfo()})
SETKEY(VK_F3, {||AddWinChild()})

DEFINE WINDOW oWin TITLE 'Janela MDI' MDI
       @15,10 SAY 'F2 - WinInfo()'     SIZE 100,30
       @18,10 SAY 'F3 - AddWinChild()' SIZE 100,30
       //oWin:SetKey( VK_F2,{||ALERT('VK_F2 da janela')})

ACTIVATE WINDOW oWin ON INIT oWin:cTitle:=oWin:cTitle + ' oWin:hWnd=> ' + NTRIM(oWin:hWnd) + ' ' + GetClassName(oWin:hWnd) MAXIMIZED 

return nil

//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
function AddWinChild()
static nsNumber:=0
local oWin
 
DEFINE WINDOW oWin TITLE 'Janela MDICHILD # ' + NTRIM(++nsNumber) MDICHILD  COLOR 'N/BG'
       @15,10 BUTTON 'F2 - WinInfo()'     SIZE 100,30
       @18,10 BUTTON 'F3 - AddWinChild()' SIZE 100,30

ACTIVATE WINDOW oWin ON INIT oWin:cTitle:=oWin:cTitle + ' oWin:hWnd=> ' + NTRIM(oWin:hWnd) + ' ' + GetClassName(oWin:hWnd)

return nil

//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
// Here, I need to know Handle of the Window activate (MDI, MDICHILD ou any)
function WinInfo()
? GetActiveWindow() // Only to illustrate
return nil
//--------------------------------------------------------------------------
//I tried other forms using
//function WinInfo()
// GetWindow()
// NEXTDLGTAB()
// GetActiveWindow()
// GetFocus()
// GetParent()
// return nil
virtually,
Éric
xHarbour.org + Borland C + FiveWin (2.8/6.12) + Pelles C + HBMake + ADSCDX
São Paulo - Brasil
http://xBaseSuporte.freeforums.org
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Eric,

? GetParent( GetFocus() )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
ericmagaldi
Posts: 37
Joined: Tue Feb 20, 2007 9:26 am
Location: São Paulo - Brazil
Contact:

Post by ericmagaldi »

Antonio Linares wrote: ? GetParent( GetFocus() )
Antonio,
almost :)

when opening a MDICHILD, same being active, the button didn't receive the focus and WinInfo () Handle of MDIClient returned, after the button received the focus, it worked.
1º-This way will work only with control that receives focus.
2º-a small adjustment in FW for Setar the focus automatically.
Is it now? :(

Code: Select all

function WinInfo()
local nHandle

nHandle:=GetParent( GetFocus() )
? nHandle,GetClassName(nHandle),GetWindowText(nHandle),GetFocus(),GetWindow() 
return nil
virtually,
Éric
xHarbour.org + Borland C + FiveWin (2.8/6.12) + Pelles C + HBMake + ADSCDX
São Paulo - Brasil
http://xBaseSuporte.freeforums.org
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Eric,

You can check the Windows classname of the hWnd using GetClassName( hWnd ) so you will know what control or window has the focus and use GetParent() if needed
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
ericmagaldi
Posts: 37
Joined: Tue Feb 20, 2007 9:26 am
Location: São Paulo - Brazil
Contact:

Post by ericmagaldi »

Antonio Linares wrote:You can check the Windows classname of the hWnd using GetClassName( hWnd ) so you will know what control or window has the focus and use GetParent() if needed
Antonio,
Is the question exactly how exactly?? Because as I described, I already tried, but I didn't do in the correct way.
The way that you indicated doesn't totally work.
virtually,
Éric
xHarbour.org + Borland C + FiveWin (2.8/6.12) + Pelles C + HBMake + ADSCDX
São Paulo - Brasil
http://xBaseSuporte.freeforums.org
User avatar
ericmagaldi
Posts: 37
Joined: Tue Feb 20, 2007 9:26 am
Location: São Paulo - Brazil
Contact:

Post by ericmagaldi »

Below I created an alternative none elegant, for being a forced form, besides being the doubt in the cases with RESOURCE, Folders (a window containing others).

Please, we needed something technically effective.

Code: Select all

//--------------------------------------------------------------------------
//That needs to be gotten better.
//I don't believe that is not possible to obtain Handle of a simple window activates, something so basic.
//--------------------------------------------------------------------------
function WinInfo()
local nHandle

if ! ((nHandle:=GetParent( GetFocus() )) > 0 .and. UPPER(GetClassName(nHandle)) == 'TMDICHILD') 

   if ! ((nHandle:=GetFocus()) > 0 .and. UPPER(GetClassName(nHandle)) == 'TMDICHILD')  
      
      if ! ((nHandle:=GetParent( GetFocus() )) > 0 .and. UPPER(GetClassName(nHandle)) == 'TMDIFRAME') 

         if ! ((nHandle:=GetActiveWindow()) > 0 .and. UPPER(GetClassName(nHandle)) $ '_TWINDOW_TDIALOG_#32770_') 

            nHandle:=-1
            
         endif
         
      endif
      
   endif
   
endif
if nHandle > 0
   ? nHandle,GetClassName(nHandle)
else
   ? 'Handle not found',GetFocus(),GetParent(GetFocus()),GetActiveWindow()
   ? 'Handle not found',GetClassName(GetFocus()),GetClassName(GetParent(GetFocus())),GetClassName(GetActiveWindow())
endif         
return nHandle
tests with MDI, MDICHILD, WINDOW, DIALOG:

Code: Select all

#include 'mxbase.ch' // FiveWin.ch, etc, etc
//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
function Main()
local oWin

SETKEY(VK_F2, {||WinInfo()})
SETKEY(VK_F3, {||AddWinChild()})
SETKEY(VK_F4, {||MakeWindow()})
SETKEY(VK_F5, {||MakeDialog()})

DEFINE WINDOW oWin TITLE 'Janela MDI' MDI
       @15,10 SAY 'F2 - WinInfo()'     SIZE 100,30
       @18,10 SAY 'F3 - AddWinChild()' SIZE 100,30
       @21,10 SAY 'F4 - MakeWindow()'  SIZE 100,30
       @24,10 SAY 'F5 - MakeDialog()'  SIZE 100,30
       
       //oWin:SetKey( VK_F2,{||ALERT('VK_F2 da janela')})

ACTIVATE WINDOW oWin ON INIT oWin:cTitle:=oWin:cTitle + ' oWin:hWnd=> ' + NTRIM(oWin:hWnd) + ' ClassName=>' + GetClassName(oWin:hWnd) MAXIMIZED 

return nil

//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
function AddWinChild()
static nsNumber:=0
local oWin
 
DEFINE WINDOW oWin TITLE 'Janela MDICHILD # ' + NTRIM(++nsNumber) MDICHILD  COLOR 'N/BG'
       @15,10 BUTTON 'F2 - WinInfo()'     SIZE 100,30
       @18,10 BUTTON 'F3 - AddWinChild()' SIZE 100,30

ACTIVATE WINDOW oWin ON INIT oWin:cTitle:=oWin:cTitle + ' oWin:hWnd=> ' + NTRIM(oWin:hWnd) + ' ClassName=>' + GetClassName(oWin:hWnd)

return nil

//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
function MakeWindow()
local oWin
 
DEFINE WINDOW oWin TITLE 'Janela WINDOW' FROM 5,20 TO 30,100
       @15,10 BUTTON 'F2 - WinInfo()'     SIZE 100,30

ACTIVATE WINDOW oWin ON INIT oWin:cTitle:=oWin:cTitle + ' oWin:hWnd=> ' + NTRIM(oWin:hWnd) + ' ClassName=>' + GetClassName(oWin:hWnd)

return nil

//--------------------------------------------------------------------------
//
//--------------------------------------------------------------------------
function MakeDialog()
local oWin
 
DEFINE DIALOG oWin TITLE 'Janela DIALOG' FROM 5,20 TO 30,100
       @15,10 BUTTON 'F2 - WinInfo()'     SIZE 100,30

ACTIVATE DIALOG oWin ON INIT oWin:cTitle:=oWin:cTitle + ' oWin:hWnd=> ' + NTRIM(oWin:hWnd) + ' ClassName=>' + GetClassName(oWin:hWnd) CENTER

return nil
virtually,
Éric
xHarbour.org + Borland C + FiveWin (2.8/6.12) + Pelles C + HBMake + ADSCDX
São Paulo - Brasil
http://xBaseSuporte.freeforums.org
User avatar
ericmagaldi
Posts: 37
Joined: Tue Feb 20, 2007 9:26 am
Location: São Paulo - Brazil
Contact:

Post by ericmagaldi »

up
virtually,
Éric
xHarbour.org + Borland C + FiveWin (2.8/6.12) + Pelles C + HBMake + ADSCDX
São Paulo - Brasil
http://xBaseSuporte.freeforums.org
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Eric,

What do you need the handle of the active window for ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
ericmagaldi
Posts: 37
Joined: Tue Feb 20, 2007 9:26 am
Location: São Paulo - Brazil
Contact:

Post by ericmagaldi »

Antonio Linares wrote:What do you need the handle of the active window for ?
To take advantage the benefits better OOP, make flexible still more my codes.
As FW doesn't have as obtaining in all of the cases (topic), Objects of the windows and other controls, I will leave in a function all of the objects of the window, but I will need to know Handle of the window activates, and I will return the corresponding object.

Code: Select all

              #xtranslate TMdiChild => MMdiChild
              #xtranslate TMdiFrame => MMdiFrame
              #xtranslate TWindow   => MWindow
              #xtranslate TDialog   => MDialog
              #xtranslate TComboBox => MComboBox
              #xtranslate TGet      => MGet

              Class MMdiChild FROM TMdiChild
              Class MMdiFrame FROM TMdiFrame
              Class MWindow   FROM TWindow
              Class MDialog   FROM TDialog
              Class MComboBox FROM TComboBox
              Class MGet      FROM TGet
In my classes inherited above, I created small improvements that can facilitate procedures basic, tedious and reducing lines of codes considerably, but maintaining the flexibility in the specific cases.
Ex:

Code: Select all

DEFINE DIALOG oDlg // Minha Classe
       oDlg:lGetUpper:=.t.              // Edition Upper ALL Gets Window (e mantem a regra específica)
       oDlg:SetKey( VK_F2, {||Any1()} ) // My method
       oDlg:SetKey( VK_F3, {||Any2()} ) // My method

       ... GET ...1 VALID GetFill()      // As funções aqui tem acesso ao objeto, semelhante ao GetActive() do Clipper
       ... GET ...2
       ... GET ...3 VALID GetFill()      // Obligatory completion
       ... GET ...4
       ... GET ...5 VALID Qualquer()
       ...
ACTIVATE DIALOG oDlg
// OK, Gravar, etc
.. BUTTON ... ACTION oDlg:EvalAllControl() // Main improvement

In the example of calls above, there is at least 3 important resources:
  1. the functions used in Valids, he has access to the current object, aiding to create more independent and intelligent functions.
  2. evaluate all the controls and recursive under the control of a single method, giving automatic focus in the control not assisted (more easiness to the user, avoids to duplicate validations, and it does not depend on the user's sequence.)
  3. Refresh gotten better and really recursive.
  4. Automatic visual indication for the user that there is some rule in the edition (it would perfume, however important)
  5. small improvements in ComboBox
  6. oDlg:CtrlEnableAll()/oDlg:CtrlDisableAll()
    and the one that more the creativity to order, etc
Can I aid myself to Handle in an effective way to return?
virtually,
Éric
xHarbour.org + Borland C + FiveWin (2.8/6.12) + Pelles C + HBMake + ADSCDX
São Paulo - Brasil
http://xBaseSuporte.freeforums.org
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Eric,

> Can I aid myself to Handle in an effective way to return?

Sorry, I don't understand what you mean
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
ericmagaldi
Posts: 37
Joined: Tue Feb 20, 2007 9:26 am
Location: São Paulo - Brazil
Contact:

Post by ericmagaldi »

Antonio Linares wrote:Eric,

> Can I aid myself to Handle in an effective way to return?

Sorry, I don't understand what you mean
Again, I need Handle of the window, this is the subject !!!
virtually,
Éric
xHarbour.org + Borland C + FiveWin (2.8/6.12) + Pelles C + HBMake + ADSCDX
São Paulo - Brasil
http://xBaseSuporte.freeforums.org
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Eric,

Try this:

GetWndDefault():hWnd
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
ericmagaldi
Posts: 37
Joined: Tue Feb 20, 2007 9:26 am
Location: São Paulo - Brazil
Contact:

Post by ericmagaldi »

Antonio Linares wrote:Try this:

GetWndDefault():hWnd
Why does suggest me that??? This function is for the LAST object used by FW.

Antonio, functions of FW don't have that, it should be something similar GetActiveWindow, GetFocus (), etc, see the examples that I passed you.

Remember, I can have several open windows, and any one can be the window activates
virtually,
Éric
xHarbour.org + Borland C + FiveWin (2.8/6.12) + Pelles C + HBMake + ADSCDX
São Paulo - Brasil
http://xBaseSuporte.freeforums.org
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Eric,

What you are looking for is something very relative.
What do you really want:

* the focused control ?
* the container window (or dialog) of that control ?

First you need to know exactly what you want so we can implement it.

You could use GetWndDefault() to stack the current active window and when that windows End()s then pop it from the stack
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
ericmagaldi
Posts: 37
Joined: Tue Feb 20, 2007 9:26 am
Location: São Paulo - Brazil
Contact:

Post by ericmagaldi »

Antonio Linares wrote:What you are looking for is something very relative.
What do you really want:

* the focused control ?
* the container window (or dialog) of that control ?
very simple, as I demonstrated in my first message, I need Handle of the window focused. Look an alternative that I did, above but it is not effective

I will use own stack.
virtually,
Éric
xHarbour.org + Borland C + FiveWin (2.8/6.12) + Pelles C + HBMake + ADSCDX
São Paulo - Brasil
http://xBaseSuporte.freeforums.org
Post Reply