/*#################################################################################################
# $Id: $
# Lira Lira Oscar Joel [oSkAr]
# Proyecto : CommCtrl32
# Archivo : comboex.prg
# Creacion : 07/09/2006, 10:39
# Actualizacion: :>: 07/14/2006 13:14
#################################################################################################*/
/*
20060714 - Modificacion necesaria en la clase TWindow y TDialog Metodo Command
Para el correcto funcionamiento de este control es necesario modificar la clase TWindow y TDialog
de Fivewin para direccionar las notificaciones al control, la modificacion es la siguiente
en el metodo Command( nWParam, nLParam ), y declarar la variable nControl como local en el mismo
metodo
case GetClassName( hWndCtl ) == "ToolbarWindow32"
oWndFromHwnd( hWndCtl ):Command( nWParam, nLParam )
// Inicia Modificacion
// Trasladamos los mensajes al control ComboBoxEx32
CASE GetClassName( hWndCtl ) == "ComboBoxEx32"
nControl := AScan( ::aControls, { |oControl| oControl:hWnd == hWndCtl } )
IF nControl > 0
::aControls[ nControl ]:Command( nWParam, nLParam )
ENDIF
// Fin de la modificacion
case hWndCtl != 0
*/
#include "Fivewin.ch"
#define CB_GETCOUNT 0x0146
#define CB_GETCURSEL 0x0147
#define CB_SETCURSEL 0x014E
#define CB_SHOWDROPDOWN 0x014F
#define CBEM_SETIMAGELIST 0x0402
#define CBEM_GETEDITCONTROL 0x0407
#define CBN_SELCHANGE 0x0001
#define SWP_NOACTIVATE 0x000G
#define WM_SETTEXT 0x000C
/*-----------------------------------------------------------------------------------------------*/
FUNCTION MainEx()
LOCAL nOp
nOp := MsgList( { "En una Ventana desde codigo" ,;
"En un Dialogo desde codigo" ,;
"En un Dialogo desde recursos" },;
"DEMO TComboBoxEx by oSkAr" )
DO CASE
CASE nOp == 1
Test01()
CASE nOp == 2
Test02()
CASE nOp == 3
Test03()
ENDCASE
MsgInfo( "Gracias por testear este control Dudas o comentarios," + CRLF +;
"envia un email a oscarlira78@hotmail.com" + CRLF +;
"http://oskar.sytes.net" )
RETURN NIL
/*-----------------------------------------------------------------------------------------------*/
FUNCTION Test01()
LOCAL oWnd, oCbx
DEFINE Window oWnd
oWnd:SetText( "oSkAr ComboBoxEx Demo" )
oCbx := TComboboxEx():New( oWnd, 50, 10, 300, 40 )
ConfiguraCbx( oCbx )
oWnd:bRClicked := { || Alert( oCbx:nAt ) }
Activate Window oWnd
RETURN NIL
/*-----------------------------------------------------------------------------------------------*/
FUNCTION Test02()
LOCAL oDlg, oCbx
DEFINE Dialog oDlg
Activate Dialog oDlg Center ON Init;
( oCbx := TComboboxEx():New( oDlg, 50, 10, 300, 40 ),;
ConfiguraCbx( oCbx ) )
RETURN NIL
/*-----------------------------------------------------------------------------------------------*/
FUNCTION Test03()
LOCAL oDlg, oCbx
DEFINE Dialog oDlg Resource "DL_COMBOEX"
Activate Dialog oDlg ON Init ;
( oCbx := TComboBoxEx():New( oDlg,,,,,,,101 ),;
ConfiguraCbx( oCbx ) )
RETURN NIL
/*-----------------------------------------------------------------------------------------------*/
FUNCTION ConfiguraCbx( oCbx )
WITH OBJECT oCbx
:AddImage( 101 )
:AddImage( 102 )
:AddImage( 103 )
:SetImageList()
:AddItem( "The" , 0, 0 )
:AddItem( "Fivewin", 1, 1 )
:AddItem( "Power" , 2, 2 )
:AddItem( "Test" , 0, 0 )
:AddItem( "by" , 1, 1 )
:AddItem( "oSkAr" , 2, 2 )
:Activate()
:bChange := { || MsgInfo( oCbx:cVar ) }
END
RETURN NIL
/*-----------------------------------------------------------------------------------------------*/
CLASS TComboBoxEx FROM TControl
DATA nTop, nLeft, nWidth, nHeight
DATA nBmpHeight
DATA nBmpWidth
DATA oImageList
DATA aTags INIT {}
DATA hGet
DATA lResource INIT .T.
METHOD New() CONSTRUCTOR
METHOD AddItem()
METHOD AddImage()
METHOD SetImageList() INLINE ::SendMsg( CBEM_SETIMAGELIST, 0, ::oImageList:hImageList )
METHOD Count() INLINE ::SendMsg( CB_GETCOUNT , 0, 0 )
METHOD Activate() INLINE IF( !::lResource, SetWindowPos( ::hWnd, NIL, ::nTop, ::nLeft, ::nWidth, ::nHeight, SWP_NOACTIVATE ), NIL )
METHOD nAt( nPos ) SETGET
METHOD ShowDropDown( lShow ) INLINE IF( Empty( lShow ), lShow := .T., NIL ), ::SendMsg( CB_SHOWDROPDOWN, lShow )
METHOD cVar( cText ) SETGET
METHOD Change() INLINE IF( !Empty( ::bChange ), Eval( ::bChange ), NIL )
METHOD Command()
ENDCLASS
/*-----------------------------------------------------------------------------------------------*/
METHOD New( oWnd, nTop, nLeft, nHeight, nWidth, nBmpWidth, nBmpHeight, nId )
LOCAL oImageList, aRect, lResource, aRect2
DEFAULT nTop := 000,;
nLeft := 000,;
nWidth := 100,;
nHeight := 100,;
nBmpWidth := 016,;
nBmpHeight := 016
IF Empty( nId )
::lResource := .F.
nId := ::GetNewId()
ENDIF
::oWnd := oWnd
::nTop := nTop
::nLeft := nLeft
::nWidth := nHeight
::nBmpWidth := nBmpWidth
::nBmpHeight := nBmpHeight
::nId := nId
::oImageList := TImageList():New( ::nBmpWidth, ::nBmpHeight )
IF! Empty( oWnd:hWnd )
IF !::lResource
::hWnd := CBExCreate( ::oWnd:hWnd, ::nId, GetInstance() )
ELSE
::hWnd := GetDlgItem( ::oWnd:hwnd, nId )
ENDIF
::hGet := ::SendMsg( CBEM_GETEDITCONTROL )
::oWnd:AddControl( SELF )
ELSE
Alert( "De momento debes de iniciar el control en el on init del dialogo" )
ENDIF
RETURN SELF
/*-----------------------------------------------------------------------------------------------*/
METHOD AddImage( cResource, cTag )
DEFAULT cTag := cResource
::oImageList:AddMasked( TBitmap():Define( cResource, , ::oWnd ), nRGB( 255, 0, 255 ) )
AAdd( ::aTags, cTag )
RETURN NIL
/*-----------------------------------------------------------------------------------------------*/
METHOD AddItem( cItem, nImage, nIndent )
DEFAULT cItem := "",;
nImage := 0 ,;
nIndent := 0
IF ValType( nImage ) == "C"
nImage := AScan( ::aTags, { |cTag| cTag = nImage } )
ENDIF
CBExAddItem( ::hWnd, cItem, nImage, nIndent, ::Count() )
RETURN NIL
/*-----------------------------------------------------------------------------------------------*/
METHOD nAt( nItem )
IF PCount() > 0
RETURN ::SendMsg( CB_SETCURSEL, nItem - 1, 0 )
ENDIF
RETURN ::SendMsg( CB_GETCURSEL, 0, 0 ) + 01
/*-----------------------------------------------------------------------------------------------*/
METHOD cVar( cText )
LOCAL nAt
IF PCount() > 0
RETURN ::SendMsg( WM_SETTEXT, 0, cText )
ENDIF
nAt := ::nAt
IF nAt > 0
RETURN CBExGetTlbText( ::hWnd, ::nAt - 1 )
ENDIF
RETURN ""
/*-----------------------------------------------------------------------------------------------*/
METHOD Command( nWParam, nLParam )
LOCAL nCode
nCode = nHiWord( nWParam )
DO CASE
CASE nCode == CBN_SELCHANGE
::Change()
ENDCASE
RETURN NIL
/*-----------------------------------------------------------------------------------------------*/
#pragma BEGINDUMP
#include <windows.h>
#include <commctrl.h>
#include "hbapi.h"
/*--------------------------------------------------------------------------------------------*/
HB_FUNC( CBEXCREATE ){ //hWnd, nId, hInstance
HWND hWnd;
hWnd = CreateWindowEx( 0, WC_COMBOBOXEX, (LPSTR) NULL,
WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWNLIST,
0, 0, 0, 100,
(HWND) hb_parnl( 1 ),
(HMENU) hb_parnl( 2 ),
(HINSTANCE) hb_parnl( 3 ),
NULL);
hb_retnl( (long) hWnd );
}
/*--------------------------------------------------------------------------------------------*/
HB_FUNC( CBEXADDITEM ){ // hwndCB, cItem, nImage, nIndent, nIndex
COMBOBOXEXITEM cbei;
cbei.iItem = hb_parni( 5 );
cbei.pszText = hb_parc( 2 );
cbei.cchTextMax = sizeof( hb_parc( 2 ) );
cbei.iImage = hb_parni( 3 );
cbei.iSelectedImage = hb_parni( 3 );
cbei.iIndent = hb_parni( 4 );
cbei.mask = CBEIF_TEXT | CBEIF_INDENT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE;
hb_retni( SendMessage( (HWND) hb_parnl( 1 ),CBEM_INSERTITEM,0,(LPARAM)&cbei) );
}
/*--------------------------------------------------------------------------------------------*/
HB_FUNC( CBEXGETTLBTEXT ){ //hWndCB, nItem
char cBuffer[255];
SendMessage( (HWND)hb_parnl( 1 ), CB_GETLBTEXT, hb_parni( 2 ), (LPARAM)&cBuffer );
hb_retc( cBuffer );
}
#pragma ENDDUMP
/*-----------------------------------------------------------------------------------------------*/