HMG Form to FiveWin

HMG Form to FiveWin

Postby Jimmy » Sat Dec 07, 2019 6:26 am

hi,

i have a working harbour App using HMG Syntax for "WINDOW"

it create 8 x WINDOW in a loop using Macro which have no Titlebar or Frame.
i use some HB_FUNC to "paint" Part of Bitmap into Window and cover it with "Region"
it need a Timer to call Function every Second to show Time()

so my Problem now is to "translate" these both Modul to FiveWin
Code: Select all  Expand view
#IFDEF Use_HMG
   #include "hmg.ch"
#ELSE
   #include "fivewin.ch"
#ENDIF
#include "DLL.ch"
#include "INKEY.ch"

#define RGN_OR             2
#define PROGRAM            "LCD_Time"
#define BMP_ERASE          0     // Borra la imagen de fondo de la ventana
#define BMP_COPY_NORMAL    1     // Pega la imagen al fondo con el tamaño original de la misma
#define BMP_COPY_SCALE     2     // Ajusta proporcionalmente la imagen para que se vea completa en la ventana
#define BMP_COPY_STRETCH   3     // Ajusta el tamaño de la imagen al tamaño de la ventana (no respeta las proporciones originales)
#define BMP_COPY_SPLIT     99    // Jimmy : more Parameter
#define BMP_INFO_WIDTH     0
#define BMP_INFO_HEIGHT    1
#define BMP_INFO_BITSPIXEL 2

#ifdef __XHARBOUR__
   #define ENUMINDEX hb_EnumIndex()
#else
   #define ENUMINDEX enum:__EnumIndex
#endif

STATIC lBusy := .F.
*--------------------------------------------------------*
*
* this Demo was made by Auge & Ohr, Jimmy 26.11.2019
* it show how to use Macro e.g. pass Parameter
*
* it create 8 x Form and "mask" it via API SetWindowRgn()
*
* Background Image is "split" into 8 Parts and show diffent Color
*
*--------------------------------------------------------*
MEMVAR a_Forms, aSubSize,aBitmap
MEMVAR FORM_1, cOnPaintProc

PROCEDURE Main()
PUBLIC a_Forms  := {}
PUBLIC aSubSize := { 100, 300 }
PUBLIC aBitmap  := {}

PRIVATE FORM_1

   SET MULTIPLE OFF
   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 0 HEIGHT 0 ;
      TITLE PROGRAM ;
      ICON 'MAIN' ;
      MAIN ;
      ON INIT CreateForms() ;
      ON RELEASE DoRelease() ;
      NOTIFYICON 'MAIN' ;
      NOTIFYTOOLTIP PROGRAM ;
      NOSHOW ;
      ON NOTIFYCLICK HideShow()

      DEFINE NOTIFY MENU OF Form_1
         ITEM '&Exit' ACTION Form_1.Release
      END MENU

      DEFINE TIMER Timer_1 OF Form_1 INTERVAL 1000 ACTION ShowTime()
   END WINDOW
   ACTIVATE WINDOW Form_1
RETURN
 


Code: Select all  Expand view
STATIC FUNCTION CreateForms()
Local aDesk := GetDesktopArea()
Local nDeskWidth  := aDesk[3] - aDesk[1]
LOCAL nDeskHeight := aDesk[4] - aDesk[2]
Local nTop := 0, nLeft := 0
Local i,iMax := 8
Local cForm
Local hBitmap
Local wide
Local height

PRIVATE cOnPaintProc

   hBitmap := BMP_LOAD_FILE("COLORS.BMP")
   wide    := BMP_GET_INFO (hBitmap, BMP_INFO_WIDTH)
   height  := BMP_GET_INFO (hBitmap, BMP_INFO_HEIGHT)

   AADD(aBitmap,hBitmap)

   nLeft := ( nDeskWidth  - ( iMax * aSubSize[ 1 ] ) - 8 ) / 2
   nTop  := ( nDeskHeight - aSubSize[ 2 ] ) / 2

   // Left Height
   FOR i = 1 TO iMax
      cForm  := "Form_"+strzero(i, 2)      

      /******************************************************************
      * aData[1] := cForm
      * aData[2] := hBitmap
      * aData[3] := wide
      * aData[4] := height
      * cOnPaintProc := "Paint_Background_Window( '" + cForm + "', '" + hb_Serialize(aData) + "')"
      ******************************************************************/

      cOnPaintProc := "Paint_Background_Window( '" + cForm           + ;
                                                "', '" + str(i)      + ;
                                                "', '" + str(wide)   + ;
                                                "', '" + str(height) + ;
                                                "', '" + str(hBitmap)+ "'  )"

      DEFINE WINDOW &cForm ;
         AT nTop, nLeft ;
         WIDTH aSubSize[ 1 ] HEIGHT aSubSize[ 2 ] ;
         CHILD ;
         TOPMOST ;
         NOSHOW ;
         NOCAPTION ;
         ON PAINT &cOnPaintProc ;
         NOMINIMIZE NOMAXIMIZE NOSIZE

      END WINDOW
#IFDEF Use_HMG
   ThisWindow.NoClose := .T.
#ELSE
   // FiveWin ?
#ENDIF

      aAdd(a_Forms, "Form_" + strzero(i,2))
      nLeft  += aSubSize[ 1 ] + 2
   NEXT

   _ActivateWindow ( a_Forms, .F. )
   HideShow()
RETURN NIL
 

