Solved

Dithering

Posted on 1998-11-10
9
208 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
[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
  • 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
Technology Partners: 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!

 

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
 

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

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

688 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