Solved

Dithering

Posted on 1998-11-10
9
201 Views
Last Modified: 2010-04-30
I am trying to simulate the dither action that
happens when you shutdown a win9.x machine. I
want to use this feature in a VB6 project I am
doing.
** Update **
      I tried the code but to no avial. I need a solution that will not change
      the properties of the form itself. The form I am trying to "dither' has many
      img & user controls on it. I want to dither that whole screen ( and it's contents ).
      When I just dither the form, the other user controls are not effected. I want to dither the
      entire screen then pop-up a message box.
Thanks,
Steve
ace@cyberspy.com
0
Comment
Question by:sar70
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1444274
It's somewhere in the KB of MS. As soon as I have more time I will look it up.
0
 
LVL 14

Expert Comment

by:waty
ID: 1444275
You could download the following file, it shows you how to dither icons. It could be a start for you :
http://www.geocities.com/SiliconValley/Peaks/1797/iconproc.zip

0
 
LVL 1

Expert Comment

by:Sekans
ID: 1444276
sar70,
The following code will dither a form for you.  I'm not sure if this is what you want.  If it is not, please expand on your question.

Regards,
Sekans

Sub Dither(vForm As Form)
Dim intLoop As Integer
vForm.DrawStyle = vbInsideSolid
vForm.DrawMode = vbCopyPen
vForm.ScaleMode = vbPixels
vForm.DrawWidth = 2
vForm.ScaleHeight = 256
For intLoop = 0 To 255
    vForm.Line (0, intLoop)-(Screen.Width, intLoop - 1), RGB(0, 0, 255 - intLoop), B
Next intLoop
End Sub
0
 

Author Comment

by:sar70
ID: 1444277
I tried the code but to no avial. I need a solution that will not change
the properties of the form itself. The form I am trying to "dither' has many
img & user controls on it. I want to dither that whole screen ( and it's contents )
when I pop a question dialog box to the user.

I also downloaded that file, but I do not know how to pull out the right code
to test it on my project.

Thanks,
Steve
ace@cyberspy.com

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:sar70
ID: 1444278
Edited text of question
0
 
LVL 3

Accepted Solution

by:
HATCHET earned 60 total points
ID: 1444279
sar70,

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

HATCHET
0
 

Author Comment

by:sar70
ID: 1444280
Thank you for the effort, the only problem I have now
is re-painting the form I dithered. I tried most of the
methods (autoredraw, paint, refresh ...) but none of which
fixed the user controls. The only way I have found to get
around it was to togle the visiblity on/off of the user control
but if you know a better way please tell me.
Thanks again for the time!   A+ !
0
 
LVL 3

Expert Comment

by:HATCHET
ID: 1444281
Changing a maximized form from Visible to Invisible and then back to Visible is the only way I can see to refresh the screen as well.   =]

HATCHET
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1444282
You can do an InvalidateRect or WM_PAINT. Just ask a question.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel Vlookup to move data back to source. 4 83
Macro which automatically sends attachment to Outlook 14 61
using web browser with BING 40 110
MsgBox 4 46
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now