Solved

Dithering

Posted on 1998-11-10
9
200 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 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

13 Experts available now in Live!

Get 1:1 Help Now