Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all 1484 articles
Browse latest View live

VB6 3D-Surface-Plotting (based on RichClient5)

$
0
0
Just another Demo, which applies antialiased and semitransparent Drawing-commands in a somewhat similar way as the "Bezier-Art"-Demo here:
http://www.vbforums.com/showthread.p...ezier-Art-quot

But in a perhaps more useful (or practical) fashion...

The implementation allows for a few nice things as rotation around the Z-axis (Azimuth) - as well as changing the Altitude per Mouse (the height above the x-y-plane).
There's a few predefined Formulas in the appropriate Combo-Box, but you can type in your own stuff as well.
To support symmetrical Surfaces as e.g. spheres or "donuts", the Plotter allows also the formula: z² = f(x,y) (as an alternative to the usual z = f(x,y)).

But here's a few screen-shots which are far more telling I assume:




This is the wellknown "saddle":




And this is the same saddle-plot. but now with an altitude of 90 degrees (full Top-View):




Here a few more shots, but only as "normal links", to not clutter the posting with too many images:
http://vbRichClient.com/Downloads/3dSrfPlot1.jpg
http://vbRichClient.com/Downloads/3dSrfPlot4.jpg
http://vbRichClient.com/Downloads/3dSrfPlot5.jpg
http://vbRichClient.com/Downloads/3dSrfPlot6.jpg

