Page 1 of 2

window transparent

Posted: Wed Jun 10, 2009 5:40 am
by jrendon
Hi all

how create a window transparent

i see one example many years ago on version 1.xx of minigui, and now need this example.

Thank's

Juan Rendón

Re: window transparent

Posted: Wed Jun 10, 2009 7:15 am
by gfilatov
jrendon wrote:Hi all

how create a window transparent

i see one example many years ago on version 1.xx of minigui, and now need this example.
Hi Juan Rendón,

Please try the following sample:

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 *
 * Copyright 2002-2009 Roberto Lopez <harbourminigui@gmail.com>
 * http://harbourminigui.googlepages.com/
*/

#include "minigui.ch" 

Function Main() 
Local nTra := 128, hWnd

	DEFINE WINDOW WinTR ;
		AT 0,0 ;
		WIDTH 300 ;
		HEIGHT 300 ;
		TITLE 'Transparent window' ;
		MAIN ;
		NOSIZE NOMAXIMIZE ;
		ON INIT ( hWnd := GetFormHandle('WinTR'), SetTransparent(hWnd, nTra) )

		@ 200,100 BUTTON But1 ;
			CAPTION "Click Me" ;
			HEIGHT 35 WIDTH 100 ;
			ACTION ( nTra := IIF(nTra == 128, 255, 128), SetTransparent(hWnd, nTra) )

	END WINDOW

	CENTER WINDOW WinTR

	ACTIVATE WINDOW WinTR

RETURN NIL 


#pragma BEGINDUMP 

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

HB_FUNC( SETTRANSPARENT )
{ 

	typedef BOOL (__stdcall *PFN_SETLAYEREDWINDOWATTRIBUTES) (HWND, COLORREF, BYTE, DWORD);

	PFN_SETLAYEREDWINDOWATTRIBUTES pfnSetLayeredWindowAttributes = NULL;

	HINSTANCE hLib = LoadLibrary("user32.dll");

	if (hLib != NULL)
	{
		pfnSetLayeredWindowAttributes = (PFN_SETLAYEREDWINDOWATTRIBUTES) GetProcAddress(hLib, "SetLayeredWindowAttributes");
	}

	if (pfnSetLayeredWindowAttributes)
	{
		SetWindowLong((HWND) hb_parnl (1), GWL_EXSTYLE, GetWindowLong((HWND) hb_parnl (1), GWL_EXSTYLE) | WS_EX_LAYERED);
		pfnSetLayeredWindowAttributes((HWND) hb_parnl (1), 0, hb_parni (2), LWA_ALPHA);
	}

	if (!hLib)
	{
		FreeLibrary(hLib);
	}

} 

#pragma ENDDUMP
8-)

Re: window transparent

Posted: Thu Jun 11, 2009 12:49 am
by fchirico
gfilatov wrote:
Please try the following sample:

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 *
 * Copyright 2002-2009 Roberto Lopez <harbourminigui@gmail.com>
 * http://harbourminigui.googlepages.com/
*/

#include "minigui.ch" 

Function Main() 
Local nTra := 128, hWnd.....
[/quote]

Hi Grigory !
	
when compiling the code your post the following error appears:

[quote]Start... 
DEMO.prg: In function `HB_FUN_SETTRANSPARENT':
DEMO.prg:57: error: `LWA_ALPHA' undeclared (first use in this function)
DEMO.prg:57: error: (Each undeclared identifier is reported only once
DEMO.prg:57: error: for each function it appears in.)
Finished With Errors. [/quote]

Can you help me please?

Saludos, Fernando Chirico.

Re: window transparent

Posted: Thu Jun 11, 2009 2:27 am
by Rathinagiri
Hi,

Kindly save 'c' pragma entries in a separate .c file and compile along with the prg and try.

Re: window transparent

Posted: Thu Jun 11, 2009 3:41 am
by fchirico
rathinagiri wrote:Hi,

Kindly save 'c' pragma entries in a separate .c file and compile along with the prg and try.
works perfectly.
Sorry for the ignorance.
Whenever you learn something new.

Thank you very much.

Regards, Fernando Chirico.

Re: window transparent

Posted: Thu Jun 11, 2009 3:52 am
by jrendon

Please try the following sample:

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 *
 * Copyright 2002-2009 Roberto Lopez <harbourminigui@gmail.com>
 * http://harbourminigui.googlepages.com/
*/

#include "minigui.ch" 

Function Main() 
Local nTra := 128, hWnd.....
Hi Grigory !

when compiling the code your post the following error appears:

Code: Select all

Start... 
DEMO.prg: In function `HB_FUN_SETTRANSPARENT':
DEMO.prg:57: error: `LWA_ALPHA' undeclared (first use in this function)
DEMO.prg:57: error: (Each undeclared identifier is reported only once
DEMO.prg:57: error: for each function it appears in.)
Finished With Errors. 
Can you help me please?

Saludos, Fernando Chirico.
Yes me to the same error on this line code

