calculate GRID height

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

calculate GRID height

Post by AUGE_OHR »

hi,

i try to calculate Size of GRID ... but something is wrong with my calculation

i use Arial 11 and this line

Code: Select all

   nHeight := ( iMax + 1 ) * 22.3
+1 is need for GRID Header and 22.3 ...
ModiStru1.jpg
ModiStru1.jpg (24.89 KiB) Viewed 2267 times
it seem to work when have < 10 Fields but than GRID is bigger than need :(
so i need a better Way for "calculation" height of GRID.

please help, thx
MODISTRU.ZIP
(1.09 KiB) Downloaded 130 times
have fun
Jimmy
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: calculate GRID height

Post by serge_girard »

Jimmy,

This works with my W7 machine, but when more than 30 or 40 the form height doesn't fit on the screen so the last records can not be seen.

Serge
There's nothing you can do that can't be done...
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: calculate GRID height

Post by AUGE_OHR »

hi,
serge_girard wrote: Tue Feb 04, 2020 8:17 am ... but when more than 30 or 40 the form height doesn't fit on the screen so the last records can not be seen.
that is exact what i wonder when it does not fit any more ... :o

---

i found

Code: Select all

HB_FUNC( GETTEXTHEIGHT )  // returns the Height of a string in pixels
have to try if other Way for calculation
have fun
Jimmy
User avatar
gfilatov
Posts: 1060
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: calculate GRID height

Post by gfilatov »

AUGE_OHR wrote: Tue Feb 04, 2020 10:34 am hi,
...
have to try if other Way for calculation
Hi Jimmy,

Please try the updated sample below: :arrow:

Code: Select all

*+--------------------------------------------------------------------
*+
*+ Source Module => c:\hmg.3.4.4\0\GRIDHIGH\\MODISTRU.PRG
*+
*+    Copyright(C) 1983-2020 by Auge & Ohr
*+
*+    Functions: Procedure main()
*+               Static Procedure SaveCreate()
*+               Static Procedure CloseForm2()
*+
*+       Tables: USE ( cDbf )
*+
*+    Reformatted by Click! 2.05.30 on Feb-4-2020 at  8:34 am
*+
*+--------------------------------------------------------------------

#include "HMG.CH"
#include "Dbstruct.ch"

*+--------------------------------------------------------------------
*+
*+    Procedure main()
*+
*+--------------------------------------------------------------------
*+
PROCEDURE main( cDbf )

LOCAL aStruc, i, iMax
LOCAL aCaption  := { "Name", "Type", "Len", "Dec" }
LOCAL aWide     := { 110, 50, 60, 60 }
LOCAL aItems    := {}
LOCAL nHeight   := 0
LOCAL nTitlebar := GETTITLEHEIGHT()

   default cDBF := "TEST.dbf"

   IF !FILE( cDbf )
      msginfo( "need DBF" )
      RETURN
   ENDIF

   ALTD()
   USE ( cDbf )
   aStruc := DBSTRUCT()
   iMax := LEN( aStruc )
   nHeight := ( iMax + 1 ) * 22.3

   FOR i := 1 TO iMax
      AADD( aItems, { aStruc[ i ] [ DBS_NAME ], ;
                      aStruc[ i ] [ DBS_TYPE ], ;
                      aStruc[ i ] [ DBS_LEN ], ;
                      aStruc[ i ] [ DBS_DEC ] } )
   NEXT

   DEFINE WINDOW Form_2 ;
              AT 0, 0 ;
              WIDTH 330 ;
              HEIGHT nHeight + nTitlebar + 40 + 50 ;
              TITLE cDbf ;
              MAIN ;
              ON RELEASE CloseForm2() ;
              FONT "Arial" ;
              SIZE 11 ;
              NOMINIMIZE ;
              NOMAXIMIZE ;
              NOSIZE

      DEFINE TOOLBAR oTOOLBAR BUTTONSIZE 50, 50 FLAT BORDER

         BUTTON oBtSave ;
                 TOOLTIP "F5: create DBF" ;
                 ACTION SaveCreate()

      END TOOLBAR

      DEFINE GRID Brow_2
         PARENT Form_2
         ROW 10 + 50
         COL 10
         WIDTH 290
         HEIGHT nHeight
         HEADERS aCaption
         WIDTHS aWide
         ITEMS aItems
         FONTNAME "Arial"
         FONTSIZE 11
         VALUE 1
      END GRID
   END WINDOW

   Form_2.Brow_2.height := GetHeght_ListView(Form_2.Brow_2.HANDLE, iMax)

   Form_2.height := Form_2.Brow_2.row + Form_2.Brow_2.height + GetTitleHeight() + 2*GetBorderHeight() + 10
   Form_2.Title := (Form_2.Title) + ' -> # visible rows: ' + hb_ntos(GetNumOfVisibleRows('Brow_2', 'Form_2'))

   ON KEY F5 OF Form_2 ACTION SaveCreate()
   ON KEY ESCAPE OF Form_2 ACTION Form_2.Release

//   Form_2.Brow_2.setfocus
   CENTER WINDOW Form_2
   ACTIVATE WINDOW Form_2

RETURN


Function GetNumOfVisibleRows ( ControlName , ParentForm )
   LOCAL i

   i := GetControlIndex ( ControlName , ParentForm )

Return ListviewGetCountPerPage ( GetControlHandleByIndex( i ) )


FUNCTION GetHeght_ListView( hBrw, nRows )  // height Grid \ Browse on the number of rows
   LOCAL a

   a    := ListViewApproximateViewRect( hBrw, nRows - 1 )  // { Width, Height }
   a[1] += Round( GetBorderWidth () / 2, 0 )               // Width
   a[2] += Round( GetBorderHeight() / 2, 0 )               // Height

RETURN a[2]

 
#pragma BEGINDUMP

#include <mgdefs.h>
#include <commctrl.h>

HB_FUNC( LISTVIEWAPPROXIMATEVIEWRECT )
{
  int iCount = hb_parni( 2 );
  DWORD Rc;

  Rc = ListView_ApproximateViewRect( ( HWND ) hb_parnl( 1 ), -1, -1, iCount );

  hb_reta( 2 );
  HB_STORNI( LOWORD( Rc ), -1, 1 );
  HB_STORNI( HIWORD( Rc ), -1, 2 );
}

#pragma ENDDUMP

*+--------------------------------------------------------------------
*+
*+    Static Procedure SaveCreate()
*+
*+    Called from ( modistru.prg )   2 - procedure main()
*+
*+--------------------------------------------------------------------
*+
STATIC PROCEDURE SaveCreate( cOutPutDBF, aNew, aHead, nRowStart, nRowEnd, nColEnd, lDone, aType )

RETURN

*+--------------------------------------------------------------------
*+
*+    Static Procedure CloseForm2()
*+
*+    Called from ( modistru.prg )   1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
STATIC PROCEDURE CloseForm2()

RETURN

*+ EOF: MODISTRU.PRG
The above code works fine for a DBF with the 32 fields. :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: calculate GRID height

Post by AUGE_OHR »

hi,
gfilatov wrote: Tue Feb 04, 2020 10:40 am Please try the updated sample below: :arrow:
The above code works fine for a DBF with the 32 fields. :idea:
THX for your Solution.

but i wonder that i need so much Code for a "simple" Problem ...
have fun
Jimmy
User avatar
gfilatov
Posts: 1060
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: calculate GRID height

Post by gfilatov »

AUGE_OHR wrote: Tue Feb 04, 2020 10:58 am hi,
gfilatov wrote: Tue Feb 04, 2020 10:40 am Please try the updated sample below: :arrow:
The above code works fine for a DBF with the 32 fields. :idea:
THX for your Solution.

but i wonder that i need so much Code for a "simple" Problem ...
Hi Jimmy,

I had revised the above code and added the two new clauses:
AUTOSIZEHEIGHT <nRow> and AUTOSIZEWIDTH <.T.|.F.>
to a standard Grid control in MiniguiEx. 8-)

The updated program code and a result's screen are below: :arrow:

Code: Select all

*+--------------------------------------------------------------------
*+
*+ Source Module => c:\hmg.3.4.4\0\GRIDHIGH\\MODISTRU.PRG
*+
*+    Copyright(C) 1983-2020 by Auge & Ohr
*+
*+    Functions: Procedure main()
*+               Static Procedure SaveCreate()
*+               Static Procedure CloseForm2()
*+
*+       Tables: USE ( cDbf )
*+
*+    Reformatted by Click! 2.05.30 on Feb-4-2020 at  8:34 am
*+
*+--------------------------------------------------------------------

#include "HMG.CH"
#include "Dbstruct.ch"

*+--------------------------------------------------------------------
*+
*+    Procedure main()
*+
*+--------------------------------------------------------------------
*+
PROCEDURE main( cDbf )

LOCAL aStruc, i, iMax
LOCAL aCaption  := { "Name", "Type", "Len", "Dec" }
LOCAL aWide     := { 110, 50, 60, 60 }
LOCAL aItems    := {}
LOCAL nHeight   := 0
LOCAL nTitlebar := GETTITLEHEIGHT()

   default cDBF := "TEST.dbf"

   IF !FILE( cDbf )
      msginfo( "need DBF" )
      RETURN
   ENDIF

   ALTD()
   USE ( cDbf )
   aStruc := DBSTRUCT()
   iMax := LEN( aStruc )

   FOR i := 1 TO iMax
      AADD( aItems, { aStruc[ i ] [ DBS_NAME ], ;
                      aStruc[ i ] [ DBS_TYPE ], ;
                      aStruc[ i ] [ DBS_LEN ], ;
                      aStruc[ i ] [ DBS_DEC ] } )
   NEXT

   DEFINE WINDOW Form_2 ;
              AT 0, 0 ;
              WIDTH 330 ;
              HEIGHT nHeight + nTitlebar + 40 + 50 ;
              TITLE cDbf ;
              MAIN ;
              ON RELEASE CloseForm2() ;
              FONT "Arial" ;
              SIZE 11 ;
              NOMINIMIZE ;
              NOMAXIMIZE ;
              NOSIZE

      DEFINE TOOLBAR oTOOLBAR BUTTONSIZE 40, 40 FLAT BORDER

         BUTTON oBtSave ;
                 TOOLTIP "F5: create DBF" ;
                 ACTION SaveCreate()

      END TOOLBAR

      DEFINE GRID Brow_2
         PARENT Form_2
         ROW 10 + 50
         COL 10
         AUTOSIZEWIDTH .T.
         AUTOSIZEHEIGHT iMax
         HEADERS aCaption
         WIDTHS aWide
         ITEMS aItems
         FONTNAME "Arial"
         FONTSIZE 11
         VALUE 1
      END GRID
   END WINDOW

   Form_2.height := Form_2.Brow_2.row + Form_2.Brow_2.height + nTitlebar + 2*GetBorderHeight()
   Form_2.width := Form_2.Brow_2.col + Form_2.Brow_2.width + 2*GetBorderWidth()
   Form_2.Title := (Form_2.Title) + ' -> # visible rows: ' + hb_ntos(GetNumOfVisibleRows('Brow_2', 'Form_2'))

   ON KEY F5 OF Form_2 ACTION SaveCreate()
   ON KEY ESCAPE OF Form_2 ACTION Form_2.Release

