|
VB Helper Newsletter
|
Rod Stephens
|
Jul 10, 2009 14:03 PDT
|
My hard drive upgrade went smoothly. It's amazing how much space you can
fit in those tiny little things. The new one is 500 GB and would easily
fit in your pocket.
(When I was a kid, my father brought home one of the early removable
disks--a precursor to floppy disks. This one was a package about 14
inches in diameter and about 3 inches thick. It held a single platter
that looked a lot like an LP. I don't know how much data it held but I
bet it was onlky a couple KB.)
----------
I rebuilt all of my XAML examples to fix some typographic problems on
their Web pages. (No one had mentioned these so I wonder if anyone's
looked at them yet.)
----------
My book "Visual Basic 2008 Programmer's Reference" received a couple
more new reviews. Yeah!
----------
Have a great week and thanks for subscribing!
Rod
RodSte-@vb-helper.com
Books To Keep: http://www.BooksToKeep.com
----------
*** Now Available ***
Beginning Database Design Solutions
http://www.amazon.com/exec/obidos/ASIN/0470385499/vbhelper/
Visual Basic 2008 Programmer's Reference
http://www.amazon.com/exec/obidos/ASIN/0470182628/vbhelper/
==========
VB6 Contents:
1. New HowTo: Get mother board serial numbers and CPU IDs in Visual
Basic 6
VB.NET Contents:
2. New HowTo: Make a continuously spinning cube by using XAML code in
Visual Basic 2008
3. New HowTo: Get mother board serial numbers and CPU IDs in Visual
Basic .NET
4. New Update for "Visual Basic 2008 Programmer's Reference"
==========
++++++++++
<VB6>
++++++++++
==========
1. New HowTo: Get mother board serial numbers and CPU IDs in Visual
Basic 6
http://www.vb-helper.com/howto_get_cpu_serial_number_id.html
http://www.vb-helper.com/HowTo/howto_get_cpu_serial_number_id.zip
The following function gets a WMI object and then gets a collection of
WMI_BaseBoard objects representing the system's mother boards. It loops
through them getting their serial numbers.
Private Function SystemSerialNumber() As String
Dim mother_boards As Variant
Dim board As Variant
Dim wmi As Variant
Dim serial_numbers As String
' Get the Windows Management Instrumentation object.
Set wmi = GetObject("WinMgmts:")
' Get the "base boards" (mother boards).
Set mother_boards = wmi.InstancesOf("Win32_BaseBoard")
For Each board In mother_boards
serial_numbers = serial_numbers & ", " & board.SerialNumber
Next board
If Len(serial_numbers) > 0 Then serial_numbers =
Mid$(serial_numbers, 3)
SystemSerialNumber = serial_numbers
End Function
The following code gets a WMI object and selects Win32_Processor
objects. It loops through them getting their processor IDs.
Private Function CpuId() As String
Dim computer As String
Dim wmi As Variant
Dim processors As Variant
Dim cpu As Variant
Dim cpu_ids As String
computer = "."
Set wmi = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & _
computer & "\root\cimv2")
Set processors = wmi.ExecQuery("Select * from Win32_Processor")
For Each cpu In processors
cpu_ids = cpu_ids & ", " & cpu.ProcessorId
Next cpu
If Len(cpu_ids) > 0 Then cpu_ids = Mid$(cpu_ids, 3)
CpuId = cpu_ids
End Function
==========
++++++++++
<VB.NET>
++++++++++
==========
2. New HowTo: Make a continuously spinning cube by using XAML code in
Visual Basic 2008
http://www.vb-helper.com/howto_xaml_spinning_cube.html
http://www.vb-helper.com/HowTo/howto_xaml_spinning_cube.zip
The following text describes key pieces of the XAML code. Download the
example and follow along.
The Window.Resources section defines a Storyboard that rotates the
GasketModel object to be defined later. It rotates the model 180 degrees
after 2 seconds, 259 degrees after 4 seconds, and then repeats forever.
<Storyboard x:Key="RotateModel">
<Rotation3DAnimationUsingKeyFrames BeginTime="00:00:00"
RepeatBehavior="Forever"
Storyboard.TargetName="GasketModel"
Storyboard.TargetProperty="(Model3D.Transform).(Transform3DGroup.Children)[0].(RotateTransform3D.Rotation)">
<SplineRotation3DKeyFrame KeyTime="00:00:02">
<SplineRotation3DKeyFrame.Value>
<AxisAngleRotation3D Angle="180" Axis="0,1,0"/>
</SplineRotation3DKeyFrame.Value>
</SplineRotation3DKeyFrame>
<SplineRotation3DKeyFrame KeyTime="00:00:04">
<SplineRotation3DKeyFrame.Value>
<AxisAngleRotation3D Angle="359" Axis="0,1,0"/>
</SplineRotation3DKeyFrame.Value>
</SplineRotation3DKeyFrame>
</Rotation3DAnimationUsingKeyFrames>
</Storyboard>
The Window.Triggers section defines an EventTrigger to start the
Storyboard when the window loads.
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard Storyboard="{StaticResource RotateModel}"/>
</EventTrigger>
Next the code creates a Viewport3D to hold all of the three-dimensional
pieces. It contains a Camera object that determines where the viewpoint
is and the direction it is looking.
<Viewport3D.Camera>
<PerspectiveCamera
Position="2, 2, 4"
LookDirection="-2, -2, -4"
UpDirection="0, 1, 0"
FieldOfView="60"/>
</Viewport3D.Camera>
The Viewport's Resources section defines a material that will be used by
most of the cube's sides.
<Viewport3D.Resources>
<!-- The material used by most surfaces. -->
<DiffuseMaterial x:Key="matGreen" Brush="LightGreen"/>
</Viewport3D.Resources>
Next the code defines a ModelVisual3D to hold the three-dimensional
objects. This object's Contents property holds a Model3DGroup that holds
the scene's lights and "physical" objects. The following code fragment
shows how this object hierarchy begins. It defines a transformation that
the Storyboard can rotate.
It also defines the scene's lights. When much of the scene uses the same
material (as in the case here), it can be fairly tricky to define lights
that give every part of the scene slightly different colors. If you use
different textures (colors, bitmaps, etc.) for the surfaces, then you
may only need ambient lighting.
<ModelVisual3D>
<ModelVisual3D.Content>
<Model3DGroup x:Name="GasketModel">
<Model3DGroup.Transform>
<Transform3DGroup>
<RotateTransform3D />
</Transform3DGroup>
</Model3DGroup.Transform>
<!-- Lights -->
<AmbientLight Color="#FF404040"/>
<DirectionalLight Color="Gray" Direction="-1,-2,0" />
<DirectionalLight Color="Gray" Direction="0,0,-1" />
<DirectionalLight Color="Gray" Direction="0,0,2" />
<DirectionalLight Color="#FF202020" Direction="1,0,0" />
The following code shows how the program defines the top of the cube.
The GeometryModel3D object's Material makes the top use the light green
material defined earlier.
The MeshGeometry3D object represents a three-dimensional object. Its
Positions attribute gives the coordinates of the top's corners. The
TriangleIndices attribute tells which triples of points should be
connected to make triangles in the scene.
<!-- Top -->
<GeometryModel3D Material="{StaticResource matGreen}">
<GeometryModel3D.Geometry>
<MeshGeometry3D
Positions="-1,1,1 1,1,1 1,1,-1 -1,1,-1"
TriangleIndices="0,1,3 1,2,3"/>
</GeometryModel3D.Geometry>
</GeometryModel3D>
Most of the cube's other faces are defined similarly. The front face,
however, displays a bitmap rather than a simple color so it is
different.
This object uses a GrometryModel3D and MeshGeometry3D similar to the
previous faces. It sets the MeshGeometry3D's Positions and
TriangleIndices properties as before (although it uses an element syntax
instead of an attribute syntax).
The TextureCoordinates property tells which points in the Positions list
match up with different parts of the bitmap. In texture coordinates, (0,
0) is the upper left corner with X increasing to the right and Y
increasing down.
The GeometryModel3D.Material defines the object's material. This example
uses an ImageBrush that displays the bitmap. You can also use a
VisualBrush that would display something drawn with WPF such as a Button
or TextBox.
<!-- Front -->
<GeometryModel3D>
<GeometryModel3D.Geometry>
<MeshGeometry3D>
<MeshGeometry3D.Positions>
<Point3D X="-1" Y="1" Z="1"/>
<Point3D X="-1" Y="-1" Z="1"/>
<Point3D X="1" Y="-1" Z="1"/>
<Point3D X="1" Y="1" Z="1"/>
</MeshGeometry3D.Positions>
<MeshGeometry3D.TextureCoordinates>
<Point X="0" Y="0"/>
<Point X="0" Y="1"/>
<Point X="1" Y="1"/>
<Point X="1" Y="0"/>
</MeshGeometry3D.TextureCoordinates>
<MeshGeometry3D.TriangleIndices>
<Int32Collection>
0,1,2 2,3,0
</Int32Collection>
</MeshGeometry3D.TriangleIndices>
</MeshGeometry3D>
</GeometryModel3D.Geometry>
<GeometryModel3D.Material>
<MaterialGroup>
<DiffuseMaterial>
<DiffuseMaterial.Brush>
<ImageBrush ImageSource="Rod.bmp"/>
</DiffuseMaterial.Brush>
</DiffuseMaterial>
</MaterialGroup>
</GeometryModel3D.Material>
</GeometryModel3D>
Those are the key elements. Download the example and experiment with it.
Note that this example builds each face as a separate GeometryModel3D
object. You could make them all use a single object but that can be
tricky.
The biggest problem is that faces could NOT share points defined in the
Positions property. When two surfaces share a point, Direct3D (which
does the drawing) averages the surface normals at that point to make the
two surfaces join smoothly. This works well for spheres and other shapes
where the tiles making up the shape should blend smoothly but it removes
the sharp edges between shapes such as cubes where the faces should not
join smoothly.
To use a single object for several faces, you would need to repeat the
points in the Positions property several times, once for each face that
used it. You could do that (and it might even give you better
performance) but it would be more confusing.
==========
3. New HowTo: Get mother board serial numbers and CPU IDs in Visual
Basic .NET
http://www.vb-helper.com/howto_net_get_cpu_serial_number_id.html
http://www.vb-helper.com/HowTo/howto_net_get_cpu_serial_number_id.zip
The following function gets a WMI object and then gets a collection of
WMI_BaseBoard objects representing the system's mother boards. It loops
through them getting their serial numbers.
Private Function SystemSerialNumber() As String
' Get the Windows Management Instrumentation object.
Dim wmi As Object = GetObject("WinMgmts:")
' Get the "base boards" (mother boards).
Dim serial_numbers As String = ""
Dim mother_boards As Object = wmi.InstancesOf("Win32_BaseBoard")
For Each board As Object In mother_boards
serial_numbers &= ", " & board.SerialNumber
Next board
If serial_numbers.Length > 0 Then serial_numbers =
serial_numbers.Substring(2)
Return serial_numbers
End Function
The following code gets a WMI object and selects Win32_Processor
objects. It loops through them getting their processor IDs.
Private Function CpuId() As String
Dim computer As String = "."
Dim wmi As Object = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & _
computer & "\root\cimv2")
Dim processors As Object = wmi.ExecQuery("Select * from
Win32_Processor")
Dim cpu_ids As String = ""
For Each cpu As Object In processors
cpu_ids = cpu_ids & ", " & cpu.ProcessorId
Next cpu
If cpu_ids.Length > 0 Then cpu_ids = cpu_ids.Substring(2)
Return cpu_ids
End Function
==========
4. New Update for "Visual Basic 2008 Programmer's Reference"
http://www.vb-helper.com/vb_prog_ref_updates.html
On page 196, Alex McKee noticed a typo. The second-to-last paragraph
ends with:
Subroutine AddCol uses similar methods to make a new Grid row.
This should be:
Subroutine AddCol uses similar methods to make a new Grid column.
(If you know of any other typos, broken code, or any other errors in
this of any of my books, I'd appreciate knowing.)
==========
Archives:
http://www.topica.com/lists/VBHelper
http://www.topica.com/lists/VB6Helper
http://www.topica.com/lists/VBNetHelper
Post questions at:
http://www.topica.com/lists/VBHelperQA
|
|
 |
|