Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Nov 20, 2019 1:49 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Custom shpaed window
PostPosted: Mon Mar 14, 2011 9:37 am 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
Hi,

I am trying to get a custom shaped window using a black and white bmp file as mask. This is the code I am using in the Open event of the window:
declare function CreateRectRgn lib "gdi32" (left as integer, top as integer, right as integer, bottom as integer) as integer
declare function SetWindowRgn lib "user32" (hWnd as integer, hRgn as Integer, bRedraw as Boolean) as integer
Declare Function CombineRgn Lib "gdi32" (hDestRgn As integer, hSrcRgn1 As integer, hSrcRgn2 As integer, nCombineMode As integer) As integer


dim RegionTmp,RegionFinal as integer
Const RGN_OR = &h2
regionFinal= CreateRectRgn (0,0, 0,0)

Dim i as integer=1
Dim j as Integer=1

While j<MaskPicture.Height
While i< MaskPicture.Width
if MaskPicture.graphics.Pixel(i,j) <> &cFFFFFF then //Maskpicture is a picture in black and white of the same size as the window
RegionTmp = CreateRectRgn (i,j,i+3,j+3) //Line A
call CombineRgn(regionFinal, regionTmp, regionFinal, RGN_OR) //Stores the combination of the two regions in RegionFinal
end if

i=i+3 //Line B1
wend
i=1
j=j+3 //Line B2
wend

call SetWindowRgn (window1.Handle, RegionFinal, true)


This works, but the border of the resulting window is very pixelated (see it here: http://postimage.org/image/24sqvfqx0/)

Image

This is the mask I am using (http://postimage.org/image/24tmancas/):
Image

The problem comes from the lines marked as Line B1 and Line B2 in the code. If I increment i and j in only one or two unities I don't get a custom shaped window, but a strangely behaving window that when it is clicked on flikers, disappears, gets greyed and the controls on it cannot be seen anymore, makes other elements of Windows fliker too, ...

The width and height of the regions created in the code marked as Line A can be reduced to 1, but then I get a grid of points of the shape of my mask surrounded by empty spaces, of course.

Any idea of why the increment in lines B1 and B2 must be 3 to see the sought behavior? Or any advice on how to solve this?

Maybe I could do it by repeating the process using a step of 3 in lines B1 and B2, an increment of 1 in line A and an offset of the starting i and j values for each time the process is repeated, but this would require 9 repetitions...

Thank you.

Pixe

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom shpaed window
PostPosted: Mon Mar 14, 2011 9:33 pm 
Offline

Joined: Sat Oct 01, 2005 5:19 pm
Posts: 3216
Do you have rounded windows? Look at the pixels in the corners ... even Microsoft does a poor job of making windows in Windows.


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom shpaed window
PostPosted: Tue Mar 15, 2011 8:44 am 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
Thank you for your answer Jym.

No, the windows are not rounded (click on the screenshot I put in my first post to see it bigger).

I have been looking for other possibilities and found out that what I want to achieve can be done by using more recent API calls. I will post the code here once I have it working as I want. Most of that code (or maybe all of it) is in the WFS.

Still, if anyone has a clue of why my code above does not work when the picture is scanned pixel by pixel I would like to hear it.

Thank you again.

Pixe

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom shpaed window
PostPosted: Tue Mar 15, 2011 7:15 pm 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
I may still need some help with this. This is where I am now:
Image

You can see a thin (darker) border around my custom shaped window. Any advice as to how to get rid of that border?

This is my current code:
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (hwnd As Integer, nIndex As Integer, dwNewLong As Integer) As Integer
declare function SetLayeredWindowAttributes lib "user32" (hWnd as Integer, ColorRef as integer, AlphaCode as byte, dwFlags as integer) as Boolean //colorref is &h00bbggrr
Declare Function SetWindowPos Lib "user32" (hwnd as Integer, hWndInstertAfter as Integer, x as Integer, y as Integer, cx as Integer, cy as Integer, flags as Integer) as Integer


Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_FRAMECHANGED = &H20

Const WS_BORDER = &H800000
Const WS_EX_LAYERED=&h00080000

Const GWL_STYLE = -16
Const GWL_EXSTYLE=-20

call setwindowlong (me.Handle, GWL_STYLE,WS_BORDER) //In combination with SetWindowPos, reduces the border to ALMOST zero
call SetWindowPos(me.WinHWND, 0, 0, 0, 0, 0, SWP_NOMOVE +SWP_NOSIZE +SWP_FRAMECHANGED) //Apply border reduction

call setwindowlong (me.Handle, GWL_EXSTYLE,WS_EX_LAYERED) //Needed to make the next line work
call setlayeredwindowattributes(me.Handle, &h00FFFFFF, 0, 1) //Make transparent all white things


Any suggestion?

Thank you,

Pixe

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom shpaed window
PostPosted: Fri Mar 18, 2011 8:08 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
Well, not sure whether you like plugins, but I have a method for this:

Window.SetWindowMaskMBS(p as picture, redraw as Boolean, transparentColor as color) as Boolean

Or you use an OverlayMBS directly to draw a custom window.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom shpaed window
PostPosted: Fri Mar 18, 2011 4:29 pm 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
Hi Christian.

Thank you, I knew it can be done using your pluggins, but for now I am just doing this for fun and for learning, so I will not go for any pluggins yet.

Pixe

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
 Post subject: Re: Custom shpaed window
PostPosted: Fri Mar 18, 2011 4:58 pm 
Offline

Joined: Wed May 20, 2009 11:02 am
Posts: 423
Finally, adding a simple "me.maximize" at the end of my previous code was enough to make the frame "disappear".

So this can be used to make a custom shape window:
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (hwnd As Integer, nIndex As Integer, dwNewLong As Integer) As Integer
declare function SetLayeredWindowAttributes lib "user32" (hWnd as Integer, ColorRef as integer, AlphaCode as byte, dwFlags as integer) as Boolean //colorref is &h00bbggrr
Declare Function SetWindowPos Lib "user32" (hwnd as Integer, hWndInstertAfter as Integer, x as Integer, y as Integer, cx as Integer, cy as Integer, flags as Integer) as Integer


Const SWP_FRAMECHANGED = &H20

Const WS_BORDER = &H800000
Const WS_EX_LAYERED=&h00080000

Const GWL_STYLE = -16
Const GWL_EXSTYLE=-20

call setwindowlong (me.Handle, GWL_STYLE,WS_BORDER) //In combination with SetWindowPos, reduces the border to ALMOST zero
call SetWindowPos(me.WinHWND, 0, 0, 0, 0, 0, SWP_FRAMECHANGED) //Apply border reduction

call setwindowlong (me.Handle, GWL_EXSTYLE,WS_EX_LAYERED) //Needed to make the next line work
call setlayeredwindowattributes(me.Handle, &h00FFFFFF, 0, 1) //Make transparent all white things

me.maximize

_________________
Using RS2011r4.3 on Windows7.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group