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

Standard API Color Picker

$
0
0
It's strange that this doesn't have more of a presence on these forums than it does, but hey ho.

Attached is the my ChooseColorAPI wrapper that I've just polished up. Here are its features:
  • It just always opens allowing you to select custom colors.
  • You can save the user-specified custom colors if you so choose (your application specific).
  • It has the ability of allowing you to specify your own dialog title.
  • You can double-click on the colors and they will auto-select and be returned to you.

Beyond that, it's pretty much the standard ChooseColorAPI function.

More could be done with this thing, but this is precisely what I needed, and I thought I'd share.

Here's code for a standard BAS module (everything needed, just focus on the ShowColorDialog procedure):

Code:


Option Explicit
'
' These are used to get information about how the dialog went.
Public ColorDialogSuccessful As Boolean
Public ColorDialogColor As Long
'
Private Type ChooseColorType
    lStructSize        As Long
    hWndOwner          As Long
    hInstance          As Long
    rgbResult          As Long
    lpCustColors      As Long
    flags              As Long
    lCustData          As Long
    lpfnHook          As Long
    lpTemplateName    As String
End Type
Private Enum ChooseColorFlagsEnum
    CC_RGBINIT = &H1                  ' Make the color specified by rgbResult be the initially selected color.
    CC_FULLOPEN = &H2                ' Automatically display the Define Custom Colors half of the dialog box.
    CC_PREVENTFULLOPEN = &H4          ' Disable the button that displays the Define Custom Colors half of the dialog box.
    CC_SHOWHELP = &H8                ' Display the Help button.
    CC_ENABLEHOOK = &H10              ' Use the hook function specified by lpfnHook to process the Choose Color box's messages.
    CC_ENABLETEMPLATE = &H20          ' Use the dialog box template identified by hInstance and lpTemplateName.
    CC_ENABLETEMPLATEHANDLE = &H40    ' Use the preloaded dialog box template identified by hInstance, ignoring lpTemplateName.
    CC_SOLIDCOLOR = &H80              ' Only allow the user to select solid colors. If the user attempts to select a non-solid color, convert it to the closest solid color.
    CC_ANYCOLOR = &H100              ' Allow the user to select any color.
End Enum
#If False Then ' Intellisense fix.
    Public CC_RGBINIT, CC_FULLOPEN, CC_PREVENTFULLOPEN, CC_SHOWHELP, CC_ENABLEHOOK, CC_ENABLETEMPLATE, CC_ENABLETEMPLATEHANDLE, CC_SOLIDCOLOR, CC_ANYCOLOR
#End If
Private Type KeyboardInput        '
    dwType As Long                ' Set to INPUT_KEYBOARD.
    wVK As Integer                ' shift, ctrl, menukey, or the key itself.
    wScan As Integer              ' Not being used.
    dwFlags As Long              '            HARDWAREINPUT hi;
    dwTime As Long                ' Not being used.
    dwExtraInfo As Long          ' Not being used.
    dwPadding As Currency        ' Not being used.
End Type
Private Type POINTAPI
    X As Long
    Y As Long
