Windows to small ?

Windows to small ?

Postby Jimmy » Wed Jul 27, 2022 4:08 pm

hi,

i try to place 2 x Control into Window but they do not "fit"

Code: Select all  Expand view  RUN
#include "fivewin.ch"

PROCEDURE Main()
LOCAL oWnd, oSay1, oSay2

   DEFINE WINDOW oWnd FROM 0, 0 TO 600, 800 PIXEL TITLE "TVIP"
       oSay1 := TSay():new(0,000,{ || "Hello" },oWnd,,,.T.,,.T.,.T.,,,400,600 )
       oSay2 := TSay():new(0,400,{ || "World" },oWnd,,,.T.,,.T.,.T.,,,400,300 )
#IFDEF __HMG__
   END WINDOW
#ENDIF
   ACTIVATE WINDOW oWnd CENTERED
RETURN

oSay2 are not full "fit" oWnd as oWnd is about 16 Pixel "to samll" ( do size on right site to see Frame of oSay2 )

what i´m doing wrong :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Windows to small ?

Postby nageswaragunupudi » Thu Jul 28, 2022 1:54 pm

Code: Select all  Expand view  RUN
function Main()

   local oWnd, oSay1, oSay2, oRect, nSayHt, nSayWd

   DEFINE WINDOW oWnd FROM 0,0 TO 400,600 PIXEL

   oRect    := oWnd:GetCliRect()
   nSayHt   := oRect:nHeight / 2
   nSayWd   := oRect:nWidth

   @      0,0 SAY oSay1 PROMPT "Hello" SIZE nSayWd,nSayHt PIXEL OF oWnd COLOR CLR_WHITE,CLR_BLUE  RIGHT
   @ nSayHt,0 SAY oSay2 PROMPT "World" SIZE nSayWd,nSayHt PIXEL OF oWnd COLOR CLR_WHITE,CLR_GREEN RIGHT

   ACTIVATE WINDOW oWnd CENTERED

return nil
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Windows to small ?

Postby Jimmy » Thu Jul 28, 2022 10:43 pm

hi,

your Sample want 400,600 but got 394,587

start App
press ALT Print-Screen
open Windows Paint and press CTRL + V

now Paint will show you Size of Bitmap

so why is a WINDOWS by FiveWin "to small" :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Windows to small ?

Postby nageswaragunupudi » Fri Jul 29, 2022 4:16 am

Let us leave FiveWin for a moment.

When we create a Window, we specify outer bounds of the Window. This is the total area occupied by the window on the screen. For this purpose, we can use windows functions CreateWindow(...) or CreateWindowEx(...), either ANSI/WIDE.

https://docs.microsoft.com/en-us/window ... atewindowa

https://docs.microsoft.com/en-us/window ... ewindowexa

The parameters x,y,nwidth,nheight define the outer coordinates of the window.

The total area of the Window consists of Client Area and non-client area.

Non client area consists of the space occupied by the title bar, menu bar (if any) and other parts of the window's border. Remaining area is the client area. Extent of the client and non-client areas depend on the style, theme, menu, etc of the window.

We can paint in the Client Area only.
To know what is the client area, we use the windows function:
GetClientArea( hWnd, lpRect )
Obviously the Client Area is smaller than the Total Area.

This is exactly the same when using FWH.
DEFINE WINDOW creates a window using either CreateWindowA() or CreateWindowExW() depending on whether the application is ANSI or Unicode.

We can use simplified functions of FWH:
GetClientArea( hWnd ) --> aRect
oWnd:GetCliRect() --> oRect
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Windows to small ?

Postby nageswaragunupudi » Fri Jul 29, 2022 4:16 am

Let us leave FiveWin for a moment.

When we create a Window, we specify outer bounds of the Window. This is the total area occupied by the window on the screen. For this purpose, we can use windows functions CreateWindow(...) or CreateWindowEx(...), either ANSI/WIDE.

https://docs.microsoft.com/en-us/window ... atewindowa

https://docs.microsoft.com/en-us/window ... ewindowexa

The parameters x,y,nwidth,nheight define the outer coordinates of the window.

The total area of the Window consists of Client Area and non-client area.

Non client area consists of the space occupied by the title bar, menu bar (if any) and other parts of the window's border. Remaining area is the client area. Extent of the client and non-client areas depend on the style, theme, menu, etc of the window.

We can paint in the Client Area only.
To know what is the client area, we use the windows function:
GetClientArea( hWnd, lpRect )
Obviously the Client Area is smaller than the Total Area.

