Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CreatePatternBrush

Posted on 1999-07-23
2
Medium Priority
?
1,010 Views
Last Modified: 2012-08-14
Can anyone help me with an example using a bitmap and createpatternbrush as I can't seem to get this to work, I can use other brushes no problem.

Thanks very much
0
Comment
Question by:deadmeat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
Mirkwood earned 1200 total points
ID: 1526891
1) Create a new form in VB.  It will create a form called Form1 by default.  
2) Double click on the CommandButton Control to place "Command1" on your newly created form.  
3) Copy that form and paste it 2 times so as to create a CONTROL ARRAY - Command(0), Command(1), Command(2).  
4) Double click on the PictureBox Control to place "Picture1" on your form.
5) Rename this PictureBox to "picBrush"
6) Copy that PictureBox and paste it 2 times so as to create a CONTROL ARRAY - picBrush(0), picBrush(1), picBrush(2).
7) Create 3 bitmap files using Microsoft Paint.  Make the first a small white square that has a loose pattern of black dots.  Make the second the same size with a white background but a tighter pattern of black dots.  Make the third the same size with a white background and a tight pattern of black dots.  This is what will make up the dithering look.
8) Make the picture that goes in the picBrush(0) the 1st bitmap.  Make the picture that goes in picBrush(1) the 2nd bitmap.  Make the picture that goes in picBrush(2) the 3rd bitmap.
9) Insert the following code into Form1 :

-------------------------------------------------------------

Option Explicit

Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hBitmap As Long) As Long
Private Declare Function PatBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long

Private Sub Command1_Click(Index As Integer)
   
  ' Set your screen resolution here by entering the Screen Width/Height
  If DitherScreen(Index, 800, 600) = True Then
    ' Dithered Screen successfully
  End If

End Sub

Private Function DitherScreen(Index As Integer, TheWidth As Integer, TheHeight As Integer) As Boolean
On Error GoTo ErrorTrap

  Dim hBrush As Long
  Dim ROP As Single
  Dim DC As Long
  Dim Res As Long
   
  picBrush(Index).ScaleMode = 3    ' Pixel
  picBrush(Index).ScaleHeight = 8
  picBrush(Index).ScaleWidth = 8
  hBrush = CreatePatternBrush(picBrush(Index).Image)

  ROP = &HA000C9 'Light Dither 10100000
  'ROP = &HA0329 'Dark Dither  00001010
   
  DC = GetDC(0)
  'DC = GetDC(Form1.Command1.hwnd)
  Res = SelectObject(DC, hBrush)
  Res = PatBlt(DC, 0, 0, TheWidth, TheHeight, ROP)

  Res = DeleteObject(hBrush)
  Res = ReleaseDC(0, DC)
   
  DitherScreen = True
   
  Exit Function
   
ErrorTrap:
  DitherScreen = False
  Exit Function
  Resume
   
End Function

-------------------------------------------------------------


There you go.

You can download a sample of this off the internet at the following URL :  
ftp://ftp.one.net/pub/users/kevinw/VisualBasic/DitherScreen.zip 
0
 

Author Comment

by:deadmeat
ID: 1526892
Thanks, that was ideal
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question