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 » Wed Jun 10, 2009 5:40 am

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: 667
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 24 times
Been thanked: 232 times
Contact:

Post by gfilatov » Wed Jun 10, 2009 7:15 am

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 » Thu Jun 11, 2009 12:49 am

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: 5264
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 169 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Thu Jun 11, 2009 2:27 am

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 » Thu Jun 11, 2009 3:41 am

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 » Thu Jun 11, 2009 3:52 am


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 » Thu Jun 11, 2009 3:56 am

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: 667
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 24 times
Been thanked: 232 times
Contact:

Post by gfilatov » Thu Jun 11, 2009 7:30 am

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 » Thu Jun 11, 2009 9:31 am

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 » Thu Jun 11, 2009 11:57 am

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