This is exactly the same when using FWH.
DEFINE WINDOW creates a window using either CreateWindowA() or CreateWindowExW() depending on whether the application is ANSI or Unicode.

We can use simplified functions of FWH:
GetClientArea( hWnd ) --> aRect
oWnd:GetCliRect() --> oRect
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Windows to small ?

Postby Jimmy » Fri Jul 29, 2022 9:28 pm

hi,

thx for Answer.

i do NOT talk about Client Area.

so your Function :
nageswaragunupudi wrote:
Code: Select all  Expand view  RUN
GetClientArea( hWnd ) --> aRect
oWnd:GetCliRect() --> oRect

have nothing to do with my "Problem"

---

please try
Code: Select all  Expand view  RUN
start App
press ALT Print-Screen
open Windows Paint and press CTRL + V

now Paint will show you Size of Bitmap == "real" SIZE of WINDOW

Result of WINDOW is not as expect ...
what i´m doing wrong with FiveWin :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Windows to small ?

Postby nageswaragunupudi » Sun Jul 31, 2022 3:07 am

My replies were in response to your first post. You have created controls with the same width as the total width of the window and incorrectly concluded that window is "too small".

Next:
now Paint will show you Size of Bitmap == "real" SIZE of WINDOW

Not correct.

The window is created by Windows OS. (API CreateWindow(...))
The window is displayed on the screen and managed by Windows OS.
So, the most reliable way of ascertaining the accurate width and height of the window is to ask the Windows OS itself and get the authentic information from the horse's mouth, by using the API call
Code: Select all  Expand view  RUN

GetWindowRect( hWnd, lpRect );
width = rct.right - rct.left;
height= rct.bottom - rct.top;
 


Here is a sample showing real width and height of window, as ascertained from Windows OS itself.
Code: Select all  Expand view  RUN

#include "fivewin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd

   oWnd:nWidth    := 300
   oWnd:nHeight   := 200

   oWnd:bPainted := <||
      local aSize := GetWndSize( oWnd:hWnd )
      oWnd:SayText( "Width  : " + hb_ntoc( aSize[ 1 ] ) + CRLF + ;
                    "Height : " + hb_ntoc( aSize[ 2 ] ) )
      return nil
      >

   ACTIVATE WINDOW oWnd CENTERED

return nil

#pragma BEGINDUMP

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

HB_FUNC_STATIC( GETWNDSIZE )     //  hWnd  -->  { nWidth, nHeight }
{
   HWND hWnd = ( HWND ) hb_parnl( 1 );

   RECT rct;

   rct.top    = 0;
   rct.left   = 0;
   rct.bottom = 0;
   rct.right  = 0;

   if( hWnd )
      GetWindowRect( hWnd, &rct );

   hb_reta( 2 );
   hb_storvni( rct.right - rct.left, -1, 1 );
   hb_storvni( rct.bottom - rct.top, -1, 2 );
}

#pragma ENDDUMP
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Windows to small ?

Postby Jimmy » Sun Jul 31, 2022 5:17 am

hi,

you are right that i have 2 x 400 Size "inside" which must be some "Frame" smaller.

but WINDOW is "smaller" under FiverWin than under Xbase++ or HMG :!:

i have not made RULER under FiveWin yet but here are HMG Code
Code: Select all  Expand view  RUN
//////////////////////////////////////////////////////////////////////
//
//  hruler.prg
//
//  Contents:
//      Draws a horizontal ruler marked every 5 pixels on the screen
//      Units are Top-Down Library columns
//      Black line at each column, blue line at midcolumn
//
//////////////////////////////////////////////////////////////////////

#include "hmg.ch"

