• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

Dithering

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
sar70
Asked:
sar70
  • 3
  • 2
  • 2
  • +2
1 Solution
 
MirkwoodCommented:
It's somewhere in the KB of MS. As soon as I have more time I will look it up.
0
 
watyCommented:
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
 
SekansCommented:
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
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!

 
sar70Author Commented:
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
 
sar70Author Commented:
Edited text of question
0
 
HATCHETCommented:
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
 
sar70Author Commented:
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
 
HATCHETCommented:
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
 
MirkwoodCommented:
You can do an InvalidateRect or WM_PAINT. Just ask a question.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now