Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
This demonstrates how to invert colors, create pol...
Author:
Alex
E-mail:
Click to e-mail author
Submitted:
1/27/2002
Version:
VB5
Compatibility:
VB5
Category:
Windows API
Views:
13175
This demonstrates how to invert colors, create polygons, and delete them. It draws a 4 sided polygon then inverts the colors of the shape. If you change the form's background color, the inverted colors will be different. This can be easily modified to change the Form1.hdc to Picture1.hdc or whatever so you could make a picture drawing/editing/viewing program such as Photoshop where the user can edit the picture.
Declarations:
'Add a command button to the form. Leave the default 'names. 'Put this in the Form1 declarations section Private Type POINT_TYPE x As Long y As Long End Type Private Declare Function InvertRgn Lib "gdi32.dll" (ByVal hdc As Long, ByVal hrgn As Long) As Long Private Declare Function CreatePolygonRgn Lib "gdi32.dll" (lpPoint As POINT_TYPE, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Code:
'========================= '| Put in command button | '========================= Dim vertex(0 To 3) As POINT_TYPE ' Rectangle Array Dim RectRgn As Long ' Rectangle's Handle Dim retval As Long ' return value ' Load the vertices of the triangular region into the array. vertex(0).x = 150: vertex(0).y = 150 ' 1st point: (150,150) vertex(1).x = 250: vertex(1).y = 200 ' 2nd point: (250,200) vertex(2).x = 150: vertex(2).y = 250 ' 3rd point: (100,200) vertex(3).x = 100: vertex(3).y = 200 ' Create the polygonal region based on the array of vertices. hrgn = CreatePolygonRgn(vertex(0), 4, ALTERNATE) ' for a triangle, fill mode is irrelevant ' Invert the pixels within the triangular region on Form1. retval = InvertRgn(Form1.hdc, hrgn) ' Delete the region to free up resources. retval = DeleteObject(hrgn)
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement