Page 1 of 2
Read Handle of any type Window ACTIVE
Posted: Mon Apr 21, 2008 4:49 pm
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
Posted: Mon Apr 21, 2008 5:09 pm
by Antonio Linares
Eric,
? GetParent( GetFocus() )
Posted: Mon Apr 21, 2008 5:36 pm
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
Posted: Mon Apr 21, 2008 7:40 pm
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
Posted: Mon Apr 21, 2008 7:53 pm
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.
Posted: Mon Apr 21, 2008 10:31 pm
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
Posted: Wed Apr 23, 2008 7:38 pm
by ericmagaldi
up
Posted: Wed Apr 23, 2008 9:24 pm
by Antonio Linares
Eric,
What do you need the handle of the active window for ?
Posted: Thu Apr 24, 2008 4:26 pm
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:
- the functions used in Valids, he has access to the current object, aiding to create more independent and intelligent functions.
- 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.)
- Refresh gotten better and really recursive.
- Automatic visual indication for the user that there is some rule in the edition (it would perfume, however important)
- small improvements in ComboBox
- 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?
Posted: Thu Apr 24, 2008 5:06 pm
by Antonio Linares
Eric,
> Can I aid myself to Handle in an effective way to return?
Sorry, I don't understand what you mean
Posted: Thu Apr 24, 2008 5:34 pm
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 !!!
Posted: Thu Apr 24, 2008 5:46 pm
by Antonio Linares
Eric,
Try this:
GetWndDefault():hWnd
Posted: Thu Apr 24, 2008 6:02 pm
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
Posted: Thu Apr 24, 2008 6:28 pm
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
Posted: Thu Apr 24, 2008 6:52 pm
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.