Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can you make "odd shape" forms in vb? 6

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
0
0
US
can you make oddshaped forms with transparent backgrounds, such as sonique, with VB...
sonique.gif


I know you can do it with VC++...

also can you make Full screen programs and be able to switch resolutions with VB...

I'm not Talking about:
Setting BorderStyle to 0
and
Setting WindowState to 2

I mean "True" Full screen... Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
You should create 3 threads for these questions. Things could get confusing, especially for others who are looking for an answer on one of these questions, and if a discussion gets started.

1 - can you make oddshaped forms -yes
2 - switch resolutions with VB - yes

1. Here is a sloppy simple example:

Option Explicit
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, _
ByVal Y2 As Long) As Long

Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, _
ByVal bRedraw As Boolean) As Long

Private Sub Form_Load()
SetWindowRgn Me.hWnd, CreateEllipticRgn(0, -1, 532, 322), True
End Sub

2. There are API calls to get the total possible supported resolutions - which is what is first needed
Changing the resolution is much simpler.

Please, start a new thread [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
1)

U want this to create idd shaped forms ....


2)
Regarding screen resolution, i will never suggest it, bcos u seldom can restore completely the original settings once u change the screen resolution..

here u will see some code that will do it for u

All the Best
Praveen Menon
pcmin@rediffmail.com
 
WOW... I never could figure that out... (i never dug that deep though...)
And I guess if you want to eliminate the title bar to make your own... buttons...
You...
Set BorderStyle to 0

and use...
Form1.WindowState to 0 or 1
to minimize and restore... right.

THNX Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Praveen,
What OS did you use for Odd Forms?
Win XP...
Is this code NOT compatible with NT (4.0)?
I ran it and got Dr. Watson (Bye Bye VB)