//   Form_2.Brow_2.setfocus
   CENTER WINDOW Form_2
   ACTIVATE WINDOW Form_2

RETURN


Function GetNumOfVisibleRows ( ControlName , ParentForm )
   LOCAL i

   i := GetControlIndex ( ControlName , ParentForm )

Return ListviewGetCountPerPage ( GetControlHandleByIndex( i ) )

*+--------------------------------------------------------------------
*+
*+    Static Procedure SaveCreate()
*+
*+    Called from ( modistru.prg )   2 - procedure main()
*+
*+--------------------------------------------------------------------
*+
STATIC PROCEDURE SaveCreate( cOutPutDBF, aNew, aHead, nRowStart, nRowEnd, nColEnd, lDone, aType )

RETURN

*+--------------------------------------------------------------------
*+
*+    Static Procedure CloseForm2()
*+
*+    Called from ( modistru.prg )   1 - procedure main()
*+
*+--------------------------------------------------------------------
*+
STATIC PROCEDURE CloseForm2()

RETURN

*+ EOF: MODISTRU.PRG
Attachments
test.png
test.png (76.84 KiB) Viewed 2159 times
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: calculate GRID height

Post by AUGE_OHR »

gfilatov wrote: Fri Feb 14, 2020 9:15 am I had revised the above code and added the two new clauses:
AUTOSIZEHEIGHT <nRow> and AUTOSIZEWIDTH <.T.|.F.>
to a standard Grid control in MiniguiEx. 8-)

The updated program code and a result's screen are below: :arrow:
that looks fine, THX

i have try to compile your HB_FUNC( ListViewApproximateViewRect ) with HMG include mgdefs.h.
it give me some Error ... about Reference ... :(

Question : can i use those HB_FUNC with HMG :?:
have fun
Jimmy
Post Reply