Create Star Shaped Window

The following code allows a programmer to create any window shape they so desire. It is currently set to create a hollow star window that can be clicked through the centre of. The window can be dragged around by the mouse and the window is closed by double clicking the form.


'************************************************************
'Insert the following code into a form with 1 command button
'on it
'************************************************************
Dim down As Boolean
Dim t As Integer '
Dim w As Integer
'****************************************************************
' Name: Create Star Shaped Window
' Description: Can Change The Shape of any form and allows the user
' to drag it around the screen. It can also be clicked through
' the centre of the window!
'
' By: Andrew Monis
'
' Inputs:Look Below
' Returns:None
' Assumes:None
' Side Effects:The Border and Title Bar Disappears. Therefore,
' the programmer has to take care to position buttons etc
' correctly.
'
' Code provided by Andrew Monis 'as is', without
' warranties as to performance, fitness, merchantability,
' and any other warranty (whether expressed or implied).
'****************************************************************

Private Sub Form_Load()
  down = False
End Sub

Private Sub Form_DblClick()
  Unload Form1
End Sub



Private Sub Command1_Click()
  Dim point(5) As POINTAPI
  point(0).x = 10 * 5
  point(0).y = 30 * 5
  point(1).x = 60 * 5
  point(1).y = 30 * 5
  point(2).x = 20 * 5
  point(2).y = 60 * 5
  point(3).x = 40 * 5
  point(3).y = 10 * 5
  point(4).x = 50 * 5
  point(4).y = 60 * 5
  point(5).x = 10 * 5
  point(5).y = 30 * 5
  Form1.Show
  SetWindowRgn hWnd, CreatePolygonRgn(point(0), 6, 1), True
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, _
        x As Single, y As Single)
  down = True
  w = x
  t = y
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _
        x As Single, y As Single)
  If down Then
    Form1.Top = Form1.Top + y - t
    Form1.Left = Form1.Left + x - w
  End If
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, _
        x As Single, y As Single)
  down = False
End Sub

'************************************************************
'Insert the following code into a separate *.BAS module
'************************************************************
'****************************************************************
'Windows API/Global Declarations for :Change Form Shape
'****************************************************************
Public Declare Function SetWindowRgn Lib "user32" _
(ByVal hWnd As Long, ByVal hRgn As Long, _
  ByVal bRedraw As Boolean) As Long
Type POINTAPI
  x As Long
  y As Long
End Type

Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint _
        As POINTAPI, _
  ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long

Download Form1.frm
Download Module1.bas



Comments

  • h

    Posted by forvb on 07/12/2004 02:30am

    h

    Reply
  • Using CreatePolygonRgn

    Posted by Legacy on 05/24/1999 12:00am

    Originally posted by: John Corbin

    How does the * 5 after each of the x,y points work into the equation??

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • A modern mobile IT strategy is no longer an option, it is an absolute business necessity. Today's most productive employees are not tied to a desk, an office, or a location. They are mobile. And your company's IT strategy has to be ready to support them with easy, reliable, 24/7 access to the business information they need, from anywhere in the world, across a broad range of communication devices. Here's how some of the nation's most progressive corporations are meeting the many needs of their mobile workers …

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds