From a826560895730742d129abff9aae0d0f5cfe5ae7 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Thu, 30 Oct 2008 02:00:51 +0000 Subject: [PATCH] 2008-10-29 19:06 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * harbour/contrib/gtwvg/gtwvg.c * harbour/contrib/gtwvg/gtwvg.h * harbour/contrib/gtwvg/hbgtwvg.ch + Added the possibility to have transparency on Window. Work-in-progress ! Rearranged .H structure for future seggregations into smaller structures * harbour/contrib/gtwvg/tests/demowvg.prg + Added functionality to make a window transparent. ; : Press F11 and F12 to increase/decrese transparency. --- harbour/ChangeLog | 12 ++ harbour/contrib/gtwvg/gtwvg.c | 34 ++++ harbour/contrib/gtwvg/gtwvg.h | 200 ++++++++++++++---------- harbour/contrib/gtwvg/hbgtwvg.ch | 1 + harbour/contrib/gtwvg/tests/demowvg.prg | 40 +++-- 5 files changed, 192 insertions(+), 95 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 9d27c1ca5c..fef5f0195e 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,18 @@ 2008-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2008-10-29 19:06 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + * harbour/contrib/gtwvg/gtwvg.c + * harbour/contrib/gtwvg/gtwvg.h + * harbour/contrib/gtwvg/hbgtwvg.ch + + Added the possibility to have transparency on Window. Work-in-progress + ! Rearranged .H structure for future seggregations into + smaller structures + + * harbour/contrib/gtwvg/tests/demowvg.prg + + Added functionality to make a window transparent. + ; : Press F11 and F12 to increase/decrese transparency. + 2008-10-30 00:10 UTC+0200 Viktor Szakats (harbour.01 syenar hu) * ChangeLog + Clarification to previous entry. diff --git a/harbour/contrib/gtwvg/gtwvg.c b/harbour/contrib/gtwvg/gtwvg.c index 957ebca346..1df30ef6fa 100644 --- a/harbour/contrib/gtwvg/gtwvg.c +++ b/harbour/contrib/gtwvg/gtwvg.c @@ -2917,6 +2917,24 @@ static BOOL hb_gt_wvt_Info( PHB_GT pGT, int iType, PHB_GT_INFO pInfo ) } break; } + + case HB_GTS_FACTOR: + { + if ( pWVT->pfnLayered ) + { + BOOL bGF; + + SetWindowLong( pWVT->hWnd, + GWL_EXSTYLE, + GetWindowLong( pWVT->hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED ); + + pWVT->pfnLayered( pWVT->hWnd, + RGB( 255,255,255 ), + hb_itemGetNI( pInfo->pNewVal2 ), + LWA_COLORKEY|LWA_ALPHA ); + } + break; + } } break; } @@ -3384,6 +3402,7 @@ static void hb_wvt_gtCreateObjects( PHB_GTWVT pWVT ) pWVT->colStart = 0; pWVT->colStop = 0; pWVT->bToolTipActive = FALSE; + pWVT->iFactor = 255; h = LoadLibraryEx( TEXT( "msimg32.dll" ), NULL, 0 ); if( h ) @@ -3400,6 +3419,21 @@ static void hb_wvt_gtCreateObjects( PHB_GTWVT pWVT ) } } + h = LoadLibraryEx( TEXT( "user32.dll" ), NULL, 0 ); + if( h ) + { + /* workaround for wrong declarations in some old C compilers */ +#if defined( UNICODE ) && defined( GetProcAddress ) + pWVT->pfnLayered = ( wvtSetLayeredWindowAttributes ) GetProcAddressW( h, TEXT( "SetLayeredWindowAttributes" ) ); +#else + pWVT->pfnLayered = ( wvtSetLayeredWindowAttributes ) GetProcAddress( h, "SetLayeredWindowAttributes" ); +#endif + if( pWVT->pfnLayered ) + { + pWVT->hUser32 = h; + } + } + for( iIndex = 0; iIndex < WVT_DLGML_MAX; iIndex++ ) { pWVT->hDlgModeless[ iIndex ] = NULL; diff --git a/harbour/contrib/gtwvg/gtwvg.h b/harbour/contrib/gtwvg/gtwvg.h index fb611c693a..f8a8d3776d 100644 --- a/harbour/contrib/gtwvg/gtwvg.h +++ b/harbour/contrib/gtwvg/gtwvg.h @@ -231,62 +231,90 @@ typedef BOOL ( WINAPI *wvtGradientFill ) ( ULONG dwNumMesh, ULONG dwMode ); +typedef BOOL ( WINAPI *wvtSetLayeredWindowAttributes )( + HWND hwnd, + COLORREF crKey, + BYTE bAlpha, + DWORD dwFlags ); + //-------------------------------------------------------------------// typedef struct { - PHB_GT pGT; /* core GT pointer */ - int iHandle; /* window number */ + HPEN penWhite; // White pen to draw GDI elements + HPEN penBlack; // Black pen to draw GDI elements + HPEN penWhiteDim; // White dim pen to draw GDI elements + HPEN penDarkGray; // Dark gray pen to draw GDI elements + HPEN penGray; // Gray pen equivilant to Clipper White + HPEN penNull; // Null pen + HPEN currentPen; // Handle to current pen settable at runtime + HBRUSH currentBrush; // Handle to current brush settable by runtime + HBRUSH diagonalBrush; // Handle to diaoganl brush to draw scrollbars + HBRUSH solidBrush; // Handle to solid brush + HBRUSH wvtWhiteBrush; // Wvt specific White colored brush + IPicture *iPicture[ WVT_PICTURES_MAX ]; // Array to hold the Picture Streams to avoid recurring loading and unloading + HFONT hUserFonts[ WVT_FONTS_MAX ] ; // User defined font handles + HPEN hUserPens[ WVT_PENS_MAX ]; // User defined pens + HINSTANCE hMSImg32; // Handle to the loaded library msimg32.dll + wvtGradientFill pfnGF; // Pointer to Address of the GradientFill function in MSImg32.dll + wvtSetLayeredWindowAttributes pfnLayered;// Pointer to set Windows attribute - transparency. + +} HB_GUIDATA, * PHB_GUIDATA; + +typedef struct +{ + PHB_GT pGT; /* core GT pointer */ + int iHandle; /* window number */ HINSTANCE hInstance; int iCmdShow; - USHORT ROWS; /* number of displayable rows in window */ - USHORT COLS; /* number of displayable columns in window */ + USHORT ROWS; /* number of displayable rows in window */ + USHORT COLS; /* number of displayable columns in window */ - COLORREF COLORS[ 16 ]; /* colors */ + COLORREF COLORS[ 16 ]; /* colors */ - BOOL CaretExist; /* TRUE if a caret has been created */ - BOOL CaretHidden; /* TRUE if a caret has been hiden */ - int CaretSize; /* Size of solid caret */ + BOOL CaretExist; /* TRUE if a caret has been created */ + BOOL CaretHidden; /* TRUE if a caret has been hiden */ + int CaretSize; /* Size of solid caret */ - POINT MousePos; /* the last mouse position */ - BOOL MouseMove; /* Flag to say whether to return mouse movement events */ + POINT MousePos; /* the last mouse position */ + BOOL MouseMove; /* Flag to say whether to return mouse movement events */ - int Keys[ WVT_CHAR_QUEUE_SIZE ]; /* Array to hold the characters & events */ - int keyPointerIn; /* Offset into key array for character to be placed */ - int keyPointerOut; /* Offset into key array of next character to read */ - int keyLast; /* last inkey code value in buffer */ + int Keys[ WVT_CHAR_QUEUE_SIZE ]; /* Array to hold the characters & events */ + int keyPointerIn; /* Offset into key array for character to be placed */ + int keyPointerOut; /* Offset into key array of next character to read */ + int keyLast; /* last inkey code value in buffer */ - POINT PTEXTSIZE; /* size of the fixed width font */ - BOOL FixedFont; /* TRUE if current font is a fixed font */ - int FixedSize[ WVT_MAX_COLS ]; /* buffer for ExtTextOut() to emulate fixed pitch when Proportional font selected */ - int fontHeight; /* requested font height */ - int fontWidth; /* requested font width */ - int fontWeight; /* Bold level */ - int fontQuality; /* requested font quality */ - char fontFace[ LF_FACESIZE ]; /* requested font face name LF_FACESIZE #defined in wingdi.h */ - HFONT hFont; /* current font handle */ + POINT PTEXTSIZE; /* size of the fixed width font */ + BOOL FixedFont; /* TRUE if current font is a fixed font */ + int FixedSize[ WVT_MAX_COLS ]; /* buffer for ExtTextOut() to emulate fixed pitch when Proportional font selected */ + int fontHeight; /* requested font height */ + int fontWidth; /* requested font width */ + int fontWeight; /* Bold level */ + int fontQuality; /* requested font quality */ + char fontFace[ LF_FACESIZE ]; /* requested font face name LF_FACESIZE #defined in wingdi.h */ + HFONT hFont; /* current font handle */ - HWND hWnd; /* the window handle */ - BOOL fInit; /* logical variable indicating that window should be open */ + HWND hWnd; /* the window handle */ + BOOL fInit; /* logical variable indicating that window should be open */ - PHB_CODEPAGE hostCDP; /* Host/HVM CodePage for unicode output translations */ - PHB_CODEPAGE inCDP; /* Host/HVM CodePage for unicode input translations */ + PHB_CODEPAGE hostCDP; /* Host/HVM CodePage for unicode output translations */ + PHB_CODEPAGE inCDP; /* Host/HVM CodePage for unicode input translations */ #if !defined(UNICODE) BYTE keyTransTbl[ 256 ]; BYTE chrTransTbl[ 256 ]; #endif - int CodePage; /* Code page to use for display characters */ - BOOL Win9X; /* Flag to say if running on Win9X not NT/2000/XP */ - BOOL AltF4Close; /* Can use Alt+F4 to close application */ - BOOL CentreWindow; /* True if window is to be Reset into centre of window */ + int CodePage; /* Code page to use for display characters */ + BOOL Win9X; /* Flag to say if running on Win9X not NT/2000/XP */ + BOOL AltF4Close; /* Can use Alt+F4 to close application */ + BOOL CentreWindow; /* True if window is to be Reset into centre of window */ BOOL IgnoreWM_SYSCHAR; - BOOL bMaximized; /* Flag is set when window has been maximized */ - BOOL bBeingMarked; /* Flag to control DOS window like copy operation */ + BOOL bMaximized; /* Flag is set when window has been maximized */ + BOOL bBeingMarked; /* Flag to control DOS window like copy operation */ BOOL bBeginMarked; BOOL bResizable; @@ -294,57 +322,26 @@ typedef struct char * pszSelectCopy; BOOL bClosable; - int ResizeMode; /* Sets the resizing mode either to FONT or ROWS */ + int ResizeMode; /* Sets the resizing mode either to FONT or ROWS */ // To Be Split in 2 Structures <1 GUI dynamic> <2 GUI fixed> // - BOOL bResizing; + int rowStart; // Holds nTop of last WM_PAINT rectangle returned by Wvt_GetPaintRect() + int rowStop; // Holds nBottom of last WM_PAINT rectangle + int colStart; // Holds nLeft of last WM_PAINT rectangle + int colStop; // Holds nRight of last WM_PAINT rectangle + + int iFactor; // Transparency factor 0~255 + + BOOL bResizing; + HDC hdc; // Handle to Windows Device Context + HDC hCompDC; // Compatible DC to _s.hdc + + int LastMenuEvent; // Last menu item selected + int MenuKeyEvent; // User definable event number for windows menu command + BOOL InvalidateWindow; // Flag for controlling whether to use ScrollWindowEx() + BOOL EnableShortCuts; // Determines whether ALT key enables menu or system menu - int LastMenuEvent; // Last menu item selected - int MenuKeyEvent; // User definable event number for windows menu command - BOOL InvalidateWindow; // Flag for controlling whether to use ScrollWindowEx() - BOOL EnableShortCuts; // Determines whether ALT key enables menu or system menu - HPEN penWhite; // White pen to draw GDI elements - HPEN penBlack; // Black pen to draw GDI elements - HPEN penWhiteDim; // White dim pen to draw GDI elements - HPEN penDarkGray; // Dark gray pen to draw GDI elements - HPEN penGray; // Gray pen equivilant to Clipper White - HPEN penNull; // Null pen - HPEN currentPen; // Handle to current pen settable at runtime - HBRUSH currentBrush; // Handle to current brush settable by runtime - HBRUSH diagonalBrush; // Handle to diaoganl brush to draw scrollbars - HBRUSH solidBrush; // Handle to solid brush - HBRUSH wvtWhiteBrush; // Wvt specific White colored brush - HDC hdc; // Handle to Windows Device Context - PHB_DYNS pSymWVT_PAINT; // Stores pointer to WVT_PAINT function - PHB_DYNS pSymWVT_SETFOCUS; // Stores pointer to WVT_SETFOCUS function - PHB_DYNS pSymWVT_KILLFOCUS; // Stores pointer to WVT_KILLFOCUS function - PHB_DYNS pSymWVT_MOUSE; // Stores pointer to WVT_MOUSE function - PHB_DYNS pSymWVT_TIMER; // Stores pointer to WVT_TIMER function - PHB_DYNS pSymWVT_KEY; - int rowStart; // Holds nTop of last WM_PAINT rectangle returned by Wvt_GetPaintRect() - int rowStop; // Holds nBottom of last WM_PAINT rectangle - int colStart; // Holds nLeft of last WM_PAINT rectangle - int colStop; // Holds nRight of last WM_PAINT rectangle - HMENU hPopup; // Handle of context menu invokable with right click - IPicture *iPicture[ WVT_PICTURES_MAX ]; // Array to hold the Picture Streams to avoid recurring loading and unloading - HDC hCompDC; // Compatible DC to _s.hdc - HFONT hUserFonts[ WVT_FONTS_MAX ] ; // User defined font handles - HPEN hUserPens[ WVT_PENS_MAX ]; // User defined pens - HWND hWndTT; // Handle to hold tooltip information - BOOL bToolTipActive; // Flag to set whether tooltip is active or not - HINSTANCE hMSImg32; // Handle to the loaded library msimg32.dll - wvtGradientFill pfnGF; // Pointer to Address of the GradientFill function in MSImg32.dll - HWND hDlgModeless[ WVT_DLGML_MAX ]; // Handle to a modeless dialog - PHB_ITEM pFunc[ WVT_DLGML_MAX ]; // Function pointer for WndProc - /* TODO: pcbFunc is redundant and should be removed */ - PHB_ITEM pcbFunc[ WVT_DLGML_MAX ]; //codeblock for WndProc - int iType[ WVT_DLGML_MAX ]; // Type of Function Pointers - Function 1, Block 2, Method 3 - HWND hDlgModal[ WVT_DLGMD_MAX ];// Handle to a modeless dialog - PHB_ITEM pFuncModal[ WVT_DLGMD_MAX ]; // Function pointer for WndProc - /* TODO: pcbFuncModal is redundant and should be removed */ - PHB_ITEM pcbFuncModal[ WVT_DLGMD_MAX ]; // codeblock for WndProc - int iTypeModal[ WVT_DLGMD_MAX ]; // Type of Function Pointers - Function 1, Block 2, Method 3 BOOL bGui; HDC hGuiDC; HBITMAP hGuiBmp; @@ -356,6 +353,49 @@ typedef struct BOOL bSetFocus; BOOL bKillFocus; + PHB_DYNS pSymWVT_PAINT; // Stores pointer to WVT_PAINT function + PHB_DYNS pSymWVT_SETFOCUS; // Stores pointer to WVT_SETFOCUS function + PHB_DYNS pSymWVT_KILLFOCUS; // Stores pointer to WVT_KILLFOCUS function + PHB_DYNS pSymWVT_MOUSE; // Stores pointer to WVT_MOUSE function + PHB_DYNS pSymWVT_TIMER; // Stores pointer to WVT_TIMER function + PHB_DYNS pSymWVT_KEY; + + HPEN penWhite; // White pen to draw GDI elements + HPEN penBlack; // Black pen to draw GDI elements + HPEN penWhiteDim; // White dim pen to draw GDI elements + HPEN penDarkGray; // Dark gray pen to draw GDI elements + HPEN penGray; // Gray pen equivilant to Clipper White + HPEN penNull; // Null pen + HPEN currentPen; // Handle to current pen settable at runtime + HBRUSH currentBrush; // Handle to current brush settable by runtime + HBRUSH diagonalBrush; // Handle to diaoganl brush to draw scrollbars + HBRUSH solidBrush; // Handle to solid brush + HBRUSH wvtWhiteBrush; // Wvt specific White colored brush + IPicture *iPicture[ WVT_PICTURES_MAX ]; // Array to hold the Picture Streams to avoid recurring loading and unloading + HFONT hUserFonts[ WVT_FONTS_MAX ] ; // User defined font handles + HPEN hUserPens[ WVT_PENS_MAX ]; // User defined pens + HINSTANCE hMSImg32; // Handle to the loaded library msimg32.dll + wvtGradientFill pfnGF; // Pointer to Address of the GradientFill function in MSImg32.dll + HINSTANCE hUser32; // Handle to the loaded library user32.dll + wvtSetLayeredWindowAttributes pfnLayered;// Pointer to set Windows attribute - transparency. + + HMENU hPopup; // Handle of context menu invokable with right click + HWND hWndTT; // Handle to hold tooltip information + BOOL bToolTipActive; // Flag to set whether tooltip is active or not + + HWND hDlgModeless[ WVT_DLGML_MAX ]; // Handle to a modeless dialog + PHB_ITEM pFunc[ WVT_DLGML_MAX ]; // Function pointer for WndProc + /* TODO: pcbFunc is redundant and should be removed */ + PHB_ITEM pcbFunc[ WVT_DLGML_MAX ]; //codeblock for WndProc + int iType[ WVT_DLGML_MAX ]; // Type of Function Pointers - Function 1, Block 2, Method 3 + HWND hDlgModal[ WVT_DLGMD_MAX ]; // Handle to a modeless dialog + PHB_ITEM pFuncModal[ WVT_DLGMD_MAX ]; // Function pointer for WndProc + /* TODO: pcbFuncModal is redundant and should be removed */ + PHB_ITEM pcbFuncModal[ WVT_DLGMD_MAX ]; // codeblock for WndProc + int iTypeModal[ WVT_DLGMD_MAX ]; // Type of Function Pointers - Function 1, Block 2, Method 3 + + PHB_GUIDATA * pGui; // GUI Data Structure + } HB_GTWVT, * PHB_GTWVT; //----------------------------------------------------------------------// diff --git a/harbour/contrib/gtwvg/hbgtwvg.ch b/harbour/contrib/gtwvg/hbgtwvg.ch index cb51356080..a50fe4e4bf 100644 --- a/harbour/contrib/gtwvg/hbgtwvg.ch +++ b/harbour/contrib/gtwvg/hbgtwvg.ch @@ -74,6 +74,7 @@ #define HB_GTS_SHOWWINDOW 10 #define HB_GTS_UPDATEWINDOW 11 #define HB_GTS_SYSTRAYICON 12 +#define HB_GTS_FACTOR 13 /* Window States */ #define WNDS_SETONTOP 1 diff --git a/harbour/contrib/gtwvg/tests/demowvg.prg b/harbour/contrib/gtwvg/tests/demowvg.prg index f5850e56c9..35b6d315e4 100644 --- a/harbour/contrib/gtwvg/tests/demowvg.prg +++ b/harbour/contrib/gtwvg/tests/demowvg.prg @@ -29,6 +29,7 @@ #include "common.ch" #include "wvtwin.ch" #include "hbgtinfo.ch" +#include "hbgtwvg.ch" REQUEST DbfCdx @@ -656,13 +657,14 @@ FUNCTION WvtMyBrowse_X() LOCAL nCursor := setCursor( 0 ) LOCAL nRow := row() LOCAL nCol := col() - LOCAL cColor := SetColor( "N/W*,N/GR*,,,N/W*" ) + LOCAL cColor := SetColor( "N/BG,N/GR*,,,N/W*" )//SetColor( "N/W*,N/GR*,,,N/W*" ) LOCAL cScr := SaveScreen( 0,0,maxrow(),maxcol() ) LOCAL aObjects:= WvtSetObjects( {} ) LOCAL hPopup := Wvt_SetPopupMenu() LOCAL stru_:={}, cDbfFile, cSqlFile, cFileIndex, cFileDbf, cRDD, nIndex STATIC nStyle := 0 + THREAD STATIC nFactor := 200 cRDD := "DBFCDX" cFileDbf := "test.dbf" @@ -687,7 +689,6 @@ FUNCTION WvtMyBrowse_X() Popups( 2 ) - //oBrowse := TBrowseNew( nTop + 3, nLeft + 2, nBottom - 1, nRight - 2 ) oBrowse := TBrowseWVG():New( nTop + 3, nLeft + 2, nBottom - 1, nRight - 2 ) oBrowse:ColSep := " " @@ -726,23 +727,29 @@ FUNCTION WvtMyBrowse_X() While !lEnd oBrowse:ForceStable() - nKey := InKey( 0 ) + nKey := InKey( 0, INKEY_ALL ) - if BrwHandleKey( oBrowse, nKey, @lEnd ) + do case + case nKey == K_F12 + nFactor -= 10 + hb_gtInfo( HB_GTI_SPEC, HB_GTS_FACTOR, nFactor ) - else - if nKey == HB_K_RESIZE - oBrowse:nBottom := maxrow() - 3 - oBrowse:nRight := maxcol() - 5 + case nKey == K_F11 + nFactor += 10 + hb_gtInfo( HB_GTI_SPEC, HB_GTS_FACTOR, nFactor ) - DispBox( 0, 0, maxrow(), maxcol(), " ", "N/W" ) - DispOutAt( oBrowse:nTop-2, oBrowse:nleft, padc( CurDrive()+":\"+CurDir()+"\"+"test.dbf", oBrowse:nRight - oBrowse:nLeft + 1 ), "W+/W" ) + case BrwHandleKey( oBrowse, nKey, @lEnd ) - oBrowse:configure() - endif - endif + case nKey == HB_K_RESIZE + oBrowse:nBottom := maxrow() - 3 + oBrowse:nRight := maxcol() - 5 - if nKey == K_F2 + DispBox( 0, 0, maxrow(), maxcol(), " ", "N/W" ) + DispOutAt( oBrowse:nTop-2, oBrowse:nleft, padc( CurDrive()+":\"+CurDir()+"\"+"test.dbf", oBrowse:nRight - oBrowse:nLeft + 1 ), "W+/W" ) + + oBrowse:configure() + + case nKey == K_F2 nIndex := IndexOrd() nIndex++ if nIndex > 3 @@ -750,7 +757,8 @@ FUNCTION WvtMyBrowse_X() endif Set Order To ( nIndex ) oBrowse:RefreshAll() - endif + + endcase end Wvt_SetPen( 0 ) @@ -1587,6 +1595,8 @@ STATIC FUNCTION MyDialogOne() oDlg:AddObject( oWvtBrw1 ) endif + Setkey( K_F12, {|| hb_gtInfo( HB_GTI_SPEC, HB_GTS_FACTOR, 200 ) } ) + oDlg:Create() oDlg:Execute() oDlg:Destroy()