End Type
Private Const WM_LBUTTONDBLCLK As Long = 515&
Private Const WM_SHOWWINDOW    As Long = 24&
Private Const WM_SETTEXT      As Long = &HC&
Private Const INPUT_KEYBOARD  As Long = 1&
Private Const KEYEVENTF_KEYUP  As Long = 2&
Private Const KEYEVENTF_KEYDOWN As Long = 0&
'
Private muEvents(1) As KeyboardInput    ' Just used to emulate "Enter" key.
Private pt32 As POINTAPI
Private msColorTitle As String
'
Private Declare Function ChooseColorAPI Lib "comdlg32" Alias "ChooseColorA" (pChoosecolor As ChooseColorType) As Long
Private Declare Function SendInput Lib "user32" (ByVal nInputs As Long, pInputs As Any, ByVal cbSize As Long) As Long
Private Declare Function SetFocusTo Lib "user32" Alias "SetFocus" (Optional ByVal hWnd As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function ChildWindowFromPointEx Lib "user32" (ByVal hWnd As Long, ByVal xPoint As Long, ByVal yPoint As Long, ByVal uFlags As Long) As Long
Private Declare Function SendMessageWLong Lib "user32" Alias "SendMessageW" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'

Public Function ShowColorDialog(hWndOwner As Long, Optional NewColor As Long, Optional Title As String = "Select Color", Optional CustomColorsHex As String) As Boolean
    ' You can optionally use ColorDialogSuccessful & ColorDialogColor or the return of ShowColorDialog and NewColor.  They will be the same.
    '
    ' CustomColorHex is a comma separated hex string of 16 custom colors.  It's best to just let the user specify these, starting out with all black.
    ' If this CustomColorHex string doesn't separate into precisely 16 values, it's ignored, resulting with all black custom colors.
    ' The string is returned, and it's up to you to save it if you wish to save your user-specified custom colors.
    ' These will be specific to this program, because this is your CustomColorsHex string.
    '
    Dim uChooseColor As ChooseColorType
    Dim CustomColors(15) As Long
    Dim sArray() As String
    Dim i As Long
    '
    msColorTitle = Title
    '
    ' Setup custom colors.
    sArray = Split(CustomColorsHex, ",")
    If UBound(sArray) = 15 Then
        For i = 0 To 15
            CustomColors(i) = Val("&h" & sArray(i))
        Next i
    End If
    '
    uChooseColor.hWndOwner = hWndOwner
    uChooseColor.lpCustColors = VarPtr(CustomColors(0))
    uChooseColor.flags = CC_ENABLEHOOK Or CC_FULLOPEN
    uChooseColor.hInstance = App.hInstance
    uChooseColor.lStructSize = LenB(uChooseColor)
    uChooseColor.lpfnHook = ProcedureAddress(AddressOf ColorHookProc)
    '
    ColorDialogSuccessful = False
    If ChooseColorAPI(uChooseColor) = 0 Then
        Exit Function
    End If
    If uChooseColor.rgbResult > &HFFFFFF Then Exit Function
    '
    ColorDialogColor = uChooseColor.rgbResult
    NewColor = uChooseColor.rgbResult
    ColorDialogSuccessful = True
    ShowColorDialog = True
    '
    ' Return custom colors.
    ReDim sArray(15)
    For i = 0 To 15
        sArray(i) = Hex$(CustomColors(i))
    Next i
    CustomColorsHex = Join(sArray, ",")
End Function

Private Function ColorHookProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If uMsg = WM_SHOWWINDOW Then
        SetWindowText hWnd, msColorTitle
        ColorHookProc = 1&
    End If
    '
    If uMsg = WM_LBUTTONDBLCLK Then
        '
        ' If we're on a hWnd with text, we probably should ignore the double-click.
        GetCursorPos pt32
        ScreenToClient hWnd, pt32
        '
        If WindowText(ChildWindowFromPointEx(hWnd, pt32.X, pt32.Y, 0&)) = vbNullString Then
            ' For some reason, this SetFocus is necessary for the dialog to receive keyboard input under certain circumstances.
            SetFocusTo hWnd
            ' Build EnterKeyDown & EnterKeyDown events.
            muEvents(0).wVK = vbKeyReturn: muEvents(0).dwFlags = KEYEVENTF_KEYDOWN: muEvents(0).dwType = INPUT_KEYBOARD
            muEvents(1).wVK = vbKeyReturn: muEvents(1).dwFlags = KEYEVENTF_KEYUP:  muEvents(1).dwType = INPUT_KEYBOARD
            ' Put it on buffer.
            SendInput 2&, muEvents(0), Len(muEvents(0))
            ColorHookProc = 1&
        End If
    End If
End Function

Private Function ProcedureAddress(AddressOf_TheProc As Long)
    ProcedureAddress = AddressOf_TheProc
End Function

Private Function WindowText(hWnd As Long) As String
    WindowText = Space$(GetWindowTextLength(hWnd) + 1)
    WindowText = Left$(WindowText, GetWindowText(hWnd, WindowText, Len(WindowText)))
End Function

Public Sub SetWindowText(hWnd As Long, sText As String)
    SendMessageWLong hWnd, WM_SETTEXT, 0&, StrPtr(sText)
End Sub


And, if you wish to just test/play, here's a bit of code for a Form1:

Code:


Option Explicit
'
Dim msOurCustomColors As String
'

Private Sub Form_Click()
    ShowColorDialog Me.hWnd, , "Pick a color for background", msOurCustomColors
    If ColorDialogSuccessful Then Me.BackColor = ColorDialogColor
End Sub

Enjoy,
Elroy

[VB6] BatchRtb 2

$
0
0
Since I am almost 100% retired now and doing a lot less VB6 programming I have been looking for things in my toolkit that might be worth sharing with the remaining VB6 community.

I have done a big rewrite of my BatchRtb Class. Here is the main ReadMe:

Code:

========
BatchRtb Version 2.0
========

BatchRtb is a VB6 class for working with RTF data in batch programs.

Instead of a RichTextBox control it creates an invisible RichEdit
control and exposes its Text Object Model (TOM) ITextDocument
interface.  A few additional methods and properties are provided for
opening, saving, and clearing RTF data.

Open and save operations accept:

    o A file name.
    o A Byte array.
    o An IStream object.
    o A ShStream object (another provided class also used internally).
    o An ADODB.Stream object.

These should all contain raw RTF data.


Notes:

    Edanmo's olelib.tlb is required for compiling, but is of course
    not needed at run time and does not need to be deployed.  A recent
    copy has been included.

    If necessary you could even create and compile an ActiveX DLL
    Project exposing the BatchRtb class and perhaps the ShStream class.
    Then this can be used from VBScript in WSH scripts, IIS ASP
    scripts, etc. (anywhere a 32-bit ActiveX DLL can be used).

    Several demo/test Projects using BatchRtb are included.


Some uses:

    o Command line programs.  Local, via PsExec.exe, etc.
    o Batch unattended scheduled tasks.
    o Services.
    o Or anywhere that you don't have a Form or UserControl you can
      site a RichTextBox or InkEdit control on.

This isn't for everyone. Few people are doing Service development, ASP scripting, etc. Most don't even have a clue how to use a CLI (cmd.exe) window, let alone schedule a non-interactive batch task using Task Scheduler any more.

But this code may contain techniques you could employ in your own programs.


BatchRtb 2.0 has been tested on Windows 10 Fall Creator's Update but not on anything else yet. It should work on anything from Windows Vista on up. I'm not sure it could be made to work on Win9x but I think it could be reworked to run on NT 4.0 on up by rewriting the ShStream class - as long as a recent version of ADO (2.5 or later) is installed. The ADO requirement could also be stripped out if necessary.

I haven't done exhaustive testing so bugs may remain in this release. But the attachment contains a number of test case Projects that exercise most of its operations.
Attached Files

VB6 - Multiline Textbox Printer

$
0
0
I had previously used a RichTextBox and the SelPrint routine, but I discovered that routine would not work with an InkEdit Control. With the help of jpbro, we put together a routine for the InkEdit Control (located in the parent forum). But that routine does not work with a Textbox, and I could not find anything online to fit the bill. So I came up with the routine attached.

This routine has experienced very little testing because my development computer does not currently have access to an actual printer. Bug reports would be appreciated.

J.A. Coutts
Attached Files

VB6 - Text Editor

$
0
0
I found a need for addtional functions that NotePad did not provide, so I came up with my own Text Editor. It has most of the functions of NotePad with a couple of extra ones.
Code:

File                Edit                Format                Search
-New                -Undo                -Word Wrap        -Find
-Open                -Cut                -Sort                -Find Next
-Save                -Copy                -Font
-Save as        -Paste
-Print                -Delete
-Exit                -Replace
                -Select All

The noticeable extra is the Sort function, which is covered in a previous post. The other extra is the ability to replace character ranges per line in addition to search and replace specific text. This is accomplished by replacing the double characters CrLf with a single character Cr, using a Split function to separate individual lines into a string array, looping through each line to replace the selected character range, and reassembling the complete string with the Join function. For large text files, search and Replace All by text will be slow, whereas Replace All by character count will be fast by comparison.

The print function has taken some time to put together, as printing from a Text Box is not straight forward, and it has experienced limited testing due to lack of an available printer. It also has been covered in a previous post.

The Line/Col function that comes with Text Editor is not considered an option, as in NotePad. Unlike NotePad, it is available in either Wrap or Unwrap modes, and is only activated by mouse click. If it is important to you, you are welcome to add activation by cursor keys.

Originally I used the API to perform the Edit functions since the VB functions were limited to 64K. But then I discovered that the keyboard functions are not limited to 64K, and perform most of those tasks quite well and with good speed. So it made a lot of sense to use the keyboard functions instead.

Like NotePad, Text Editor provides an adjustable window that remembers it's location and size.

The surprising part of this effort is that with the additional functionality provided, the executable is 1/3 the size of Notepad. I have added functions that meet my current needs, and other users may have specific functions that can be added to meet their needs.

J.A. Coutts
Attached Images
  
Attached Files

mBox Reader

$
0
0
Hi this is a mail message box reader I made to read old usenet message box files. if you want any mail box files you can find a load on wayback machine. with this little app it makes it easyer to read each message. anyway hope you like it.

Name:  logo.jpg
Views: 139
Size:  40.6 KB

Download Source Project:

mBox.zip
Attached Images
 
Attached Files

Text To Picture

$
0
0
Hi
This is a project I made sometime ago, it allows you to encrypt text and save as a bitmap, You can then load the bitmap and with the right encrypt key you used you can decrypt the text.
Hope you find it usfull.

Name:  logo.jpg
Views: 124
Size:  153.9 KB

Download Project
Text2Pic.zip
Attached Images
 
Attached Files

Random Password Generator

$
0
0
Hi,
This is a password generator I made a few months back with the help of a friend who added a few featires. it contains many options skins and more hope you like it.

Name:  logo.jpg
Views: 141
Size:  50.7 KB

Download Source Code:
PwsGenStd.zip
Attached Images
 
Attached Files

Radial Busy GIF

$
0
0
I was looking for a simple rotary graphic to indicate that a program was busy performing a task. I found such an image at this Web site:
http://www.ajaxload.info/
You can change the color combinations to produce and download the Animated GIF file. I have included 2 circular busy GIFs, one with a white background and one with a light yellow background.

Unfortunately, VB6 does not directly support animated GIF files. Based on an Animated GIF Control by Jen Sam Lam, I put together the attached User Control. An animated GIF is a layered structure consisting of a number of frames. Because none of the picture based controls in VB6 support the layered structure, it is broken up into the individual frames in an Image array. In this case there are 8 frames controlled by a timer.

The individual frames are converted into a temporary file and loaded to the image array. I was wondering if there was a more direct way of loading the individual frames. Feedback is welcome.

J.A. Coutts

Updated: 06/20/2020 - See later post for details
Attached Images
 
Attached Files

ColorPicker similar to PhotoShop's (Learn vbRichClient5.Cairo drawing step by step)

$
0
0
There are several good ColorPickers in the CodeBank, for example:

(1) ColinE66's ColourPicker[vbRichClient]: http://www.vbforums.com/showthread.p...r-vbRichClient
(2) Eduardo's Wheel Color Picker: http://www.vbforums.com/showthread.p...l-Color-Picker

But I need a ColorPicker similar to PhotoShop's, because PhotoShop is the most widely used drawing tool in the world.

wqweto wrote a very good ColorPicker similar to PhotoShop's 18 years ago, but its UI is so old that I can't use it in my projects. So I decided to rewrite wqweto's ColorPicker with vbRichClient5.Cairo.

Although I've used RC5.Cairo in my Spread and CodeEditor, Cairo's syntax is completely different from VB6 GDI, so that as long as I don't use Cairo for 6 months, I'll completely forget Cairo's usage, and I need to start learning it from scratch. Therefore, I think it necessary to record the process of rewriting wqweto's ColorPicker with RC5.Cairo for others interested in learning Cairo drawing.

It will take some time to rewrite wqweto's ColorPicker, because I need to spend a lot of time to search for information and test the usage of Cairo. Fortunately, Olaf has left a large number of Cairo examples on this forum. Searching these examples can solve almost all Cairo drawing problems.

wqweto's real-time PhotoShop like color-picker
http://www.planet-source-code.com/vb...xtCodeId=36529

Note:
My ultimate goal is to use RC5.Cairo to develop a professional and modern ColorPicker similar to PhotoShop's, which will be named vbColorPicker. If I have more time in the future, I'll rewrite Eduardo's Wheel Color Picker with Cairo and add it to vbColorPicker to form vbColorPickerPro. As for cwColorPicker, I need Olaf's help and guidance to complete it. Maybe ColinE66 is a better candidate to develop it.

List of revisions:
Code:

2020-07-06
- vbColorPicker Final

2020-07-02
- Add PopupPosition parameter to ShowEx function.
- Improved FrmColorPicker

Note:
Now the vbColorPicker is basically completed.

2020-07-01
- Completely rewrote FrmColorPicker

2020-06-30
- Add CreateBarSat (DreamManor -- RC5.Cairo)
- Add CreateRectSat (DreamManor -- RC5.Cairo)
- Add CreateRectSatAccelerate (DreamManor -- RC5.Cairo)
- Add CreateBarBri (DreamManor -- RC5.Cairo)
- Add CreateRectBri (DreamManor -- RC5.Cairo)
- Add CreateRectBriAccelerate (DreamManor -- RC5.Cairo)
- Add Only-Web-Colors Test-Option
- Improved SpinBox
- Add vbColorPicker: FrmColorPicker(Beta)

2020-06-28
- Add cUpDown.cls (DreamManor -- RC5.Cairo)
- Add SpinBox User Control (DreamManor)
- Add SpinBox Test Page (DreamManor)

2020-06-27 a.m.
- Create Rect Hue (DreamManor -- RC5.Cairo)
- Create Rect Hue (Acclerate) (DreamManor -- RC5.Cairo)
- Create Rect RGB (DreamManor -- RC5.Cairo)
- Add Speed Compare Module

2020-06-26
- Create Bar Hue (DreamManor -- RC5.Cairo)
- Create Bar RGB (DreamManor -- RC5.Cairo)
- Create Rect RGB (Acclerate) (DreamManor -- RC5.Cairo)

2020-06-25 p.m.
- Draw border on a picture(DreamManor -- RC5.Cairo)
- Draw bar selector (DreamManor -- RC5.Cairo)
- Draw bar selector (Olaf -- Best Practice)
- Draw rect marker (DreamManor -- RC5.Cairo)

2020-06-25
- First released learning/rewriting framework

Attached Images
 
Attached Files

Simulate TLS 1.3

$
0
0
To understand TLS 1.3, https://tls13.ulfheim.net/ is useful, but unfortunately it contains several discrepancies if you want to follow it in detail (eg. labels are not complete). For the detail, https://tools.ietf.org/html/rfc8448 is better. Unfortunately, Win 8.1 does not support x25519, so the best I could come up with was a simulation without generating the Agreed Secret.

Like previous cryptographic protocols, TLS 1.3 uses a Session Hash. Unlike previous protocols, it uses 2 sets of keys and encrypts part of the handshake. The Session Hash uses the decrypted data, and Write keys on the Server are Read keys on the Client (and visa versa).

The attached program attempts to duplicate the steps in the IETF trace example for the Simple 1-RTT Handshake, separating the Client steps from the Server. In the Client and Server portions, the Hash is not calculated or shown, as it is included in the Info. Clicking "Client" or "Server" takes you to the first step of calculating the "Early Secret". Using the "Enter" key advances through each step until the keys are summarized at the end.

The Key options on the other hand don't show all the information used, the Session Hash is calculated, and calculations are made as soon as the information is available.

The next step will be to add the actual encryption/decryption as well as the application data.

J.A. Coutts
Attached Images
 
Attached Files

mBox Reader

$
0
0
Hi this is a mail message box reader I made to read old usenet message box files. if you want any mail box files you can find a load on wayback machine. with this little app it makes it easyer to read each message. anyway hope you like it.

Name:  logo.jpg
Views: 142
Size:  40.6 KB

Download Source Project:

mBox.zip
Attached Images
 
Attached Files

Text To Picture

$
0
0
Hi
This is a project I made sometime ago, it allows you to encrypt text and save as a bitmap, You can then load the bitmap and with the right encrypt key you used you can decrypt the text.
Hope you find it usfull.

Name:  logo.jpg
Views: 127
Size:  153.9 KB

Download Project
Text2Pic.zip
Attached Images
 
Attached Files

Random Password Generator

$
0
0
Hi,
This is a password generator I made a few months back with the help of a friend who added a few featires. it contains many options skins and more hope you like it.

Name:  logo.jpg
Views: 143
Size:  50.7 KB

Download Source Code:
PwsGenStd.zip
Attached Images
 
Attached Files

Radial Busy GIF

$
0
0
I was looking for a simple rotary graphic to indicate that a program was busy performing a task. I found such an image at this Web site:
http://www.ajaxload.info/
You can change the color combinations to produce and download the Animated GIF file. I have included 2 circular busy GIFs, one with a white background and one with a light yellow background.

Unfortunately, VB6 does not directly support animated GIF files. Based on an Animated GIF Control by Jen Sam Lam, I put together the attached User Control. An animated GIF is a layered structure consisting of a number of frames. Because none of the picture based controls in VB6 support the layered structure, it is broken up into the individual frames in an Image array. In this case there are 8 frames controlled by a timer.

The individual frames are converted into a temporary file and loaded to the image array. I was wondering if there was a more direct way of loading the individual frames. Feedback is welcome.

J.A. Coutts

Updated: 06/20/2020 - See later post for details
Attached Images
 
Attached Files

ColorPicker similar to PhotoShop's (Learn vbRichClient5.Cairo drawing step by step)

$
0
0
There are several good ColorPickers in the CodeBank, for example:

(1) ColinE66's ColourPicker[vbRichClient]: http://www.vbforums.com/showthread.p...r-vbRichClient
(2) Eduardo's Wheel Color Picker: http://www.vbforums.com/showthread.p...l-Color-Picker

But I need a ColorPicker similar to PhotoShop's, because PhotoShop is the most widely used drawing tool in the world.

wqweto wrote a very good ColorPicker similar to PhotoShop's 18 years ago, but its UI is so old that I can't use it in my projects. So I decided to rewrite wqweto's ColorPicker with vbRichClient5.Cairo.

Although I've used RC5.Cairo in my Spread and CodeEditor, Cairo's syntax is completely different from VB6 GDI, so that as long as I don't use Cairo for 6 months, I'll completely forget Cairo's usage, and I need to start learning it from scratch. Therefore, I think it necessary to record the process of rewriting wqweto's ColorPicker with RC5.Cairo for others interested in learning Cairo drawing.

It will take some time to rewrite wqweto's ColorPicker, because I need to spend a lot of time to search for information and test the usage of Cairo. Fortunately, Olaf has left a large number of Cairo examples on this forum. Searching these examples can solve almost all Cairo drawing problems.

wqweto's real-time PhotoShop like color-picker
http://www.planet-source-code.com/vb...xtCodeId=36529

Note:
My ultimate goal is to use RC5.Cairo to develop a professional and modern ColorPicker similar to PhotoShop's, which will be named vbColorPicker. If I have more time in the future, I'll rewrite Eduardo's Wheel Color Picker with Cairo and add it to vbColorPicker to form vbColorPickerPro. As for cwColorPicker, I need Olaf's help and guidance to complete it. Maybe ColinE66 is a better candidate to develop it.

List of revisions:
Code:

2020-07-06
- vbColorPicker Final

2020-07-02
- Add PopupPosition parameter to ShowEx function.
- Improved FrmColorPicker

Note:
Now the vbColorPicker is basically completed.

2020-07-01
- Completely rewrote FrmColorPicker

2020-06-30
- Add CreateBarSat (DreamManor -- RC5.Cairo)
- Add CreateRectSat (DreamManor -- RC5.Cairo)
- Add CreateRectSatAccelerate (DreamManor -- RC5.Cairo)
- Add CreateBarBri (DreamManor -- RC5.Cairo)
- Add CreateRectBri (DreamManor -- RC5.Cairo)
- Add CreateRectBriAccelerate (DreamManor -- RC5.Cairo)
- Add Only-Web-Colors Test-Option
- Improved SpinBox
- Add vbColorPicker: FrmColorPicker(Beta)

2020-06-28
- Add cUpDown.cls (DreamManor -- RC5.Cairo)
- Add SpinBox User Control (DreamManor)
- Add SpinBox Test Page (DreamManor)

2020-06-27 a.m.
- Create Rect Hue (DreamManor -- RC5.Cairo)
- Create Rect Hue (Acclerate) (DreamManor -- RC5.Cairo)
- Create Rect RGB (DreamManor -- RC5.Cairo)
- Add Speed Compare Module

2020-06-26
- Create Bar Hue (DreamManor -- RC5.Cairo)
- Create Bar RGB (DreamManor -- RC5.Cairo)
- Create Rect RGB (Acclerate) (DreamManor -- RC5.Cairo)

2020-06-25 p.m.
- Draw border on a picture(DreamManor -- RC5.Cairo)
- Draw bar selector (DreamManor -- RC5.Cairo)
- Draw bar selector (Olaf -- Best Practice)
- Draw rect marker (DreamManor -- RC5.Cairo)

2020-06-25
- First released learning/rewriting framework

Attached Images
 
Attached Files

Simulate TLS 1.3

$
0
0
To understand TLS 1.3, https://tls13.ulfheim.net/ is useful, but unfortunately it contains several discrepancies if you want to follow it in detail (eg. labels are not complete). For the detail, https://tools.ietf.org/html/rfc8448 is better. Unfortunately, Win 8.1 does not support x25519, so the best I could come up with was a simulation without generating the Agreed Secret.

Like previous cryptographic protocols, TLS 1.3 uses a Session Hash. Unlike previous protocols, it uses 2 sets of keys and encrypts part of the handshake. The Session Hash uses the decrypted data, and Write keys on the Server are Read keys on the Client (and visa versa).

The attached program attempts to duplicate the steps in the IETF trace example for the Simple 1-RTT Handshake, separating the Client steps from the Server. In the Client and Server portions, the Hash is not calculated or shown, as it is included in the Info. Clicking "Client" or "Server" takes you to the first step of calculating the "Early Secret". Using the "Enter" key advances through each step until the keys are summarized at the end.

The Key options on the other hand don't show all the information used, the Session Hash is calculated, and calculations are made as soon as the information is available.

The next step will be to add the actual encryption/decryption as well as the application data.

J.A. Coutts
Attached Images
 
Attached Files

Programmatically adding and using buttons on a VB form.

$
0
0
Put this code in Form1, and make sure to set the form's AutoRedraw property to True (you won't want printed text disappearing permanently if it's below the form and you just need to resize it).
Code:

Private Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByRef lpParam As Any) As Long
Private Declare Function DestroyWindow Lib "user32.dll" (ByVal hWnd As Long) As Long

