EditBox control: increase capacity

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: EditBox control: increase capacity

Post by srvet_claudio »

Hi all.
The final solution is more simpler than what I said in the previous post.

In source file: c_windows.c you change the original GETWINDOWTEXT function for this function:

Code: Select all

HB_FUNC ( GETWINDOWTEXT )
{
   int iLen = GetWindowTextLength((HWND) hb_parnl (1));
   TCHAR *cText = (TCHAR*) hb_xgrab((iLen+1) * sizeof(TCHAR));
   GetWindowText((HWND) hb_parnl (1), (LPTSTR) cText, (iLen+1));
   HMG_retc( cText );
   hb_xfree( cText );
}
and re-build the library.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

EditBox control: increase capacity

Post by Pablo César »

Thank you Dr. Soto ! Working properly.

GETWINDOWTEXT function shorter and better !

I will announce in the other forum your patch for fix and for next releases. Many tks
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
Carlos Britos
Posts: 245
Joined: Sat Aug 02, 2008 5:03 pm

Re: EditBox control: increase capacity

Post by Carlos Britos »

Hi Claudio
I found a couple of problems in the editbox.
With increasing text size caretPos not return the real value.
The overwrite mode is not working.
Everything seems to be related to EM_GETSEL (32 bit). I don't have it very clear.
I don't know how to increase the limit of EM_GETSEL.
It wasn't tested yet with your last function.

Lamento no poder ayudar
Regards/Saludos, Carlos (bcd12a)
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: EditBox control: increase capacity

Post by srvet_claudio »

Carlos Britos wrote:Hi Claudio
I found a couple of problems in the editbox.
With increasing text size caretPos not return the real value.
The overwrite mode is not working.
Everything seems to be related to EM_GETSEL (32 bit). I don't have it very clear.
I don't know how to increase the limit of EM_GETSEL.
It wasn't tested yet with your last function.

Lamento no poder ayudar
Carlos thanks for reporting this bug.

In source file: h_controlmisc.prg you change the original _GetCaretPos function for this function:

Code: Select all

*-----------------------------------------------------------------------------*
Function _GetCaretPos ( ControlName , FormName )
*-----------------------------------------------------------------------------*
Local i, nStart, nEnd
   i := GetControlIndex ( ControlName, FormName )
   If i == 0
      Return 0
   EndIf
   HMG_SendMessage ( _HMG_SYSDATA [3] [i] , EM_GETSEL, @nStart, @nEnd )
Return nEnd

In source file: c_windows.c your add this function:

Code: Select all

HB_FUNC (HMG_SENDMESSAGE)
{  HWND hWnd   = (HWND) hb_parnl(1);
   UINT nMsg   = (UINT) hb_parnl(2);
   LONG wParam = (LONG) hb_parnl(3);
   LONG lParam = (LONG) hb_parnl(4);
   LONG lResult;

   lResult = (LONG) SendMessage (hWnd, nMsg, (WPARAM) &wParam, (LPARAM) &lParam);
   hb_retnl ((LONG) lResult);

   if (HB_ISBYREF(3))
       hb_stornl ((LONG) wParam, 3);
   if (HB_ISBYREF(4))
       hb_stornl ((LONG) lParam, 4);
}
Best Regards,
Claudio
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

EditBox control: increase capacity

Post by Pablo César »

Hi Claudio,