*+--------------------------------------------------------------------
*+
*+    Function MAIN()
*+
*+--------------------------------------------------------------------
*+
PROCEDURE MAIN
Local aDesk := GetDesktopArea()
Local nDeskWidth  := aDesk[3] - aDesk[1]
LOCAL nDeskHeight := aDesk[4] - aDesk[2]

   DEFINE WINDOW Win1 ;
           AT 0, 0 ;
           WIDTH nDeskWidth ;
           HEIGHT 100 ;
           TITLE "Ruler" ;
           ICON "MYHICO" ;
           MAIN ;
           NOMAXIMIZE ;
           NOMINIMIZE ;
           NOSIZE ;
           ON INIT DoInit() ;
           ON PAINT Proc_ON_PAINT()

      DEFINE CONTEXT MENU OF Win1
            MENUITEM " 10 %" ACTION SetTransparency( 10)
            MENUITEM " 20 %" ACTION SetTransparency( 20)
            MENUITEM " 30 %" ACTION SetTransparency( 30)
            MENUITEM " 40 %" ACTION SetTransparency( 40)
            MENUITEM " 50 %" ACTION SetTransparency( 50)
            MENUITEM " 60 %" ACTION SetTransparency( 60)
            MENUITEM " 70 %" ACTION SetTransparency( 70)
            MENUITEM " 80 %" ACTION SetTransparency( 80)
            MENUITEM " 90 %" ACTION SetTransparency( 90)
            MENUITEM "100 %" ACTION SetTransparency(100)
        END MENU

   //         DEFINE STATUSBAR
   //             DATE
   //             CLOCK
   //         END STATUSBAR

   END WINDOW

   CENTER WINDOW Win1
   ACTIVATE WINDOW Win1

RETURN

STATIC PROCEDURE SetTransparency(nIn)
LOCAL nValue := 255/100
   ThisWindow.AlphaBlendTransparent := INT(nValue * nIn)
RETURN


*+--------------------------------------------------------------------
*+
*+    Procedure DoInit()
*+
*+    Called from ( hruler.prg )   1 - function main()
*+
*+--------------------------------------------------------------------
*+
STATIC PROCEDURE DoInit()
LOCAL nValue := 255/100
   ThisWindow.AlphaBlendTransparent := INT(nValue * 70)
RETURN

*+--------------------------------------------------------------------
*+
*+    Procedure Proc_ON_PAINT()
*+
*+    Called from ( hruler.prg )   1 - function main()
*+
*+--------------------------------------------------------------------
*+
STATIC PROCEDURE Proc_ON_PAINT

LOCAL Width  := BT_ClientAreaWidth( "Win1" )
LOCAL Height := BT_ClientAreaHeight( "Win1" ) - BT_StatusBarHeight( "Win1" )
LOCAL hDC, BTstruct
LOCAL cText
LOCAL i

   hDC = BT_CreateDC( "Win1", BT_HDC_INVALIDCLIENTAREA, @BTstruct )

   FOR i := 0 TO Width STEP 10
      IF ( i % 100 ) = 0
         BT_DrawLine( hDC, 100 - 30, i, 35, i, BLACK, 2 )

         cText := LTRIM( STR( i ) )
         nTypeText := BT_TEXT_TRANSPARENT                   // BT_TEXT_OPAQUE
         nAlingText := BT_TEXT_CENTER + BT_TEXT_TOP
         BT_DrawText( hDC, 10, i, cText, "MS Sans Serif", 10, BLUE, { 228, 228, 228 }, nTypeText, nAlingText )

      ELSEIF ( i % 50 ) = 0
         BT_DrawLine( hDC, 100 - 30, i, 50, i, BLACK, 2 )
      ELSE
         BT_DrawLine( hDC, 100 - 30, i, 60, i, BLACK, 2 )
      ENDIF
   NEXT

   FOR i := 5 TO Width STEP 10
       BT_DrawLine( hDC, 100 - 30, i, 65, i, BLACK, 2 )
   NEXT

   BT_DeleteDC( BTstruct )
RETURN

STATIC FUNCTION GetDesktopArea()
LOCAL aDesk := {0,0,0,0}
   aDesk[3] := GetDesktopWidth()
   aDesk[4] := GetDesktopHeight()
RETURN aDesk

*+ EOF: HRULER.PRG


Xbase++ Code
Code: Select all  Expand view  RUN
#include "Gra.ch"
#include "Xbp.ch"
#include "Appevent.ch"
#include "Font.ch"
#include "OS.ch"

#include "DLL.ch"
#define HWND_DESKTOP    0
#define LOGPIXELSX      88
#define LOGPIXELSY      90
#define DESKTOPVERTRES  117
#define DESKTOPHORZRES  118

DLLFUNCTION GetDeviceCaps(hDC,Index)   USING STDCALL FROM GDI32.DLL
DLLFUNCTION GetDC( hDC )               USING STDCALL FROM USER32.DLL

PROCEDURE APPSYS
LOCAL cTitle  := "Horizontal Ruler"
LOCAL hWndDlg := DllCall( "User32.dll", DLL_STDCALL, "FindWindowA", 0, cTitle )
   IF !( hWndDlg == 0 )
      DllCall( "User32.dll", DLL_STDCALL, "SetForegroundWindow", hWndDlg )
      DllCall( "User32.dll", DLL_STDCALL, "BringWindowToTop", hWndDlg )
      DllCall( "User32.dll", DLL_STDCALL, "ShowWindow", hWndDlg, 1 )
      DllCall( "User32.dll", DLL_STDCALL, "UpdateWindow", hWndDlg )
      *** It is a second instance....  Bye Bye
      QUIT
   ENDIF