the WINDOW Form_1 is not shown and goes to Tray-Icon where you start App. right-click show Exit
in FUNCTION CreateForms() 8 x WINDOW &cForm are create. i use (WM_) PAINT Event.
Code: Select all  Expand view
FUNCTION Paint_Background_Window(cForm,cID,cwide,cheight,cBitmap)
//
// Note : don't made STATIC FUNCTION with Macro !
//
LOCAL hWnd
LOCAL hBitmap
LOCAL nMode  := BMP_COPY_SPLIT
LOCAL Row    := 0
LOCAL Col    := 0
Local nNo    := 0
Local wide   := 32
Local height := 35
Local nPart  := 0

   nNo       := VAL(cID    )
   wide      := VAL(cwide  )
   height    := VAL(cheight)
   hBitmap   := VAL(cBitmap)
   nPart     := ROUND(wide/8,0)-1

   hWnd      := GetFormHandle(cForm)
   Row       := GetProperty(cForm ,"Height")
   Col       := GetProperty(cForm ,"Width" )

   BMP_PAINT (hWnd, hBitmap, nMode,0,0,Row,Col,;
                                   0,nPart*(nNo-1),height,nPart)

RETURN NIL
 

here HB_FUNC
Code: Select all  Expand view
//*************************************************************************************************
// BMP_PAINT (hWnd, hBitmap, nMode, Row, Col, Row2, Col2)
// BMP_PAINT (hWnd, hBitmap, nMode, Row, Col, Row2, Col2, aSource.top, aSource.left, aSource.bottom, aSource.right)
//*************************************************************************************************

HB_FUNC(BMP_PAINT)
{
   HWND hWnd;
   HBITMAP hBitmap;
   HDC memDC, hDC;
   RECT rect;
   RECT aSource;
   BITMAP bm;
   int nMode;

   hWnd     = (HWND)    hb_parnl (1);
   hBitmap  = (HBITMAP) hb_parnl  (2);
   nMode    = hb_parni (3);

   GetClientRect(hWnd, &rect);

   //hDC = GetDC (hWnd);   // obtine un hDC para toda el area del cliente (se puede pintar en cualquier lugar del area del cliente)
   PAINTSTRUCT ps;
   hDC = BeginPaint (hWnd, &ps);  // obtiene un hDC solo para el area invalida (area que debe ser repintada) en un mensaje WM_PAINT

   if (nMode == BMP_ERASE)
       FillRect(hDC,&rect,(HBRUSH) GetSysColorBrush(COLOR_BTNFACE));
   else
   {
       FillRect(hDC,&rect,(HBRUSH) GetSysColorBrush(COLOR_BTNFACE)); // borra la imagen anterior antens de asignar otra

       memDC = CreateCompatibleDC(hDC);

       SelectObject(memDC, hBitmap);

       rect.top    = hb_parnl (4);
       rect.left   = hb_parnl (5);

       if (nMode == BMP_COPY_NORMAL)
      {
          rect.bottom = hb_parnl (6);
          rect.right  = hb_parnl (7);
          BitBlt(hDC, rect.left, rect.top, rect.right, rect.bottom, memDC, 0, 0, SRCCOPY);
      }


       GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);

       if (nMode == BMP_COPY_SCALE)
       {  if ((int) bm.bmWidth * rect.bottom / bm.bmHeight <= rect.right)
            rect.right= (int) bm.bmWidth * rect.bottom / bm.bmHeight;
         else
            rect.bottom = (int) bm.bmHeight * rect.right / bm.bmWidth;

          StretchBlt(hDC, rect.left, rect.top, rect.right, rect.bottom, memDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
       }

       if (nMode == BMP_COPY_SPLIT)   // Jimmy
       {
          rect.bottom = hb_parnl (6);
          rect.right  = hb_parnl (7);

          aSource.top    = hb_parnl (8);
          aSource.left   = hb_parnl (9);
          aSource.bottom = hb_parnl (10);
          aSource.right  = hb_parnl (11);

          StretchBlt(hDC, rect.left, rect.top, rect.right, rect.bottom, memDC, aSource.left, aSource.top, aSource.right, aSource.bottom, SRCCOPY);
       }

       if (nMode == BMP_COPY_STRETCH)
          StretchBlt(hDC, rect.left, rect.top, rect.right, rect.bottom, memDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);

       DeleteDC(memDC);
   }

   //EndPaint (hWnd, hDC); //Elimina el hDC y Valida el area pintada
   ReleaseDC(hWnd, hDC);   //Elimina el hDC pero NO Valida el area pintada
                           //Al no validar el area pintada permite que los procesos de pintura siguientes encadenados puedan usar hDC = BeginPaint (hWnd, &ps);

}

 

note BMP_COPY_SPLIT which i have include to "split" Bitmap into 8 parts

so how to get it work under FiveWin while i got Error like these when link
c:\fwh\samples\1\HMG_UHR.prg(58) Error E0030 Syntax error "syntax error at 'WINDOW'"
c:\fwh\samples\1\HMG_UHR.prg(60) Error E0030 Syntax error "syntax error at 'NOTIFY'"
c:\fwh\samples\1\HMG_UHR.prg(61) Error E0030 Syntax error "syntax error at '&Exit'"
c:\fwh\samples\1\HMG_UHR.prg(62) Error E0030 Syntax error "syntax error at 'END'"
c:\fwh\samples\1\HMG_UHR.prg(64) Warning W0001 Ambiguous reference 'TIMER_1'
c:\fwh\samples\1\HMG_UHR.prg(66) Error E0030 Syntax error "syntax error at 'END'"
c:\fwh\samples\1\HMG_UHR.prg(121) Error E0030 Syntax error "syntax error at 'WINDOW'"
c:\fwh\samples\1\HMG_UHR.prg(132) Error E0013 NEXT does not match FOR

please help a FiveWin Newbie, thx
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1689
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: HMG Form to FiveWin

Postby Jimmy » Sat Dec 07, 2019 9:56 am

this is the Result of it
Image
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1689
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 66 guests