Page 1 of 2
Combobox scroll (function PopupBrowse())
Posted: Thu Dec 10, 2015 9:46 am
by Richard Chidiak
Good morning
I have a combobox redefined from resource, dropdown list.
I need a horizontal scroll on this combobox in addition to the normal vertical scroll.
I have tried cbs-autohscroll style but without success, same with WS_HSCROLL .
Anyone has an idea on what style can display the horizontal scrollbar ?
Thanks for help,
Re: Combobox scroll
Posted: Fri Dec 11, 2015 8:35 am
by Antonio Linares
Richard,
Have you considered to use a GET and a XBrowse together ?
Here you have a function PopupBrowse() that behaves quite similar to a combobox, but you have all the xbrowse possibilities:
Code: Select all
function PopupBrowse( aValue, oGet, bInit )
local oDlg, oBrw
local aPoint := { oGet:nTop + oGet:nHeight, oGet:nLeft }
if oGet:Cargo == nil
aPoint = ClientToScreen( oGet:oWnd:hWnd, aPoint )
DEFINE DIALOG oDlg OF oGet:oWnd STYLE WS_POPUP ;
SIZE 500, 180
ACTIVATE DIALOG oDlg NOWAIT ;
ON INIT oDlg:SetPos( aPoint[ 1 ], aPoint[ 2 ] )
@ 0, 0 XBROWSE oBrw ARRAY aValue AUTOSORT ;
SIZE oDlg:nWidth, oDlg:nHeight OF oDlg PIXEL
oBrw:CreateFromCode()
Eval( bInit, oBrw )
oBrw:PostMsg( WM_SETFOCUS )
oBrw:bKeyDown = { | nKey | If( nKey == VK_RETURN, oDlg:End(),) }
oBrw:bChange = { || oGet:VarPut( oBrw:aCols[ 1 ]:Value ), oGet:Refresh() }
oBrw:bLButtonUp = { | nRow, nCol | If( nRow > oBrw:nHeaderHeight,;
( Eval( oBrw:bChange ), oDlg:End(),;
oGet:oWnd:GoNextCtrl( oGet:hWnd ),;
oGet:Cargo := nil ),) }
oBrw:Seek( oGet:GetText() )
oGet:Cargo = oDlg
oGet:bKeyDown = { | nKey | If( nKey == VK_DOWN, oBrw:GoDown(),),;
If( nKey == VK_UP, oBrw:GoUp(),),;
If( nKey == VK_RETURN, oDlg:End(),), 0 }
oGet:oWnd:bLClicked = { || oDlg:End(), oGet:Cargo := nil }
oGet:oWnd:bMouseWheel = { || oDlg:SetFocus() }
else
oGet:Cargo:End()
oGet:Cargo = nil
endif
return nil
An example of use:
REDEFINE GET oGet VAR ... ;
ID ... OF oDlg ACTION PopupBrowse( aValues, oGet, bInit )
Re: Combobox scroll
Posted: Fri Dec 11, 2015 10:51 am
by Jack
What is this ACTION on a GET ?
I use VALID but never ACTION .
When is it execute ?
Thanks
Re: Combobox scroll
Posted: Fri Dec 11, 2015 6:28 pm
by joseluisysturiz
Jack wrote:What is this ACTION on a GET ?
I use VALID but never ACTION .
When is it execute ?
Thanks
Puedes usarlo con el VALID o ACTION, un pequeño boton que se crea a la derecha del GET y se ejecuta al hacer click alli, saludos...
@ x, y GET oGet VAR cVar.... ;
ACTION PopupBrowse( aValue, oGet, bInit )
Re: Combobox scroll
Posted: Sat Dec 12, 2015 4:59 am
by Richard Chidiak
Antonio
Thanks
I will try and let you know,
Regards
Richard
Re: Combobox scroll
Posted: Sun Dec 20, 2015 1:19 pm
by horacio
Antonio, he probado tu solución y tengo el siguiente problema, cuando abro el combo y hago foco en otro control con el ratón, este no se cierra. Tampoco si presiono el ratón sobre la barra de título del dialogo que contiene el combo. Habrá alguna solución para esto ? Muchísimas gracias.
Saludos
Re: Combobox scroll
Posted: Mon Dec 21, 2015 6:52 am
by Antonio Linares
Horacio,
Aqui tienes una versión mejorada:
Code: Select all
function PopupBrowse( aValue, oGet, bInit )
local oDlg, oBrw
local aPoint := { oGet:nTop + oGet:nHeight, oGet:nLeft }
if oGet:Cargo == nil
aPoint = ClientToScreen( oGet:oWnd:hWnd, aPoint )
DEFINE DIALOG oDlg OF oGet:oWnd STYLE WS_POPUP ;
SIZE 500, 180
ACTIVATE DIALOG oDlg NOWAIT ;
ON INIT oDlg:SetPos( aPoint[ 1 ], aPoint[ 2 ] )
@ 0, 0 XBROWSE oBrw ARRAY aValue AUTOSORT ;
SIZE oDlg:nWidth, oDlg:nHeight OF oDlg PIXEL
oBrw:CreateFromCode()
Eval( bInit, oBrw )
oBrw:PostMsg( WM_SETFOCUS )
oBrw:bKeyDown = { | nKey | If( nKey == VK_RETURN, oDlg:End(), ) }
oBrw:bChange = { || oGet:VarPut( oBrw:aCols[ 1 ]:Value ), oGet:Refresh() }
oBrw:bLButtonUp = { | nRow, nCol | If( nRow > oBrw:nHeaderHeight,;
( Eval( oBrw:bChange ), oDlg:End(),;
oGet:oWnd:GoNextCtrl( oGet:hWnd ),;
oGet:Cargo := nil ),) }
oGet:bLostFocus = { || oGet:Cargo := nil, oDlg:End() }
oGet:oWnd:bGotFocus = { || oGet:Cargo := nil, oDlg:End() }
oBrw:Seek( oGet:GetText() )
oGet:Cargo = oDlg
oGet:bKeyDown = { | nKey | If( nKey == VK_DOWN, oBrw:GoDown(),),;
If( nKey == VK_UP, oBrw:GoUp(),),;
If( nKey == VK_DELETE, ( oGet:VarPut(0), oGet:Refresh(), oDlg:End()),),;
If( nKey == VK_RETURN, oDlg:End(),), 0 }
oGet:oWnd:bLClicked = { || oDlg:End(), oGet:Cargo := nil }
oGet:oWnd:bMouseWheel = { || oDlg:SetFocus() }
else
oGet:Cargo:End()
oGet:Cargo = nil
endif
return nil
Re: Combobox scroll (function PopupBrowse())
Posted: Mon Dec 21, 2015 1:29 pm
by horacio
Antonio, gracias por tu respuesta. He probado esta nueva versión. Ahora si cierra el combo si pico con el ratón en otro control. Solo faltaría que si muevo el dialogo que contiene el combo, este se cierre. Muchísimas gracias.
Saludos
Re: Combobox scroll (function PopupBrowse())
Posted: Mon Dec 21, 2015 4:37 pm
by Antonio Linares
Horacio,
Prueba esta versión mejorada, gracias
Code: Select all
function PopupBrowse( aValue, oGet, bInit )
local oDlg, oBrw
local aPoint := { oGet:nTop + oGet:nHeight, oGet:nLeft }
if oGet:Cargo == nil
aPoint = ClientToScreen( oGet:oWnd:hWnd, aPoint )
DEFINE DIALOG oDlg OF oGet:oWnd STYLE WS_POPUP ;
SIZE 500, 180
ACTIVATE DIALOG oDlg NOWAIT ;
ON INIT oDlg:SetPos( aPoint[ 1 ], aPoint[ 2 ] )
@ 0, 0 XBROWSE oBrw ARRAY aValue AUTOSORT ;
SIZE oDlg:nWidth, oDlg:nHeight OF oDlg PIXEL
oBrw:CreateFromCode()
Eval( bInit, oBrw )
oBrw:PostMsg( WM_SETFOCUS )
oBrw:bKeyDown = { | nKey | If( nKey == VK_RETURN, oDlg:End(), ) }
oBrw:bChange = { || oGet:VarPut( oBrw:aCols[ 1 ]:Value ), oGet:Refresh() }
oBrw:bLButtonUp = { | nRow, nCol | If( nRow > oBrw:nHeaderHeight,;
( Eval( oBrw:bChange ), oDlg:End(),;
oGet:oWnd:GoNextCtrl( oGet:hWnd ),;
oGet:Cargo := nil ),) }
oGet:bLostFocus = { || oGet:Cargo := nil, oDlg:End() }
oGet:oWnd:bGotFocus = { || oGet:Cargo := nil, oDlg:End() }
oGet:oWnd:bMMoved = { || oGet:Cargo := nil, oDlg:End() }
oBrw:Seek( oGet:GetText() )
oGet:Cargo = oDlg
oGet:bKeyDown = { | nKey | If( nKey == VK_DOWN, oBrw:GoDown(),),;
If( nKey == VK_UP, oBrw:GoUp(),),;
If( nKey == VK_DELETE, ( oGet:VarPut(0), oGet:Refresh(), oDlg:End()),),;
If( nKey == VK_RETURN, oDlg:End(),), 0 }
oGet:oWnd:bLClicked = { || oDlg:End(), oGet:Cargo := nil }
oGet:oWnd:bMouseWheel = { || oDlg:SetFocus() }
else
oGet:Cargo:End()
oGet:Cargo = nil
endif
return nil
Re: Combobox scroll (function PopupBrowse())
Posted: Mon Dec 21, 2015 5:21 pm
by horacio
Antonio, no funciona bien. Si muevo el ratón fuera del combo este se cierra. Tampoco trabaja la rueda del ratón cuando el mismo está abierto. La linea que hace fallar es
Code: Select all
oGet:oWnd:bMMoved := { || oGet:Cargo := nil, oDlg:End() }
Muchas Gracias
Saludos
Re: Combobox scroll (function PopupBrowse())
Posted: Mon Dec 21, 2015 5:27 pm
by Antonio Linares
Horacio,
Prueba a cambiar esa línea por esta:
oGet:oWnd:bMoved = { || oGet:Cargo := nil, oDlg:End() }
Re: Combobox scroll (function PopupBrowse())
Posted: Tue Dec 22, 2015 8:44 am
by pgfdz
Hello
Try with this code
A greeting
Code: Select all
#include "fivewin.ch"
function main()
local oWnd, oCbx
local cVar := "Hola"
local aItems := {"Hola","cara","de","bola"}
DEFINE WINDOW oWnd
@ 10, 10 COMBOBOX oCbx VAR cVar ITEMS aItems SIZE 200, 300 PIXEL OF oWnd
ACTIVATE WINDOW oWnd ON INIT SetCbxHScroll( oCbx )
return nil
FUNCTION SetCbxHScroll( oCbx )
SumarEstilo( HWndComboList( oCbx:hWnd ), WS_HSCROLL )
return 0
#pragma BEGINDUMP
#include "windows.h"
#include "hbapi.h"
#include "commctrl.h"
HB_FUNC( SUMARESTILO )
{
HWND hWnd = (HWND) hb_parnl( 1 );
DWORD dwStyle = GetWindowLong( hWnd, GWL_STYLE );
dwStyle |= ((DWORD)hb_parnl(2));
SetWindowLong( hWnd, GWL_STYLE, dwStyle );
}
BOOL SGetComboBoxInfo( HWND hWnd, PCOMBOBOXINFO pcbi )
{
typedef BOOL (CALLBACK* LPFNDLLFUNC)( HWND, PCOMBOBOXINFO );
HINSTANCE hLib;
LPFNDLLFUNC GetComboBoxInfo;
BOOL bRet = FALSE;
hLib = LoadLibrary( "User32.dll" );
if( hLib )
{
GetComboBoxInfo = ((LPFNDLLFUNC) GetProcAddress( hLib, "GetComboBoxInfo" ));
bRet = (BOOL) GetComboBoxInfo( hWnd, pcbi );
FreeLibrary( hLib );
}
return bRet;
}
// Obtener el HWND de la lista desplegable del combobox
HB_FUNC( HWNDCOMBOLIST )
{
COMBOBOXINFO cbi ;
ZeroMemory( &cbi, sizeof( COMBOBOXINFO ) );
cbi.cbSize = sizeof(COMBOBOXINFO);
SGetComboBoxInfo( (HWND) hb_parnl( 1 ), &cbi );
hb_retnl( (LONG)cbi.hwndList ) ;
}
#pragma ENDDUMP
Re: Combobox scroll (function PopupBrowse())
Posted: Tue Dec 22, 2015 9:08 am
by Antonio Linares
function PopupBrowse() has been included in next FWH 15.11
Re: Combobox scroll (function PopupBrowse())
Posted: Tue Dec 22, 2015 11:55 am
by Silvio.Falconi
Antonio,
can you make a small sample to call popbrowse function please ?
Re: Combobox scroll (function PopupBrowse())
Posted: Tue Dec 22, 2015 12:05 pm
by Antonio Linares
Silvio,
REDEFINE GET oGet VAR ... ;
ID ... OF oDlg ACTION PopupBrowse( aValues, oGet, bInit )
aValues can be an array or a recordset