RETURN

PROCEDURE Main
LOCAL oDlg, oXbp, drawingArea, oPS
LOCAL nEvent, mp1, mp2
LOCAL lIsW98Run
LOCAL hWnd     := 0
LOCAL aDesk    := AppDesktop():currentSize()
LOCAL aSize    := {aDesk[1]-100,62}
LOCAL xDesk    := {0,0}
LOCAL aNewPos  := {0,0}
LOCAL aPos     := {0,0}
LOCAL cText
LOCAL i
LOCAL hDC        := GetDC( HWND_DESKTOP )
LOCAL nXLogPixel := GetDeviceCaps( hDC, LOGPIXELSX )
LOCAL nYLogPixel := GetDeviceCaps( hDC, LOGPIXELSY )
LOCAL nDHORZRES  := GetDeviceCaps( hDC, DESKTOPHORZRES ) // native Monitor Size !
LOCAL nDVERTRES  := GetDeviceCaps( hDC, DESKTOPVERTRES ) // native Monitor Size !
LOCAL nDPi,nFaktor

LOCAL aDragArea
LOCAL nX, nY
LOCAL lMove    := .F.

   * ------------------------------------------------- *
   *
   *  add Zoll/cm on upper site
   *
   * ------------------------------------------------- *

   // native Monitor Size
   xDesk[1] := nDHORZRES
   xDesk[2] := nDVERTRES

   // Scale
   nFaktor  := xDesk[1] / aDesk[1]
   // up to 125% old style = 120DPi
   IF nFaktor < 1.26
      nFaktor := 1
   ENDIF

   // real Pixel / Zoll
   nDPi     := ROUND(nFaktor*nXLogPixel,0)

   // new add Zoll/cm on upper side
   aSize[2] := aSize[2]+40

   // start Position
   aPos   := {50,aDesk[2]-aSize[2]}

   * ------------------------------------------------- *

   IF Os(OS_FAMILY) == "WIN9X"
      lIsW98Run  := .T.                         // W98 is running
   ELSE
      lIsW98Run  := .F.                         // XP is running
   ENDIF

   oDlg := XbpDialog():new( AppDesktop(), , aPos, aSize, , .F.)
   oDlg:taskList  := .T.
   oDlg:title     := "Horizontal Ruler"
   oDlg:Border    := XBPDLG_NO_BORDER
   oDlg:maxButton := .F.
   oDlg:minButton := .T.
   oDlg:icon      :=100
   oDlg:drawingArea:rbClick  := {|aPos, uNIL, obj| MenuTPZ(hWnd,oDlg,aPos) }
   oDlg:create()

   hWnd := oDlg:getHWND()

   drawingArea := oDlg:drawingArea
   drawingArea:setColorBG( GRA_CLR_PALEGRAY   )
   drawingArea:setFontCompoundName( "8.Arial" )

   aNewPos[2] := 20
   FOR i := 1 TO aSize[1] STEP 100
      IF i = 1
         aNewPos[1]  := 0
         cText       := "0"
      ELSE
         aNewPos[1]  := i -12
         cText       := LTRIM(STR(i-1))
      ENDIF

      // Pixel
      oXbp := XbpStatic():new( drawingArea, , aNewPos, {30,12}, { { XBP_PP_COMPOUNDNAME, "8.MS Sans Serif" } } )
      oXbp:caption := cText
      oXbp:clipSiblings := .T.
      oXbp:options := XBPSTATIC_TEXT_VCENTER+XBPSTATIC_TEXT_LEFT
      oXbp:create()
   NEXT

   oPS  := XbpPresSpace():new()
   oPS:create( oDlg:drawingArea:winDevice() )

   oDlg:drawingArea:paint := {|| DrawGraphic( oPS, aSize, nDPi ) }

   IF lIsW98Run
      oDlg:show()
   ELSE
      SetWindowLayered(hWnd,.T.)        // Stil setzen
      SetWindowTransparency(hWnd,100)   // unsichtbar machen
      oDlg:show()
      SetWindowTransparency(hWnd,100,15) // sichtbar machen
   ENDIF

   SetAppFocus( oDlg )
   nEvent := xbe_None
   DO WHILE nEvent <> xbeP_Close
      nEvent := AppEvent( @mp1, @mp2, @oXbp )
      DO CASE
         CASE nEvent == xbeM_LbDown .AND. oXbp:isDerivedFrom("XbpIWindow")

            oDlg:drawingArea:setPointer(, XBPSTATIC_SYSICON_WAIT, XBPWINDOW_POINTERTYPE_SYSPOINTER )

            aDragArea := GetCursorPos()
            aPos := oDlg:currentpos()
            nX := aDragArea[ 1 ] - aPos[ 1 ]
            nY := aDragArea[ 2 ] - aPos[ 2 ]
            aDragArea[ 1 ] -= nX
            aDragArea[ 2 ] -= nY
            //
            // set to Cursor Position
            //
            oDlg:setPos( aDragArea )

            oDlg:drawingArea:setPointer(, XBPSTATIC_SYSICON_MOVE, XBPWINDOW_POINTERTYPE_SYSPOINTER )

            oDlg:drawingArea:captureMouse( .T. )
            lMove := .T.

         CASE nEvent == xbeM_Motion .AND. oXbp:isDerivedFrom("XbpIWindow")

            IF lMove = .T.
               aDragArea := GetCursorPos()
               aDragArea[ 1 ] -= nX
               aDragArea[ 2 ] -= nY
               oDlg:setPos( aDragArea )
            ENDIF

         CASE nEvent == xbeM_LbUp   .AND. oXbp:isDerivedFrom("XbpIWindow")
            //
            //
            //
            aDragArea := GetCursorPos()
            aDragArea[ 1 ] -= nX
            aDragArea[ 2 ] -= nY

            oDlg:setPos( aDragArea )
            SETAPPFOCUS( oDlg )
            oDlg:drawingArea:setpointer(, XBPSTATIC_SYSICON_ARROW, XBPWINDOW_POINTERTYPE_SYSPOINTER )

            oDlg:drawingArea:captureMouse( .F. )
            lMove := .F.

         OTHERWISE
            oXbp:handleEvent( nEvent, mp1, mp2 )
      ENDCASE
   ENDDO