reference Link:
Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
or you can ensure that the 'unusual' region is completely within the confines of the window's client area, as this would also eliminate the title bar (and borders) from view. Adding your own buttons for closing, minimising etc is pretty easy - but how about dragging the window around? There's a fairly standard technique for doing this, as illustrated below (this leverages a slightly modified version of CCLINT's example code):
[tt]
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "User32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub ReleaseCapture Lib "User32" ()
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2

Private Sub Form_Load()
Form1.Width = 600 * Screen.TwipsPerPixelX
Form1.Height = 400 * Screen.TwipsPerPixelX
SetWindowRgn Me.hWnd, CreateEllipticRgn(8, 64, 532, 322), True
End Sub


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lngReturnValue As Long

If Button = 1 Then
Call ReleaseCapture
lngReturnValue = SendMessage(Form1.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End Sub

 
related link...
Odd Shaped Buttons With VB: thread222-445048

What about using a bitmap as the Shape With a transparent Mask Color...

Praveen, I think this is what you used Right?

And is there a listing of gdi32.DLL available? Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
OK...

I just Found another site with a tutorial....


Download the zip and read through the Help file...
Zip: rgnpower.zip
Help: RgnHelp2.hlp


It explains all the Functions...
Code:
CombineRgn	Combines two existing regions into a new region.
CreateEllipticRgn	Creates an elliptical region.
CreateEllipticRgnIndirect	Creates an elliptical region.
CreatePolygonRgn	Creates a polygonal region.
CreatePolyPolygonRgn	Creates a region consisting of series of closed polygons.
CreateRectRgn	Creates a rectangular region.
CreateRectRgnIndirect	Creates a rectangular region.
CreateRoundRectRgn	Creates a rounded rectangular region.
EqualRgn	Determines whether two regions are identical.
FillRgn	Fills the given region with a brush pattern.
FrameRgn	Draws a border for a given region.
GetPolyFillMode	Retrieves the current polygon fill mode.
GetRgnBox	Retrieves the coordinates of the bounding rectangle of a region.
InvertRgn	Inverts the colours in a region.
OffsetRgn	Moves the given region.
PaintRgn	Fills the region with the selected brush pattern.
PtInRegion	Tests whether a point is within a region.
RectInRegion	Tests whether any part of a rectangle is within a region.
SetPolyFillMode	Sets the polygon fill mode.
SetWindowRgn	Sets a window region to a window.

Plus a lot more...

Thanks to Everyone for the post...

This is pretty stuff is pretty interesting...

If anyone has any other Ideas... Please post them Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
GDI32 comes with windows... it is a system file.. like user32.dll All the Best
Praveen Menon
pcmin@rediffmail.com
 
strongm,

aint this sub supposed to be in the form_mousedown event?
Form_MouseMove is gonna be pretty expensive, i suppose...

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lngReturnValue As Long

If Button = 1 Then
Call ReleaseCapture
lngReturnValue = SendMessage(Form1.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End Sub
All the Best
Praveen Menon
pcmin@rediffmail.com
 
Doesn't mouse down only get called ONCE when you press the mouse button...

(I could be wrong...)

I thought the order of events was:
Code:
Mouse_Down 'one time
Mouse_Move 'continuous until mouseup
Mouse_Up   'one time

...Just out of curiosity. Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Mouse move event fires when ever u move the mouse inside the form. not necessary that the mouse button is pressed.. All the Best
Praveen Menon
pcmin@rediffmail.com
 
but still...
Does mouse_down Fire once...
or until mouse_up is fired Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Ok.. Praveen,
Technically you are right...
You can use either/or...
But I think they are both about the same...

Is there a way you know of to check for speed...

Visually I can't see a difference.

Actually... I don't think there is a difference since they both cut off if the mouse is not pressed...

If the mouse is pressed they are going to fire the same way, either way... if not they will not... still more or less the same process...


Visually the Equivalent is (in theory)...

if Mouse_Move then
if Button = 1 then
...move window...
end if

If Mouse_Button then
end if
end if

if Mouse_Move then
If Mouse_Button then
if Button = 1 then
...move window...
end if

end if
end if

So the Only difference is (1) if call...
so... if you want to call that expensive or not, can be contaversial...

I DO see where you are coming from though...

In order to save resources for future needs...
You DO want to go with Mouse_Down

If you don't care about speed or system resources (and YOU WILL BE some-day) you CAN use either/or.

Thanks For Pointing that out Praveen Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Then again... If you DO NOT move the mouse... and the button IS PRESSED, the Mouse_Down WILL BE being fired and the Mouse_Move WILL NOT...
But if the Mouse is not moving, the window will not be able to move.
So, also in theory, You could be wasting resources by holding the mouse button down while not moving the mouse...
Because of the fact it will actually go through the whole process of moving the window even though It is not moving...

So, to add to the complication...

Is it more expensive to execute an IF statement when the mouse IS moved and the button IS NOT Pressed...
Or execute the WHOLE PROCESS of moving the window, even if it is not being moved, while the button IS being pressed, and the mouse IS NOT moving?

...Any Comments or Suggestions?

Also how would you Re-Size a window...
is there a call you make like the one to move the window?...

If Button = 1 Then
Call ReleaseCapture
lngReturnValue = SendMessage(Form1.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Yep, the code could quite happily be placed in the MouseDown event

Cost is a minor concern once the button is pressed, since all mouse messages then use the default message processing loop - i.e, once we send the WM_NCLBUTTONDOWN message VB has no involvement in what is going on until the mouse button is released.

It is perhaps a concern BEFORE the button is pressed, since every pixel the mouse moves results in a MouseMove event, even if the only thing that happens is a brief If statement that fails.
 
True strong.. i was concerned about the event getting fired, even tho we want the code to be executed when we click the mouse and drag the form to a new place..
But in my POV, everything that results in firing unwanted code is bulky...

Just a thot.. All the Best
Praveen Menon
pcmin@rediffmail.com
 
What call do you make to resize a window manually?

or

do you just use me.width / me.height & mousedown/up...

Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Well, me.width/me.height probably are not all that useful when you are considering an irregular area. In the examples provided above, for example, we've happen to have been looking at an elliptical region. This is pretty easy to resize, since the parameters used in creating it are the corners of a bounding rectangle. But if your shape is more complex that this...
 
...I'm using A rounded rectangle... constrained to the width and height of the form...
border style = none
Appearance = Flat
scale mode = pset

using:
scalewidth/scaleheight to get the width/height (in pixels)
and scalex/scaley (X,vbpixels,vbtwips) to set the size of the form

And drawing the custom frame with a series of filled circles (for the corners) and filled boxes (for the center)
using the radius of the circles and for/next loops to generate a gradient from specified color to the edge...

I made a picture box in the lower right corner, and fomed it into a shape I am using as a grab-handle,
and I am using it's mouse down/move/up to set an initial point and initial size...
then modifying the size relative to the mouse and those 2 initial items...
similar to: width = oldWidth + (mouseX - oldX)
there is a global Var (of boolean) that is switched on and used to restrict reentry to the mousedown event to set the initial points...
If the trigger is switched the commands in the mousemove are active... (resizing the window)
Finally the trigger is switched to off when mouseUp occurs
(All three using the left mouse button)

I will post the code here tomorrow when I get to work.

Let me know if you have any alternative suggestions...

If you don't understand what I am talking about...
Like I said I will post the code tommorrow, and you can read through it...

Note: when using PictureBoxes As Buttons...
I Usually rename them to CommandX (Command1...) such as a command button is named... If it keeps it's properties as a picture box... For only displaying a picture... It remains Picture1

All PictureBoxes AND CommandButtons Used in My Code That follows on this post will ALL be pictureboxes! Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top