Private Const WS_VISIBLE As Long = &H10000000
Private Const WS_CHILD As Long = &H40000000


Public IsRunning As Boolean


Private Sub Form_Load()
    'set the BUTTON window class function
    hButton = CreateWindowEx(0, "BUTTON", "", 0, 0, 0, 0, 0, 0, 0, 0, ByVal 0&)
    OldWndProc = SetClassLong(hButton, GCL_WNDPROC, AddressOf WndProc)
    DestroyWindow hButton
   
    'create buttons
    hButton = CreateWindowEx(0, "BUTTON", "Test Button 1", WS_VISIBLE Or WS_CHILD, 50, 20, 120, 30, hWnd, 0, 0, ByVal 0&)
    hButton2 = CreateWindowEx(0, "BUTTON", "Test Button 2", WS_VISIBLE Or WS_CHILD, 50, 20 + 30, 120, 30, hWnd, 0, 0, ByVal 0&)
   
    'make sure the button class function knows the program is running
    IsRunning = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
    'make sure the button class function knows the program is not running
    IsRunning = False
   
    'restore original BUTTON window class function
    SetClassLong hButton, GCL_WNDPROC, OldWndProc
   
    'remove buttons
    DestroyWindow hButton
    DestroyWindow hButton2
End Sub


Put this code in Module1.
Code:

Public Declare Function SetClassLong Lib "user32.dll" Alias "SetClassLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Const GCL_WNDPROC As Long = -24

Public Const WM_LBUTTONDOWN As Long = &H201
Public Const WM_LBUTTONDBLCLK As Long = &H203
Public Const WM_LBUTTONUP As Long = &H202


Public OldWndProc As Long

Public hButton As Long
Public hButton2 As Long

'function to handle all button messages
Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If Form1.IsRunning Then
        'If (uMsg = WM_LBUTTONDOWN) Or (uMsg = WM_LBUTTONDBLCLK) Then ButtonClick hWnd
        If uMsg = WM_LBUTTONUP Then ButtonClick hWnd
    End If
    WndProc = CallWindowProc(OldWndProc, hWnd, uMsg, wParam, lParam)
End Function


'function to handle all button clicks
Private Sub ButtonClick(ByVal hWnd As Long)
    Select Case hWnd
        Case hButton
            Button1Clicked
        Case hButton2
            Button2Clicked
    End Select
End Sub


'click handler for button 1
Private Sub Button1Clicked()
    Form1.Print "123"
End Sub


'click handler for button 2
Private Sub Button2Clicked()
    Form1.Print "ABC"
End Sub


When the program is run, two buttons will appear on the form. If you click the one called Test Button 1, it will print "123" on Form1. If you click the button called Test Button 2, it will print "ABC" on Form1.

Each button will respond after releasing it from a click. If you want it to respond at the instant it's clicked, instead of waiting to be released, comment out the line of code:
Code:

If uMsg = WM_LBUTTONUP Then ButtonClick hWnd
and uncomment out the line of code:
Code:

'If (uMsg = WM_LBUTTONDOWN) Or (uMsg = WM_LBUTTONDBLCLK) Then ButtonClick hWnd

Anchor Control

$
0
0
This code example is so that the controls can be anchored to the Form to be resized.

Although there are several examples of anchoring, I noticed that when placing the controls inside the FormChild, the anchoring becomes irregular at runtime and, with that, the anchored controls do not appear as in the design mode, and overlap each other.

To get around this I created this example based on the example of colleague SeabrookStan.

Follow link ... http://www.vbforums.com/showthread.p...king-made-Easy

In VB.Net there is a form property called AutoScaleMode and so this problem is corrected but in VB6 this property is not. So the present example corrects the problem.
Attached Files

[VB6] Another "magnifier"

$
0
0
The topic of writing screen magnifiers came up the other day, and I thought I might trot out this old approach.

Basically it shows simple use of a GDI Region object with StretchBlt. I had another example using StretchBlt then MaskBlt, but this is actually far simpler and less code.

A Timer is used here only to catch any movement at 5 frames/sec to keep overhead low, but even 10 fps shouldn't be too expensive on most PCs. The demo does a "4x" magnification.

Name:  sshot.png
Views: 119
Size:  1.7 KB

Here "DrawGrid" was just a simple program with some colors for me to magnify.

The "MagnifyX4" program is the grey square with the red arrow pointing at the magnified region, which can be dragged around to magnify different parts of the screen.

The circular GDI Region was only used to produce the "clever" circular magnification. You could just use StretchBlt without it to get a square magnifier.

Code:

Option Explicit
'
'Form1 is borderless, mainly to help draw an "arrow" to indicate the captured area of the
'desktop in this demo.  With a border the arrow would be off a bit (too low by the caption
'bar height and outline).
'
'We use a Timer control here in order to accomodate magnifying anything animated or moving.
'
'Assumptions:
'
'  o Form1's client area is square.
'

Private Const WIN32NULL As Long = 0

Private Declare Function CreateEllipticRgn Lib "gdi32" ( _
    ByVal nLeftRect As Long, _
    ByVal nTopRect As Long, _
    ByVal nRightRect As Long, _
    ByVal nBottomRect As Long) As Long

Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long

Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Function GetWindowRect Lib "user32" ( _
    ByVal hWnd As Long, _
    ByRef RECT As RECT) As Long

Private Declare Function ReleaseDC Lib "user32" ( _
    ByVal hWnd As Long, _
    ByVal hDC As Long) As Long