RETURN

PROCEDURE DrawGraphic( oPS, aSize, nDPI )
LOCAL aAttr[ GRA_AA_COUNT], i
LOCAL n

   aAttr[GRA_AA_COLOR] := GRA_CLR_BLACK
   GraSetAttrLine(oPS, aAttr)
   for i = 0 to aSize[1] step 10
      graline( oPs, {i, 0}, {i, if(i % 100 = 0, 20, if(i % 50 = 0, 16, 12))})
   next
   aAttr[GRA_AL_COLOR] :=  GRA_CLR_BLUE
   GraSetAttrLine(oPS, aAttr)
   for i = 5 to aSize[1]-5 step 10
      graline( oPs, {i, 0}, {i, 8})
   next

   * ------------------------------------------------- *
   *
   *  add Zoll/cm on upper site
   *
   * ------------------------------------------------- *

   FOR i = 0 to aSize[1] step 1
      IF (i % ROUND(nDPI/25.4*10/2,0) = 0)       // 0.5 cm
         aAttr[GRA_AL_COLOR] :=  GRA_CLR_BLUE
         GraSetAttrLine(oPS, aAttr)
         Graline( oPs, {i, 60}, {i,72})
      ENDIF
      IF (i % ROUND(nDPI/25.4*10,0) = 0)         // 1 cm
         aAttr[GRA_AL_COLOR] :=  GRA_CLR_RED
         GraSetAttrLine(oPS, aAttr)
         Graline( oPs, {i, 55}, {i,72})
      ENDIF
      IF (i % nDPI = 0)                          // 1 Zoll
         aAttr[GRA_AL_COLOR] :=  GRA_CLR_CYAN
         GraSetAttrLine(oPS, aAttr)
         Graline( oPs, {i, 40}, {i,72})
      ENDIF
   NEXT

RETURN

*
* eof
*

i do NOT agree about ALT+PrintScreen -> Paste into PAINT that SIZE is "wrong"

your Sample want 400,600 but got 394,587 under FiveWin 22.07 ( BCC7 32 Bit )
PAINT and my both RULER show same Size 394,587 which is (much) smaller than expect 400,600

---

open PAINT and make a Bitmap with 400 x 600 Color RED
start you App and move it over Bitmap

you will "see" RED Backgound of Bitmap while FiveWin App does NOT cover hole Area
so what i´m doing wrong :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 52 guests