window transparent

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
jrendon
Posts: 92
Joined: Thu Aug 14, 2008 9:21 pm

window transparent

Post 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

User avatar
gfilatov
Posts: 742
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 28 times
Been thanked: 352 times
Contact:

Post 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-)
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

User avatar
fchirico
Posts: 324
Joined: Sat Aug 23, 2008 11:27 pm
Location: Argentina

Post 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.
Saludos, Fernando Chirico.

User avatar
Rathinagiri
Posts: 5304
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 189 times
Been thanked: 203 times
Contact:

Post by Rathinagiri »

Hi,

Kindly save 'c' pragma entries in a separate .c file and compile along with the prg and try.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
fchirico
Posts: 324
Joined: Sat Aug 23, 2008 11:27 pm
Location: Argentina

Post 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.
Saludos, Fernando Chirico.

User avatar
jrendon
Posts: 92
Joined: Thu Aug 14, 2008 9:21 pm

Post 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

User avatar
jrendon
Posts: 92
Joined: Thu Aug 14, 2008 9:21 pm

Post 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 ..? :?: :?:

User avatar
gfilatov
Posts: 742
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 28 times
Been thanked: 352 times
Contact:

Post 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. :|
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

User avatar
Alex Gustow
Posts: 290
Joined: Thu Dec 04, 2008 1:05 pm
Location: Yekaterinburg, Russia
Contact:

Post 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 :)]

User avatar
fchirico
Posts: 324
Joined: Sat Aug 23, 2008 11:27 pm
Location: Argentina

Post 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.
Saludos, Fernando Chirico.

Post Reply