Code: Select all

pfnSetLayeredWindowAttributes((HWND) hb_parnl (1), 0, hb_parni (2), LWA_ALPHA);
Thank's
Juan Rendon

Re: window transparent

Posted: Thu Jun 11, 2009 3:56 am
by jrendon
fchirico wrote:
rathinagiri wrote:Hi,

Kindly save 'c' pragma entries in a separate .c file and compile along with the prg and try.
works perfectly.
Sorry for the ignorance.
Whenever you learn something new.

Thank you very much.

Regards, Fernando Chirico.
:? humm my ignorace is more .... How to compile the .c file ..? :?: :?:

Re: window transparent

Posted: Thu Jun 11, 2009 7:30 am
by gfilatov
jrendon wrote:

Hi Grigory !

when compiling the code your post the following error appears:

Code: Select all

Start... 
DEMO.prg: In function `HB_FUN_SETTRANSPARENT':
DEMO.prg:57: error: `LWA_ALPHA' undeclared (first use in this function)
DEMO.prg:57: error: (Each undeclared identifier is reported only once
DEMO.prg:57: error: for each function it appears in.)
Finished With Errors. 
Can you help me please?

Saludos, Fernando Chirico.
Yes me to the same error on this line code

Code: Select all

pfnSetLayeredWindowAttributes((HWND) hb_parnl (1), 0, hb_parni (2), LWA_ALPHA);
Hi Juan Rendon,

Please be so kind to try an updated sample below:

Code: Select all

/*
* MINIGUI - Harbour Win32 GUI library Demo
*
* Copyright 2002-2009 Roberto Lopez <harbourminigui@gmail.com>
* http://harbourminigui.googlepages.com/
*/

#include "minigui.ch" 

Function Main() 
Local nTra := 128, hWnd

   DEFINE WINDOW WinTR ;
      AT 0,0 ;
      WIDTH 300 ;
      HEIGHT 300 ;
      TITLE 'Transparent window' ;
      MAIN ;
      NOSIZE NOMAXIMIZE ;
      ON INIT ( hWnd := GetFormHandle('WinTR'), SetTransparent(hWnd, nTra) )

      @ 200,100 BUTTON But1 ;
         CAPTION "Click Me" ;
         HEIGHT 35 WIDTH 100 ;
         ACTION ( nTra := IIF(nTra == 128, 255, 128), SetTransparent(hWnd, nTra) )

   END WINDOW

   CENTER WINDOW WinTR

   ACTIVATE WINDOW WinTR

RETURN NIL 


#pragma BEGINDUMP 

#define LWA_ALPHA 0x02

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

HB_FUNC( SETTRANSPARENT )
{ 

   typedef BOOL (__stdcall *PFN_SETLAYEREDWINDOWATTRIBUTES) (HWND, COLORREF, BYTE, DWORD);

   PFN_SETLAYEREDWINDOWATTRIBUTES pfnSetLayeredWindowAttributes = NULL;

   HINSTANCE hLib = LoadLibrary("user32.dll");

   if (hLib != NULL)
   {
      pfnSetLayeredWindowAttributes = (PFN_SETLAYEREDWINDOWATTRIBUTES) GetProcAddress(hLib, "SetLayeredWindowAttributes");
   }

   if (pfnSetLayeredWindowAttributes)
   {
      SetWindowLong((HWND) hb_parnl (1), GWL_EXSTYLE, GetWindowLong((HWND) hb_parnl (1), GWL_EXSTYLE) | WS_EX_LAYERED);
      pfnSetLayeredWindowAttributes((HWND) hb_parnl (1), 0, hb_parni (2), LWA_ALPHA);
   }

   if (!hLib)
   {
      FreeLibrary(hLib);
   }

} 

#pragma ENDDUMP
I hope that helps. :|

Re: window transparent

Posted: Thu Jun 11, 2009 9:31 am
by Alex Gustow
Hi all!
I tried updated sample (Win98, Harbour 1.1.0.dev (Rev. 11020), HMGExt 1.6.67 ).

If it helps to someone:

1. Compile time warning
--------
Warning W8017 c:\borland\bcc55\include\winuser.h 3536: Redefenition of
'LWA_ALPHA' is not identical
--------

2. no effect in Win98 [of course :)]

Re: window transparent

Posted: Thu Jun 11, 2009 11:57 am
by fchirico
gfilatov wrote: Hi Juan Rendon,

Please be so kind to try an updated sample below:

Code: Select all

/*
* MINIGUI - Harbour Win32 GUI library Demo
*
* Copyright 2002-2009 Roberto Lopez <harbourminigui@gmail.com>
* http://harbourminigui.googlepages.com/
*/

#include "minigui.ch" 

Function Main() 
Local nTra := 128, hWnd.....................
....
I hope that helps.  :|[/quote]

This code works OK too, and I can compile directly in HMG.

Thank You Grigory.

Saludos, Fernando Chirico.