Private Declare Function SelectClipRgn Lib "gdi32" ( _
    ByVal hDC As Long, _
    ByVal hRgn As Long) As Long

Private Declare Function StretchBlt Lib "gdi32" ( _
    ByVal hdcDest As Long, _
    ByVal nXOriginDest As Long, _
    ByVal nYOriginDest As Long, _
    ByVal nWidthDest As Long, _
    ByVal nHeightDest As Long, _
    ByVal hdcSrc As Long, _
    ByVal nXOriginSrc As Long, _
    ByVal nYOriginSrc As Long, _
    ByVal nWidthSrc As Long, _
    ByVal nHeightSrc As Long, _
    Optional ByVal dwRop As RasterOpConstants = vbSrcCopy) As Long

Private CaptureWH As Long
Private GrabX As Single
Private GrabY As Single
Private MagnifyWH As Long

Private Sub Peek()
    Dim hDCScreen As Long
    Dim hRgn As Long
    Dim RECT As RECT

    hDCScreen = GetDC(WIN32NULL)
    hRgn = CreateEllipticRgn(0, 0, MagnifyWH, MagnifyWH)
    SelectClipRgn hDC, hRgn
    GetWindowRect hWnd, RECT
    With RECT
        StretchBlt hDC, _
                  0, _
                  0, _
                  MagnifyWH, _
                  MagnifyWH, _
                  hDCScreen, _
                  .Left - CaptureWH, _
                  .Top - CaptureWH, _
                  CaptureWH, _
                  CaptureWH
    End With
    SelectClipRgn hDC, WIN32NULL
    DeleteObject hRgn
    ReleaseDC WIN32NULL, hDCScreen
    Set Picture = Image