changes were made and rebuilded LIB, but overwrite mode is still not working. :(
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: EditBox control: increase capacity

Post by srvet_claudio »

Pablo César wrote:but overwrite mode is still not working. :(
Sorry Pablo, but I not understand what you said.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

EditBox control: increase capacity

Post by Pablo César »

Me refiero que cuando editamos dentro del EditBox, mismo que presionemos la tecla insert, no difiere el comportamiento entre sobre-escribir um texto ya existe y el modo de insercion de texto. Para que puedas entender mejor Claudio, fijate en este link (ejecutable y fuentes):

How do I introduce insert/overwrite mode in edit control ?
Carlos Britos wrote:The overwrite mode is not working.
Creo que esto nunca funcionó en el EditBox de HMG. Solo vuelvo a exponer lo que Carlos se referia. Seria importante como nueva implementacion y no como correccion.

-=-

I mean that when you edit within the EditBox, even we press the insert key, no different behavior between um overwrite text already exists and the text insertion mode. So you can better understand Claudio and notice in this link (executable and source)
Carlos Britos wrote:The overwrite mode is not working.
I think this never worked in the EditBox HMG. Just back to expose what Carlos was referring. It would be important as a new implementation and not as correction of it.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: EditBox control: increase capacity

Post by srvet_claudio »

Pablo César wrote:I think this never worked in the EditBox HMG. Just back to expose what Carlos was referring. It would be important as a new implementation and not as correction of it.
Ok now I understand, the problem is that EditBox control does not support these functions, you must be implemented to "lung".
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
Carlos Britos
Posts: 245
Joined: Sat Aug 02, 2008 5:03 pm

Re: EditBox control: increase capacity

Post by Carlos Britos »

srvet_claudio wrote:

Code: Select all

HB_FUNC (HMG_SENDMESSAGE)
Best Regards,
Claudio
Hi Claudio
This code works ok, thanks Maestro.
Regards/Saludos, Carlos (bcd12a)
Carlos Britos
Posts: 245
Joined: Sat Aug 02, 2008 5:03 pm

Re: EditBox control: increase capacity

Post by Carlos Britos »

srvet_claudio wrote:
Pablo César wrote:I think this never worked in the EditBox HMG. Just back to expose what Carlos was referring. It would be important as a new implementation and not as correction of it.
Ok now I understand, the problem is that EditBox control does not support these functions, you must be implemented to "lung".
Hi
Can anyone test this code?

Code: Select all

/*
 * HMG - Harbour Win32 GUI library Demo
 *
 * Copyright 2010 Roberto Lopez <mail.box.hmg@gmail.com>
 * http://www.hmgforum.com//
*/

#include "hmg.ch"

Function Main

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 HEIGHT 480 ;
		TITLE 'HMG Demo' ;
		ICON 'DEMO.ICO' ;
		MAIN

		@ 30,10 EDITBOX Edit_1 ;
			WIDTH 410 ;
			HEIGHT 140 ;
         VALUE 'EditBox!!'

      SendMessage (GetControlHandle("Edit_1","Form_1"), 197, 0, 0 )

		DEFINE BUTTON D
			ROW	250
			COL	290
			WIDTH	130
         CAPTION  '_GetCaretPos'
         ACTION   msginfo( hb_NtoS( _GetCaretPos( "Edit_1", "Form_1" ) ) )

		END BUTTON

	END WINDOW

	Form_1.Center()

	Form_1.Activate()

Return Nil



*-----------------------------------------------------------------------------*
Function _GetCaretPos ( ControlName , FormName )
*-----------------------------------------------------------------------------*
Local i, nStart, nEnd
   i := GetControlIndex ( ControlName, FormName )
   If i == 0
      Return 0
   EndIf

   HMG_SendMessage ( _HMG_SYSDATA [3] [i] , 176, @nStart, @nEnd )
Return nEnd



#pragma BEGINDUMP

#include <windows.h>
#include "hbapi.h"


HB_FUNC (HMG_SENDMESSAGE)
{  HWND hWnd   = (HWND) hb_parnl(1);
   UINT nMsg   = (UINT) hb_parnl(2);
   LONG wParam = (LONG) hb_parnl(3);
   LONG lParam = (LONG) hb_parnl(4);
   LONG lResult;

   lResult = (LONG) SendMessage (hWnd, nMsg, (WPARAM) &wParam, (LPARAM) &lParam);
   hb_retnl ((LONG) lResult);

   if (HB_ISBYREF(3))
       hb_stornl ((LONG) wParam, 3);
   if (HB_ISBYREF(4))
       hb_stornl ((LONG) lParam, 4);
}

#include "SET_COMPILE_HMG_UNICODE.ch"
#include "HMG_UNICODE.h"




#define _WIN32_IE      0x0500
#define HB_OS_WIN_32_USED
#include <shlobj.h>

#include <windows.h>
#include <commctrl.h>
#include "hbapi.h"
#include "hbvm.h"
#include "hbstack.h"
#include "hbapiitm.h"
#include "winreg.h"
#include "tchar.h"


LRESULT APIENTRY SubClassFunc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );

static WNDPROC lpfnOldWndProc;

HB_FUNC( INITEDITBOX )
{

   HWND hwnd;
   HWND hbutton;
   int Style ;

   hwnd = (HWND) hb_parnl (1);

   Style = ES_MULTILINE | ES_WANTRETURN | WS_CHILD ;

   if ( hb_parl (10) )
   {
      Style = Style | ES_READONLY ;
   }

   if ( ! hb_parl (11) )
   {
      Style = Style | WS_VISIBLE ;
   }

   if ( ! hb_parl (12) )
   {
      Style = Style | WS_TABSTOP ;
   }

   if ( ! hb_parl (13) )
   {
      Style = Style | WS_VSCROLL  ;
   }
   else
   {
      Style = Style | ES_AUTOVSCROLL ;
   }

   if ( ! hb_parl (14) )
   {
      Style = Style | WS_HSCROLL ;
   }

   hbutton = CreateWindowEx( WS_EX_CLIENTEDGE, _TEXT("EDIT"), _TEXT(""),
   Style ,
   hb_parni(3), hb_parni(4) , hb_parni(5), hb_parni(6) ,
   hwnd,(HMENU)hb_parni(2) , GetModuleHandle(NULL) , NULL ) ;

   SendMessage ( hbutton , (UINT)EM_LIMITTEXT ,(WPARAM) hb_parni(9) , (LPARAM) 0 ) ;

   lpfnOldWndProc = (WNDPROC) SetWindowLong( (HWND) hbutton, GWL_WNDPROC, (LONG) SubClassFunc);

   hb_retnl ( (LONG) hbutton );

}


LRESULT APIENTRY SubClassFunc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{

   switch( msg )
   {
      case WM_CHAR:                               //
         if ( ( ! GetKeyState( VK_INSERT ) == 0 ) && ( wParam != VK_RETURN ) && ( wParam != VK_BACK ) )
            SendMessage( hWnd, WM_KEYDOWN, VK_DELETE, 0 ) ;
         break;

      return CallWindowProc( lpfnOldWndProc, hWnd, 0, 0, 0 ) ;
   }
   return CallWindowProc( lpfnOldWndProc, hWnd, msg, wParam, lParam ) ;
}

#pragma ENDDUMP


Regards/Saludos, Carlos (bcd12a)
Post Reply