Ok, finally the Source-code-link (as said, dependent on the RC5-libs which one can download from vbRichClient.com):
(only 7KB, so it's a pretty small code-base to study).

Have fun with it.

Olaf
Attached Files

VB6 - RicherLabel UserControl

$
0
0
Sometimes you need to use one or more Labels on a Form that just need to offer a little bit "richer" options.

Maybe you need to have some of the text bold or underlined. Maybe you need a superscript or subscript. Maybe you need to use a symbol from one of the symbol fonts like Windings. Maybe you need a second color to highlight a word or a symbol.

RicherLabel offers a way to do this without a lot of trouble. It basically accepts a Caption property with a simple markup syntax and renders the Caption according to the markup instructions.

You can even do simple "color blinking" as shown in the demo.

Some limitations:

  • It doesn't support a BorderStyle.
  • No multiline support.
  • No word-wrap.
  • No justification (always left-justified).


If you need some with a border and some without, make another copy of the UserControl and name it something like RicherLabelB and then set the UserControl's BorderStyle. Or you might rework RicherLabel to draw its own border and add a BorderStyle property to it.

You could also work out a scheme for it and then implement word-wrap and multiline labels.

The RicherLabel markup consists of instructions of one character escaped using the ` (accent grave) character. You could easily change this yourself to something else, or maybe change the way the color table works, etc. You can also strip out functions you don't need pretty easily to reduce the compiled size of programs using RicherLabels.

Name:  sshot1.png
Views: 39
Size:  8.9 KB

Demo: Design Time


Name:  sshot2.png
Views: 49
Size:  16.7 KB

Demo: Run Time
Attached Images
  
Attached Files

VB6 Simple Async-Download-Ctl for multiple Files

$
0
0
Just a simple demonstration of the AsyncDownload-Feature, any VB-Usercontrol has already built-in.

It supports http- and ftp-downloads for files up to 2GB.

What's perhaps interesting from a Control-Design-point, is the organization of the whole thing.

There's a Host-Control: ucAsyncDLHost which only ensures Scrolling and Event-Delegation of the
separate Download-Entries it manages and visualizes.

The AsyncDownload itself is performed within another (Child-)Control: ucAsyncDLStripe,
which is a windowless-Control (containing a simple Progress-Bar and a simple Stop/Resume-Button).

So, those windowless-"Stripe-entries" make up the "Rows" within the outer ucAsyncDLHost Control.

Here's the usual Screenshot and the Download-Link:

http://vbRichClient.com/Downloads/As...nloadDemo2.zip

Olaf
Attached Images
 

MCOULTER876 - My Entire Code Bank

$
0
0
Here is my entire code bank (too long for vbforums.com to accept):

<removed by moderator>

MCOULTER876 - My Entire Code Bank

Animated Spinner Class [vbRichClient5]

$
0
0
After contributing to the following thread (http://www.vbforums.com/showthread.p...Wheel-Spinning), I thought others might be interested in an animated spinner, so I packaged my code into a class and added a simple demo form that allows you to play around with the parameters in real-time.

Demo Screenshot:

Name:  Spinner6.png
Views: 5
Size:  23.8 KB

Samples:

Name:  Spinners.png
Views: 36
Size:  47.1 KB

Source code:

AnimatedSpinner.zip

Features:
Clockwise/Counter-Clockwise animation
Adjustable Speed of spin in, normal spin, and spin out frames
Number of segments to draw
Size of the spinner
Padding between the edge of the spinner box and the spinner
Base Color of the spinner
Background color of the spinner (including transparent background)
Size of the hole in the middle of the spinner
Total Degrees that the spinner should span
Degrees of margin between segments
Gaussian Blur, optionally clipping blurred edges

NOTE: This demo requires the vbRichClient5 framework to be registered on your development system: http://www.vbrichclient.com/#/en/Downloads.htm

This code is free to use for any purpose. No warranties, not extensively test.

Enjoy!
Attached Images
  
Attached Files

Hidden Conversations V1

$
0
0
Ever wonder who might be listening to your online conversations. Aside from all the
possibilities with Social Media sites, your email is anything but private. And it
doesn't matter if you are using SSL (Secure Sockets Layer) or TLS (Transport Layer
Security). These security systems are only for the transport layer, and do not cover
storage. And even if the messages get stored encrypted, guess who controls the
Encryption/Decryption. Your only way around it is to encrypt the message before you
send it, and the person at the other end must have the decryption key. And if you are
using central storage for your messages (AKA Cloud computing), the encrypted message
is always available for someone to try and figure out the key.

Hidden Conversations is a 2 part private messaging system with built in
encryption/decryption. Version 1.0 uses Symmetric keys that start with a shared secret,
and change with every record sent. Because shared secrets are relatively easy to crack,
Version 2.0 will use 2048 bit Public/Private keys to start the conversation. Version
1.0 works for relatively short messages, but long messages that get broken up into
multiple packets will cause problems. Therefore, Version 2.0 packets will be structured
with a record length.

The 2 programs (Host & Client) are self contained, and do not require any additional
controls. Although the Cryptographic calls will probably work on most Windows operating
systems, the TCP/IP calls require a dual stack operating system that supports both IPv4
and IPv6. This more or less restricts it to Windows Vista or later. Because of the lack
of a full IPv6 network, IPv6 has not been tested yet.

J.A. Coutts
Attached Files

VB6 Png-Alpha-Rendering (using WIA)

$
0
0
So, yeah - this Demo is not dependent on vbRichClient for a change ;), but on a System-lib instead (wiaaut.dll),
which comes pre-installed on newer systems.

The Demo-Code contains two Classes:
cPngCache (showing how to read Pngs per WIA, copying Alpha-Channel-ByteArray-content - premultiplying it - converting it into a 32bpp-VB-StdPicture)
cButton (makes use of the Class above, then dealing appropriately with Multi-State PNG-content ... ButtonNormal, ButtonPressed, Hovered, etc.)

Well, not much more to say, the Demo is small and the classes do not contain much code ... here's a screenshot:



And here the Download-Link: http://vbRichClient.com/Downloads/PngAlphaRendering.zip (~200KB, containing a few Image-Resources)

Olaf

VB6 Png-Alpha-Rendering with GDI+ (alternatively per WIA)

$
0
0
So, yeah - this Demo is not dependent on vbRichClient for a change ;), but on a System-lib instead,
which comes pre-installed on newer systems.

The Demo-Code contains two Classes:
cPngCache (showing how to read Pngs per GDI+ (alternatively per WIA), copying premultiplied Alpha-Channel-content - and converting (caching) it into a 32bpp-VB-StdPicture)
cButton (makes use of the Class above, then dealing appropriately with Multi-State PNG-content ... ButtonNormal, ButtonPressed, Hovered, etc.)

Well, not much more to say, the Demo is small and the classes do not contain much code ... here's a screenshot:

Edit: Changed the Demo to use GDI+ as a default now, since the WIA-libs are not on each and every XP-system (though GDI+ usually is).
The older WIA-class is still contained in the *.vbp though.



And here the Download-Link: http://vbRichClient.com/Downloads/PngAlphaRendering.zip (~200KB, containing a few Image-Resources)

Olaf

VB6 - JsonBag, Another JSON Parser/Generator

$
0
0
With SOAP basically a dead duck and XML itself fading in importance, JSON is becoming more and more important as a serialization format today.

I've seen a number of VB6 JSON implementations around, including a couple posted right here in the CodeBank. Sadly none of them are very good, with little quirks and latent bugs (like improperly handling numeric data). Most of these ignore and flout the JSON standards at JSON too!

In any case I have my own implementation designed to conform as closely as possible to the standard, and now at version 1.6 it seems mature enough to share. I rewrote my notes into six pages of documentation which should make it a bit easier for others to use.


Bug reports are welcome. Though it seems to be working fine it is hard to prove code to be correct and there are probably edge cases I've never encountered.

Performance seems more than adequate for its purpose, which is mainly access to cloud computing services. Local config files are probably best still handled as plain old INI format files, though one could use JSON for that as well I suppose.


There is just one Class involved: JsonBag.cls, and as the documentation suggests it should be easy enough to import into a VBA host (Excel, etc.) as long as you tweak the API calls for 64-bit hosts when required.


The attachment includes this Class along with the documentation in RTF format, packaged up as a testbed Project JsonBagTest.vbp:

Name:  sshot.png
Views: 246
Size:  20.5 KB

As you can see JsonBag supports a Whitespace property to format JSON for readability. By default compact JSON is generated.


Accessing the "document model" and creating JSON documents in code is easy enough. This is illustrated by a fragment from the test Project:

Code:

Private Sub cmdGenSerialize_Click()
    With JB
        .Clear
        .IsArray = False 'Actually the default after Clear.

        ![First] = 1
        ![Second] = Null
        With .AddNewArray("Third")
            .Item = "These"
            .Item = "Add"
            .Item = "One"
            .Item = "After"
            .Item = "The"
            .Item = "Next"
            .Item(1) = "*These*" 'Should overwrite 1st Item, without moving it.

            'Add a JSON "object" to this "array" (thus no name supplied):
            With .AddNewObject()
                .Item("A") = True
                !B = False
                !C = 3.14E+16
            End With
        End With
        With .AddNewObject("Fourth")
            .Item("Force Case") = 1 'Use quoted String form to force case of names.
            .Item("force Case") = 2
            .Item("force case") = 3

            'This syntax can be risky with case-sensitive JSON since the text is
            'treated like any other VB identifier, i.e. if such a symbol ("Force"
            'or "Case" here) is already defined in the language (VB) or in your
            'code the casing of that symbol will be enforced by the IDE:

            ![Force Case] = 666 'Should overwrite matching-case named item, which
                                'also moves it to the end.
            'Safer:
            .Item("Force Case") = 666
        End With
        'Can also use implied (default) property:
        JB("Fifth") = Null

        txtSerialized.Text = .JSON
    End With
End Sub

Attached Images
 
Attached Files

Fuzzy Search Demo [VB6/vbRichClient5]

$
0
0
The vbRichClient5 library for VB6 includes support for the SQLite database engine, and acts as a wrapper for the user defined collation (sort) and user-defined functions features of SQLite. Thanks to the work of Olaf Schmidt, it is really easy to create standard VB6 classes that extend the functionality of SQLite.

I've been experimenting with some "fuzzy" search routines using my own custom collation and ranking code (modified Metaphone), intertwined with the vbRC5 ranking code (RatCliff), and have put together a little demo here:

RC5SearchDemo.zip

Before you can use this demo, you will need to download and register the vbRichClient5 library from http://www.vbrichclient.com/#/en/Downloads.htm

"Search" is a really interesting (and constantly evolving) area of human>computer interaction, and I think VB6 is somewhat lacking (no native regex, no built-in fuzzy algorithms like metaphone, ratcliff, etc...). I'm really hoping for some input from the community on how to make this fuzzy matching better, under more search/language scenarios - for the benefit of all. Please feel free to hack away with the above demo and report back with your results, and let's see if we can create a search algorithm (or suite of algorithms) that produce consistently useful results.
Attached Files

DNS Filter

$
0
0
Our DNS server was being used as an attack vector against primarily Chinese servers. DNS by preference uses UDP packets instead of TCP packets. The UDP protocol is much faster than TCP, but unlike TCP it does not perform a handshake. It is essentially one way communication with no confirmation of receipt. Because of that, it is possible to fake the sender IP address, and this is what the attackers were doing. A 128 byte request was causing a 388 byte invalid response to be sent to the target server. By enlisting many hacked computers, the attackers could overwhelm the target. Because the hackers were sending false source information to legitimate DNS servers, it was difficult to track the actual source.

Our DNS server has the capability to block source addresses that send too many requests per second, but it was getting to be a pain to update the list, and the list itself was getting quite long. So I set about to design a filter. For this purpose I am using the Windows Packet Filter Kit from NT Kernel Resources. This high performance packet filtering framework hooks the NDIS (Network Driver Interface Specification) driver in your Windows Operating System. This allows me to inspect each packet and only target incoming Port 53 UDP packets for further processing. A 20 element cache is maintained with the Source IP Address, the Question Type, the Question, and a Timeout. When a DNS request is received, the program checks the cache and if does not exist or is timed out, it is added with the maximun timeout. If it already exists, the timeout is reset to the maximum and the record dropped. A timer decrements the timeout values every second.

I had considered building this progam some time ago because some abusive DNS servers were using brute force by sending multiple requests for the same thing. The worst offender was Yahoo, which not only sent multiple requests from the same server, but also used multiple servers for the same thing. These hackers only served to elevate the priority.

This program is a work in progress, and once it has proven itself, I will convert it to run as a Service. To run as a Service, I must ensure that the program makes no attempt to display to the Desktop, as this can cause the operating system to get into an endless loop when the user is logged off and the desktop is not available. All potential errors must be trapped, and logged to the Event or other log.

J.A. Coutts
Edit: When the filter was put into production, a bug was discovered that caused Overflow errors in the PacketRead routine. The problem was caused by Message Types greater than 32,767, which got interpreted as negative numbers. The problem was resolved by changed the data type to long integer from integer. To facilitate this resolution, Error Trapping and a logging function was added.
Attached Files

Changing The Shape of your Form and Showing Transparent animation on the Desktop

$
0
0
This is a simple Form transparency demo. It simply demonstrates how you can make your Form any shape you want and show pictures and animation on the desktop in the shape of your Form. It basically shows you how to change the shape of your Form to almost anything or shape you would want and to show animation (using animated gif) on the desktop

Left mouse down to move the Form

Right mouse down for options
Attached Files

DNS Filter Service

$
0
0
This is the Service Version of the Filter program previously posted. The Service version of DNS Filter not only requires the WinpkFilter from NT Kernel Resources (free for personal use) but also the NT Service Control from Microsoft (freely available). So far it has been tested on Server 2000 and Windows Vista.

It consists of 2 programs; one is the actual service, and the other to load and manage the Service. Although the service can install itself, the management program is needed to store a couple of parameters. Because the Service runs in Session 0, the Registry values must be placed in the Registry in a location that allows System access. Because the management program runs in Session 1 or more, it has no actual interaction with the service. It deals entirely with the Service Manager (services.msc). I used to use the System Tray for interaction between a service and the desktop, but that is now difficult to do with Session Isolation. I also used to use the Dart Service Control (which I prefer), but that requires the user to purchase a license.

J.A. Coutts

Note: DNSFilSvc was designed to be run in Development mode as well as a Service. To compile the service, change the IsService flag to True. In order to get the logging routine to function on Server 2000, I had to manually create the DNS sub-directory in the Logfiles directory. Server 2000 would not automatically create it.

Addendum: I finally got the low level filtering in WinpkFilter working. This allowed me to only process Port 53 UDP requests, thereby reducing the amount of code needed and theoretically reducing system resources required. The problem turned out to be bad type declarations in the sample code provided.

Bug Fix 11/12/2013: A bug was discovered that randomly allowed some duplicated queries to get through the filter. A fixed length buffer (128 bytes) was maintained to receive incoming query names. This string information was of variable length, but always ended in a null character. When the name was added to the string array, VB only recognized up to the null character. If the previous query was longer than the current one, extra characters got left behind in the fixed length buffer. For example, if "12345678.com" was followed by "123456.com", what was shown in the buffer was "123456.com m", which of course did not compare to what was already in cache. This was corrected by clearing the fixed length buffer after every query. At the same time, table updates were sped up by maintaining an end of cache pointer.
Attached Files

Alphablending - A Simple Demo

$
0
0
This small demo shows you how you can alpha blend one picture onto another. In this demo only part of the target picture is alpha blended.
Attached Files

Slot Machine

$
0
0
This is a simple demo of a slot machine. It has three spinners that simulate a slot machine when the handle is pulled down (this uses a button instead of a handle).
Attached Files

Desktop Digital Clock

Simple way to Export FlexGrid to Excel

$
0
0
I see many people asking how to export a VB6 MSFlexgrid to an Excel workbook....this short code with a couple of simple For-Loops is an easy way to do it (Make sure you have a REFERENCE to MS Excel in your project).

Code:

Private Sub smnuExportExcel_Click()
    Dim oExcel As excel.Application
    Dim oWb As excel.Workbook
    Dim oSheet As excel.Worksheet
    Dim x As Integer
    Dim y As Integer
    Set oExcel = New excel.Application
    Set oExcel = CreateObject("Excel.Application")
    Set oWb = oExcel.Workbooks.Add
    Set oSheet = oWb.Worksheets("Sheet1")
    With oSheet
    For x = 0 To flexgrid1.Rows - 1 
        For y = 0 To 6
            .Cells(x + 1, y + 1) = flexgrid1.TextMatrix(x, y) 'Note, "x + 1" as Excel refers to rows and columns beginning with 1, whereas VB6's flexgrids start with 0.
        Next y
    Next x

    oWb.SaveAs FileName:=App.Path & "\myExcelFile.xlsx"
    oExcel.Visible = True
    Set oWb = Nothing
    Set oExcel = Nothing
End Sub

Excel Writer

$
0
0
Project to create an ActiveX DLL which is capable of writing Excel 2007 xlsx files directly.
No need for Excel to be installed.
An xlsx is just a ZIP archive with all kind of XML files and bunch of tables.
After a few weeks of reverse engineering I was able to create this project.

There are no pivot-tables or charts!

This project uses source code written by:
  • Andrew McMillan -> clsZipClass and clsZipFile
  • Steve McMahon -> clsStringBuilder
  • LaVolpe -> Collection Key routines


Also needed is the zlibwapi.dll which can be found in the zlib125dll.zip


Sample code (needs a reference to the created ActiveX DLL)

Code:

Option Explicit

Private Sub Command1_Click()
  Dim cExcel As clsExcel2007
  Dim cWS As clsWorksheet2007
  Dim tCell As tpExcelCell2007
 
  Set cExcel = New clsExcel2007
 
  ' Add the first Worksheet
  Set cWS = cExcel.AddWorkSheet("My first sheet")
 
  tCell = cExcel.NewCellType
  tCell.Row = 1: tCell.Column = 1:  tCell.Value = "A1"
  cWS.AddCellType tCell
 
  tCell = cExcel.NewCellType
  tCell.Row = 2: tCell.Column = 1:  tCell.Value = "A2"
  cWS.AddCellType tCell
 
  tCell = cExcel.NewCellType
  tCell.Row = 3: tCell.Column = 1:  tCell.Value = "A3"
  cWS.AddCellType tCell
 
  tCell = cExcel.NewCellType
  tCell.Row = 4: tCell.Column = 1:  tCell.Value = "A4"
  cWS.AddCellType tCell
 
  tCell = cExcel.NewCellType ' using empty values
  tCell.Row = 1: tCell.Column = 2: tCell.Value = "B1":  tCell.BackColor = vbRed
  cWS.AddCellType tCell
 
  tCell = cExcel.NewCellType ' using empty values
  tCell.Row = 2: tCell.Column = 2: tCell.Value = "B2":  tCell.FontBold = True
  tCell.Comment = "Font Bold"
  cWS.AddCellType tCell
 
  tCell = cExcel.NewCellType ' using empty values
  tCell.Row = 3: tCell.Column = 2: tCell.Value = "B3":  tCell.ForeColor = RGB(0, 127, 0)
  cWS.AddCellType tCell
 
  tCell = cExcel.NewCellType ' using empty values
  tCell.Row = 4: tCell.Column = 2: tCell.Value = "B4":  tCell.BorderLeftColor = vbBlue
  tCell.Comment = "Blue border"
  cWS.AddCellType tCell
 
  ' Add a second WorkSheet
  Set cWS = cExcel.AddWorkSheet("Sheet 2")
 
  tCell = cExcel.NewCellType
  tCell.Row = 1: tCell.Column = 1:  tCell.Value = Atn(1) * 4
  tCell.FormatString = "0.00"
  cWS.AddCellType tCell
 
  tCell = cExcel.NewCellType
  tCell.Row = 2: tCell.Column = 1:  tCell.Value = Date
  tCell.FormatString = "dd MMM yyyy"
  tCell.Comment = tCell.FormatString

 
  tCell = cExcel.NewCellType
  tCell.Row = 2: tCell.Column = 1:  tCell.Value = TimeSerial(25, 34, 12)
  tCell.FormatString = "[h]:mm"
  tCell.Comment = tCell.FormatString
  cWS.AddCellType tCell


  tCell = cExcel.NewCellType
  tCell.Row = 1: tCell.Column = 2: tCell.Value = "MergeCell"
  cWS.AddCellType tCell
 
  tCell = cExcel.NewCellType
  tCell.Row = 2: tCell.Column = 2: tCell.Value = "MergeCell"
  cWS.AddCellType tCell
 
  tCell = cExcel.NewCellType
  tCell.Row = 3: tCell.Column = 2: tCell.Value = "B3"
  tCell.HorizontalAlignment = chaCenter
  cWS.AddCellType tCell

  tCell = cExcel.NewCellType
  tCell.Row = 4: tCell.Column = 2: tCell.Value = "right"
  tCell.HorizontalAlignment = chaRight
  cWS.AddCellType tCell


  cWS.MergeCells 1, 2, 2, 2
 
  cExcel.Save "D:\Excel 2007 files\Reports\Test1.xlsx"
 
  cExcel.Terminate
 
  Set cWS = Nothing
  Set cExcel = Nothing
End Sub

Private Sub Command2_Click()
  Dim cExcel As clsExcel2007
  Dim cWS As clsWorksheet2007
  Dim tCell As tpExcelCell2007
  Dim lRow As Long, lCol As Long
 
  Set cExcel = New clsExcel2007
 
  Set cWS = cExcel.AddWorkSheet("Single sheet")
  For lRow = 1 To 200
    For lCol = 1 To 500
      tCell = cExcel.NewCellType
      tCell.Row = lRow
      tCell.Column = lCol
      tCell.Value = lRow * lCol
      cWS.AddCellType tCell
    Next lCol
  Next lRow
     
  cExcel.Save "D:\Excel 2007 files\Reports\Test2.xlsx"

  cWS.Terminate
  cExcel.Terminate
 
  Set cWS = Nothing
  Set cExcel = Nothing

End Sub

Attached Files

Color Management (ICC Profile) support in VB6: guide and sample project

$
0
0
Name:  Color_Management_Screenshot.jpg
Views: 72
Size:  108.4 KB


Download the sample project (250kb, including sample images)

VB6_ColorManagement.zip


What does the sample project include?

  • Color_Management (module). This contains all the necessary code for adding color management to your VB project.
  • pdLayer (class). A DIB wrapper borrowed from this vb6 project (hence the "pd" prefix). Useful if you want to load JPEG/PNG/TIFF files with embedded profiles. Not necessary if your application won't support loading images at run-time.
  • frmColorManagement (form). Sample form. Demonstrates use of the included module.
  • cCommonDialog (class). Code-only common dialog wrapper by Steve McMahon. Included to make loading images easier.


Acknowledgments

Many thanks to LaVolpe for this helpful post and sample code, which provided a great starting point for this topic.

What is color management and why does it matter?

Short answer: if your application uses images (and especially if it lets the user load or modify images), those images won't look 100% correct without color management.

Long answer: Color Management article on Wikipedia.

Do I need color management in my application?

It depends. If you do not use images in your application, then no - color management is a waste of your time.

If you do use images in your application, then color management is worth considering.

Most importantly, if you allow users to load their own images, I would consider color management a "must-have". Without it, you risk images not looking the same way they do in other software (including Windows photo viewer, PhotoShop, GIMP, etc). Users may think your software is broken, when really, it is just not color managed.

Is it hard to support color management in a VB6 app?

Yes and no, with an emphasis on "mostly no". Color management can be broken into two broad categories:

+ Color management for your forms and picture boxes. Retrieving the stock system color profile, assigning it to VB picture boxes and forms, then activating color management is extremely simple. With the sample project, you can do it in two lines of code. (Note that image boxes cannot be easily color managed, because they do not expose an hDC property.)

+ Color management for imported images. This is trickier, and it requires the use of GDI+ (or some other imaging library, like FreeImage) to parse the image data and extract any embedded ICC profile. The sample project simplifies the process to a few lines of code, but it assumes GDI+ is present (something that should be true for most anyone on Win XP SP2 or later, but which may not be guaranteed for earlier XP users). It also requires the use of DIBs, for which I provide a comprehensive wrapper, but which may complicate your project more than you want.

Can I drop your code into my project and assume everything is color managed?

Mostly. As I said, you'll need to manually activate color management for any forms or picture boxes that display images. This is done using two lines of code:

Code:

assignColorProfileToDC PictureBox.hDC
setColorManagementForDC PictureBox.hDC, True

Please note that if your picture boxes and/or forms use AutoRedraw, you may need to re-activate color management prior to drawing on the picture box, because AutoRedraw can cause the hDC of the picture box to change. (There is no measurable performance overhead in reapplying color management settings.)

If you allow the user to load images in your software, it will take more work to ensure color management for said images. Refer to the sample project for details.

What versions of Windows are supported?

Anything XP or later, assuming GDI+ is present on the target machine. If you don't care about supporting ICC profiles embedded in images, the code should work for Windows 2000 as well, though I haven't tested this.

Are any special dependencies required?

Nope! Windows itself provides a very capable color management engine, so you don't need to add any DLLs or other references to your project. Everything is accomplished by flat function calls to mscms.dll

Does this code provide the same level of color management as PhotoShop?

No, but it's closer than you might think. This project makes a number of assumptions in order to keep things simple and fast (like using the sRGB working space by default, rather than providing a choice). PhotoShop provides much more granular control over every step of the color management chain. That said, you should not notice any difference between images loaded via this sample project and images loaded via PhotoShop, assuming your copy of PhotoShop uses recommended settings.
Attached Images
 
Attached Files
Viewing all 1484 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>