End Sub

Private Sub Form_Load()
    AutoRedraw = True
    ScaleMode = vbTwips
    BackColor = &H808080
    ForeColor = vbRed
    DrawWidth = 3
    Line (30, 30)-(360, 360)
    Line (30, 30)-(360, 30)
    Line (30, 30)-(30, 360)
    MagnifyWH = ScaleX(ScaleWidth, ScaleMode, vbPixels)
    CaptureWH = MagnifyWH / 4

    Show
    DoEvents
    Peek
    MsgBox "Left-click and drag to move, shift-left-click to exit"
    With Timer1
        .Interval = 200 '5 fps capture.
        .Enabled = True
    End With
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Shift And vbShiftMask Then
        Unload Me
    ElseIf Button = vbLeftButton Then
        GrabX = X
        GrabY = Y
    End If
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim NewLeft As Single
    Dim NewTop As Single

    If Button = vbLeftButton Then
        NewLeft = Left + X - GrabX
        NewTop = Top + Y - GrabY
        Move NewLeft, NewTop
        'Commented out since we're using Timer1 to magnify anything animated
        'such as a video we're watching:
        'Peek
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
    Peek
End Sub

Attached Images
 
Attached Files

[VB6] GDI Path clipping

$
0
0
I don't see a lot here on this topic. Perhaps it's a bit "forgotten" or maybe not that useful to most people. This example is a bit silly but it might be enough to get you started using GDI Paths for a certain kind of graphics effects.

Code:

Option Explicit

Private Const OUTPUT_TEXT As String = "Some Text"

Private Declare Function AbortPath Lib "gdi32" (ByVal hDC As Long) As Long

Private Declare Function BeginPath Lib "gdi32" (ByVal hDC As Long) As Long

Private Declare Function EndPath Lib "gdi32" (ByVal hDC As Long) As Long

Private Enum CombineRgnStyles
    RGN_AND = 1    'The new clipping region includes the intersection (overlapping areas)
                    'of the current clipping region and the current path.
    RGN_OR = 2      'The new clipping region includes the union (combined areas) of the
                    'current clipping region and the current path.
    RGN_XOR = 3    'The new clipping region includes the union of the current clipping
                    'region and the current path but without the overlapping areas.
    RGN_DIFF = 4    'The new clipping region includes the areas of the current clipping
                    'region with those of the current path excluded.
    RGN_COPY = 5    'The new clipping region is the current path.
End Enum

Private Declare Function SelectClipPath Lib "gdi32" ( _
    ByVal hDC As Long, _
    ByVal Mode As CombineRgnStyles) As Long

Private Sub Paint()
    Static TickTock As Integer
    Dim N As Single

    If TickTock = 0 Then ForeColor = vbYellow Else ForeColor = vbRed
    For N = 0 To ScaleHeight Step 12
        Line (0, N)-(ScaleWidth, N)
    Next
    If TickTock = 1 Then ForeColor = vbYellow Else ForeColor = vbRed
    For N = 4 To ScaleHeight Step 12
        Line (0, N)-(ScaleWidth, N)
    Next
    If TickTock = 2 Then ForeColor = vbYellow Else ForeColor = vbRed
    For N = 8 To ScaleHeight Step 12
        Line (0, N)-(ScaleWidth, N)
    Next
    TickTock = (TickTock + 1) Mod 3
End Sub

Private Sub Form_Load()
    AutoRedraw = True
    BeginPath hDC
    Circle (40, 30), 20
    Circle (150, 35), 10
    Circle (250, 20), 5
    CurrentX = (ScaleWidth - TextWidth(OUTPUT_TEXT)) / 2
    CurrentY = (ScaleHeight - 1.25 * TextHeight(OUTPUT_TEXT)) / 2
    Print OUTPUT_TEXT;
    Circle (260, 140), 15
    Circle (75, 160), 10
    Circle (200, 180), 5
    EndPath hDC
    SelectClipPath hDC, RGN_COPY
    DrawWidth = 4
    Paint
    Timer1.Enabled = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
    AbortPath hDC
End Sub

Private Sub Timer1_Timer()
    Paint
End Sub

Name:  sshot.png
Views: 84
Size:  1.5 KB

Run it to see the effect animation.
Attached Images
 
Attached Files
Viewing all 1461 articles
Browse latest View live


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