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

Hexeditor OCX control

$
0
0
A hexeditor/viewer is another commonly needed component. Here is one I have been using for a number of years now.

Name:  screenshot.jpg
Views: 93
Size:  89.9 KB

The core of this one was taken from a standalone hexeditor written by Rang3r and released on psc in 2001

http://www.Planet-Source-Code.com/vb...34729&lngWId=1

It has been converted into an OCX and includes common functions such as load from string/bytearray/file,
ability to copy hexcodes, search, and extract strings. It also has good performance on large files.

The ocx also includes a public class so you can launch a hexeditor on its own form without having to host it
on a dedicated form of your own.

Any updates will be in the git repo here:

https://github.com/dzzie/hexed

public methods:
Code:


Property BookMarks() As Collection
Public Property hWndAscii() As Long
Public Property hWndCanvas() As Long
Public Property hwnd() As Long
Public Property AsciiBGColor() As Long
Public Property HexBGColor() As Long
Public Property MarginBGColor() As Long
Public Property MarginColor() As Long
Public Property AsciiColor() As Long
Public Property EvenColor() As Long
Public Property OddColor() As Long
Public Property ModColor() As Long
Public Property Font() As StdFont
Public Property IsDirty() As Boolean
Public Property DataLength() As Long
Public Property SelLength() As Long
Public Property SelStart() As Long
Public Property SelTextAsHexCodes(Optional prefix As String = Empty) As String
Public Property SelText() As String
Public Property Columns() As Long
Property ReadChunkSize() As Long
Property LoadedFile() As String
Property VisibleLines() As Long
Property CurrentPosition() As Long
Public Sub GotoNextBookmark()
Public Sub ToggleBookmark(ByVal Pos As Long)
Public Sub ShowBookMarks()
Public Function FileSize() As Long
Public Function GetDataChunk(ByVal Pos As Long) As String
Public Function GetData(ByVal Pos As Long) As Byte
Public Sub Scroll(ByVal Amount As Long)
Public Sub Save()
Public Sub SaveAs(Optional fpath As String = Empty, Optional defaultfName As String)
Public Sub FullView()
Public Sub HexView()
Public Sub AsciiView()
Public Function LoadFile(fpath As String, Optional ViewOnly As Boolean = True) As Boolean
Function FileExists(path As String) As Boolean
Function FolderExists(path As String) As Boolean
Public Function LoadByteArray(bArray As Variant, Optional ViewOnly As Boolean = True) As Boolean
Public Function LoadString(data As String, Optional ViewOnly As Boolean = True) As Boolean
Public Sub DeleteData(ByVal Pos As Long, ByVal length As Long)
Public Sub OverWriteData(ByVal Pos As Long, data() As Byte)
Public Sub InsertData(ByVal Pos As Long, data() As Byte)
Public Sub ShowInsert()
Public Sub CopyData(ByVal Pos As Long, ByVal length As Long)
Public Sub DoUndo()
Public Sub Refresh()
Public Sub DoCut()
Public Function Strings(Optional minLen As Long = 7, Optional unicode As Boolean = False) As String()
Public Sub SelectAll()
Public Sub DoPaste()
Public Sub DoPasteOver()
Public Sub DoDelete()
Public Sub DoCopy()
Public Sub ShowGoto()
Public Sub scrollTo(ByVal Pos As Long)
Public Sub ShowFind()
Public Function Search(match As String, Optional isUnicode As Boolean = False, Optional caseSensitive As Boolean = False) As String()
Public Function ShowHelp()
Public Function ShowAbout()
Public Function ShowOpen(Optional initDir As String, Optional ViewOnly As Boolean = False) As Boolean

Attached Images
 
Attached Files

[VB6] - PE parsing library

$
0
0
This is a set of classes for parsing PE files.

Exposes most commonly needed fields such as optional header, imports, exports, relocations, resources, sections, etc.
Includes a couple extras such as a built in offset calculator form, file properties class, hashing class, and asm/disasm classes (if you have the C olly.dll)

Stable source attached, any updates will be in git here:

https://github.com/dzzie/libs/tree/master/pe_lib2

If you need to work on x64 binaries I do have a newer version but it has another ActiveX dependency for working
with x64 numbers.

https://github.com/dzzie/libs/tree/master/pe_lib3

If you have to work with .NET structures check out vbgamers work at the link below.
I havent played with this section of code yet but will eventually include it in my libs:

https://github.com/VBGAMER45/Semi-VB...r/modVBNET.bas
Attached Files

VB6 - Hash10

$
0
0
Now this one makes a lot of sense. I accidentally ran across it while searching for something else.

https://docs.microsoft.com/en-us/win...ypt-bcrypthash

BCryptHash performs a single hash computation. This is a convenience function that wraps calls to BCryptCreateHash, BCryptHashData, BCryptFinishHash, and BCryptDestroyHash.

Attached is the updated Hash program I previously posted.

Unfortunately, it only works in Windows 10. If you try to run it in Vista or Win 8.1, you will get this error:

Run-time error '453':
Can't find DLL entry point BCryptHash in bcrypt.dll

J.A. Coutts

Note: Because I don't have VB6 on a Win 10 machine, this program has never been run in the IDE, only as an executable on Win 10.
Attached Files

CheckBoxCombo 1.3 (A professional, effective and ready-to-use Multi-select ComboBox)

$
0
0
What is CheckBoxCombo?

CheckBoxCombo is a general-purpose Multi-select ComboBox User Control designed for Visual Basic. It differs from the conventional ComboBox behavior by allowing user to select one or more items from its drop-down list. CheckBoxCombo greately integrates the existing power of standard VB controls (ComboBox and ListBox) to provide its powerful features and can be easily integrated into any sort of Windows GUI project in VB. Sure, it's a must to have companion in your standard VB Toolbox.

Why is CheckBoxCombo?

The conventional ComboBox control in VB allows you to select only one item at a time from its drop-down list. It cannot be used in situations where you need to select more than one item at a time. For this particular purpose you should use a multi-choice enabled ListBox, which is all right, if you have enough space on your interface/form. But what if you have a very limited space to place the ListBox with dozens of items; may be closer to the bottom of your interface? CheckBoxCombo is a great replacement in such situations where you need to save the space on your UI (User Interface), with its great dynamic features.

CheckBoxCombo is also elegant in providing multiple inputs to SQL queries in database programming.

Further, CheckBoxCombo allows you to set any of its properties even at run-time, which is not even allowed by the traditional ComboBox control. One such property is [sorted], which you can dynamically set the sorting at run-time. This gives you a great flexibility in using the user control simply by overriding the design-time settings as you wish. CheckBoxCombo also exposes some methods to support less coding when working with it.

Its [OnListSearch] property helps user to search and select any item in the list easily.

The user control greatly supports for modern visual styles since it integrates the existing VB controls which support visual styles.

The ActiveX version of CheckBoxCombo is fully compatible even with VBA, if you need to use CheckBoxCombo with Microsoft Office (32-bit) as well.

With CheckBoxCombo's professional features and familiarity in use due to nearly familiar syntax it provides, you will more feel it like a must to have control in your standard VB Toolbox.

Outstanding features of CheckBoxCombo:

  • Professional, effective and ready-to-use design for any sort of Windows GUI project in VB
  • No dependent modules, extremely easy to integrate as a single module
  • Extremely easy to use
  • Ability to setup all supported properties even at run-time
  • Very smooth and faster operation, even with thousands of items
  • Dynamic sorting on ascending or descending, supporting thousands of items
  • Supports for different longest-text-display modes
  • Search-and-select feature for items
  • Exposes methods to support less coding
  • Highly flexible and configurable
  • Powerful and reliable on all supported operations
  • User friendly and familiar syntax
  • Supports for all flavors of Windows from Windows XP with visual styles
  • Full ActiveX compatibility with VBA (Microsoft Office 32-bit)
  • And more...

Note: Please go through the User Documentation and study the Demo Application attached herewith, so that you may get a clear idea about CheckBoxCombo.

Comments, suggestions are greatly welcome...

Version History:
Code:

 
Revision update 1.3.2 (18-07-2018)
 ----------------------------------
 • Made internal improvements in hooking machanism
 • Bugfixes in ActiveX
 
 CheckBoxCombo 1.3 (15-07-2018)
 ------------------------------
 • Made changes to ActiveX version to be fully compatible with VBA.
  Now it’s possible to use CheckBoxCombo even in UserForms,
  Spreadsheets, Documents, etc. in Microsoft Office 32-bit editions
 • Optimized hooking mechanism
 • Fixed issues with MDI
 • Fixed issues related to Display Monitor
 • Fixed issues with mouse-wheel and scrollbars
 • Made minor changes to documentation

 CheckBoxCombo 1.2 (05-07-2018)
 ------------------------------
 • Included FillList method. Now the list can be filled by
  a String/Variant type array
 • Fixed the scrollbar issue
 • Enhanced the mouse-click support for selecting/unselecting
  items in the list. Now mouse-click supports anywhere on the
  list item for quick selections
 • Fixed several minor bugs and general optimizations were done
 • Updated User Documentation
 
 CheckBoxCombo 1.1 (30-06-2018)
 ------------------------------
 • Made syntax changes of AddItem, RemoveItem and FindItem methods
 • Introduced DelimiterConact Property
 • Introduced CBCUPdate Property
 • Introduced CBCUpdateCompleted event
 • Revised <Change> event in v1.0 to <ItemCheck>
 • Fixed several bugs and some optimizations were done
 • Updated User Documentation

CheckBoxCombo 1.0 (26-06-2018)
 ------------------------------
 • The initial version of CheckBoxCombo

Attached Images
    
Attached Files

Add-In to Replace Fonts

$
0
0
Here's a little Add-In I wrote, primarily for replacing all the MS Sans Serif fonts in large projects I've got, and I thought I'd share. It does allow you to replace any screen-available font with any other screen-available font. It's been something I've wanted/needed to do for some time.

Here's a screenshot:

Name:  ReplaceFont.png
Views: 302
Size:  7.9 KB

Let me give some caveats to start:

  • I haven't tested it for any MDI-type projects, and I'm not sure what it'll do in those situations.
  • I always use my IDE in a SDI mode, but I don't think that should make any difference.
  • I didn't do the work to make an IDE Toolbar button for it. However, once it's loaded, it'll appear as a menu sub-item on the Add-Ins menu. If you click the "Hide Me" button on the interface, just click the "Replace Font" sub-menu item, and it'll re-appear.


Also, let me talk a bit about Add-Ins for the uninitiated. There are a couple of different ways to execute this Add-In: One, you can just load it in the IDE and execute it. When you do this, it'll execute but nothing much will happen. However, if you load a second copy of the IDE and then call up your Add-In Manager, you'll see this Add-In. If you Load it, you'll then see the Add-In. However, all of this is more-or-less a mode for debugging the Add-In.

The second way to use it is to compile it. It'll make an Add-In-type ActiveX DLL. And, the mere act of compiling it will also register it. Just because I'm a nice guy, I've also included two little DLLReg.vbs & DLLUnreg.vbs scripts. If you drag the compiled DLL onto either of those scripts, it'll register/unregister it. If you compiled it, but didn't compile it where you want it to permanently reside, this will allow you a way to move it (unregister, move the DLL, re-register). Personally, I have a VB6_Addins folder in my Microsoft Visual Studio folder, and that's where I keep these DLLs. Also, the act of compiling will create a couple of other files (ReplaceFont.exp & ReplaceFont.lib), but those aren't needed and can be deleted. Just don't delete the source files (ReplaceFont.vbp, ReplaceFont.frm/x, ReplaceFont.Dsr).

Let me say a bit about the features too:

  • If you specify controls (in addition to forms), it will go through all controls of the form, regardless of whether or not they're nested in containers.
  • The "List w Font" button doesn't actually do anything to your project. However, it goes through all the forms and controls, and makes a list of the forms that have the "From" font somewhere on them. It's just a way to get an idea of what the "Do The Font Replacement(s)" button will do if you click it.
  • The "Segoe" and "Microsoft Sans Serif" buttons are just a couple of quick options for filling in the "To" font.


UPDATE (July 1, 2018, version 1.01): Fixed the tab order, alphabetized (sorted) the ComboBoxes, added an option to cover CTL & PAG files in addition to FRM files.

Enjoy,
Elroy
Attached Images
 
Attached Files

Detect DLL support

$
0
0
I found an API call that simplifies the Hash process by combining several steps into one:

http://www.vbforums.com/showthread.p...017-VB6-Hash10

It only works with Win 10, and I was curious if there was a performance advantage. So I hashed a 7,042 KB file several times with the old process, and with the newer process on the same Win 10 machine. The average time taken with the old process was 0.101 seconds, compared to 0.065 seconds with the newer process. I cannot explain why, but there does seem to be an advantage to using the newer process when it is available. That would mean being able to detect if the newer call was supported. So I came up with this:
Code:

    On Error Resume Next
    'Test if Win 10 API supported using dummy call
    Call BCryptHash(0&, 0&, 0&, 0&, 0&, 0&, 0&)
    If Err = 453 Then 'Use original API cslls
        bHash = HashData(StrPtr(HashAlg), bBuffer)
    Else 'Use Win 10 Calls
        bHash = Hash10Data(StrPtr(HashAlg), bBuffer)
    End If

Is there a better way to accomplish this?

J.A. Coutts

VB6 Simple Virtual ComboBox (OwnerDrawn)

$
0
0
As the title says, a simple approach to accomplish ownerdrawing from Data in external Data-Containers
in a "DropDown-scenario".

As usual with virtual (bound) Controls, they are internally lightweight, since the Drawing happens on the outside.

Nevertheless (depending on what the OwnerDraw-Event offers), a typical scenario
can usually be implemented in only a few lines of OwnerDraw-Handler-Code -
right on the Data of your exernal DataSource-Container (be that an Array, a Collection or a Recordset).

The implementation below is based on only about 140 Lines of UserControl-Code.
Feel free to swap the SubClasser (Tricks clsSubClass currently) to your own implementation, if you like...

And since "Multi-Select-DropDown-scenarios" are apparently "en vouge" these days,
the Control supports this as well - as the ScreenShot below shows:


Ok, here's the Demo-Code: VirtualCombo.zip

Have fun with it...

Edit: enhancement of the MinVisibleItems-Prop, to work also in non-manifested environments.
Edit2: MouseWheel-based Scrolling now updates the currently selected Item-under the Mouse + additional Event (MouseMoveOnItem, to address Hover-Areas within a given Item)

Olaf
Attached Files

(VB6) Err.Raise using HRESULT_FROM_WIN32 and vbObjectError

$
0
0
Convert Win32 error using vbObjectError and HRESULT_FROM_WIN32

HRESULT_FROM_WIN32 is the name of a macro used in C to convert a WIN32 error into an HRESULT error (although since XP it has been replaced by an inline function).

The Win32 errors are easily converted into HRESULT errors. Win32 errors are 16 bit values, whilst HRESULT errors are 32 bit values. The additional 16 bits define the Facility and the Severity of the error. HRESULT encapsulates Win32 errors when the Facility code is set to FACILITYT_WIN32 and severity set to SEVERITY_ERROR and the low 16 bits contain the Win32 error number.

vbObjectError is the exact value of an HRESULT with the facility code set to FACILITY_ITF.

Visual Basic will recognize a returning HRESULT from a function and process it automatically using Err.Raise. When you raise an error in Visual Basic with "Err.Raise vbObjectError Or nMyError," you are unknowingly using an HRESULT with a status code of nMyError.

It is a small step to convert from a FACILITY_ITF used in vbObjectError to a FACILITY_WIN32 required to encapsulate Win32 API errors. Win32 errors are then recognised by Visual Basic as an HRESULT and the Err.Description includes the description of the Win32 error.

The conversion is to take the 16 bit Win32 errors and combine this with FACILITY_WIN32 and SEVERITY_ERROR. It is not necessary to use the vbObjectError but because of the HRESULT connection, it illustrates how Visual Basic can use HRESULT errors.

The constant vbObjectError is derived from the FACILITY_ITF code together with the Error severity code.
vbObjectError = FACILITY_ITF or Severity_Error
= (4 << 16) or 0x80000000


This vbObjectError can be used to create a new constant vbWin32Error by adding an adjustment for the different FACILITY codes FACILITY_ITF and FACILITYT_WIN32.
vbWin32Error = vbObjectError + ((FACILITY_WIN32 - FACILITY_ITF) * (2 ^ 16))

The Win32API error can then be converted to an HRESULT error by adding this constant vbWin32Error to the error, and the error can be trapped using the Visual Basic Err.Raise method, and the error description can be accessed using Err.Description.

The resulting Err.Description identifies the error as a Win32 HRESULT by starting the error description with "Automation error"

The function below HRESULT_FROM_WIN32 converts a Win32 Error into an HRESULT, and the function WIN32_FROM_HRESULT converts HRESULT error back into Win32 Error.

Code:

Private Const FACILITY_ITF = 4
Private Const FACILITY_WIN32 = 7
Private Const vbWin32Error = vbObjectError + ((FACILITY_WIN32 - FACILITY_ITF) * (2 ^ 16))

Public Function HRESULT_FROM_WIN32(LastDllError As Long) As Long
    If (((LastDllError And (Not &HFFFF&)) = 0) and (LastDllError <>0)) Then
        HRESULT_FROM_WIN32 = (LastDllError Or vbWin32Error)
    Else
        HRESULT_FROM_WIN32 = LastDllError
    End If
End Function

Public Function WIN32_FROM_HRESULT(HRESULT As Long) As Long
    If ((HRESULT And (Not &HFFFF&)) = vbWin32Error) Then
        WIN32_FROM_HRESULT = (HRESULT And &HFFFF&)
    Else
        WIN32_FROM_HRESULT = HRESULT
    End If
End Function

These functions can be used to raise a VB error from a Win32 api function, using the err.raise method:

Code:

Private Sub UsageExample()
Dim RetApi As Long
    On Error GoTo EH
'    RetApi = Win32ApiFunction() ' returns 0 if error, <> 0 if successful
    If RetApi = 0 Then
        Err.Raise HRESULT_FROM_WIN32(Err.LastDllError)
    End If
    Exit Sub
EH:
    MsgBox "Error Nos : " & WIN32_FROM_HRESULT(Err.Number) _
    & vbCrLf & "Error : " & Err.Description
End Sub


References
  • Q189134 HOWTO: Raise an Error in Visual Basic From Your C DLL
  • MSDN OldNewThing blog - How do I convert an HRESULT to a Win32 error code
  • WinError.h
  • Platform SDK: COM - Using Macros for Error Handling
  • MSDN blog - The evolution of HRESULT_FROM_WIN32


Update July 6th 2018

Google Cloud Natural Language Text-To-Speech

$
0
0
PLEASE SEE THE INCLUDED READ ME FILE FOR COMPLETE INSTRUCTIONS BEFORE RUNNING THE PROJECT

Here is a project I did that shows you how to use the power of Google Cloud for next level natural sounding Text-To-Speech (TTS).
It shows you how to use either Windows Media Player or the Common Controls MultiMedia control to play the audio files.
Google Cloud TTS Documentation

Unfortunately, you can NOT just open the project and run it... It requires you to have a google cloud account with text to speech API enabled. It is complicated to set up but once you do its trivial to use. It is completely free to sign up but does require a credit/debit card. It is completely free for the first 1-4 million characters.They don't charge your account but access will be denied once the limit is reached till you upgrade your account.

Normally you would have a server (called the backend) that processes the request for you in client applications as not to leak your access tokens.Google cloud tts is free for 1 million characters and after they charge $4 per milllion. I plan on using this in future applications so i couldn't include the access tokens in the code. YOU MUST HAVE YOUR OWN GOOGLE CLOUD ACCOUNT TO RUN THE PROGRAM!
(Note: If someone would like to donate their first 1 million free characters for this example let me know.)

PLEASE SEE THE INCLUDED READ ME FILE FOR COMPLETE INSTRUCTIONS BEFORE RUNNING THE PROJECT

This sample app uses and requires the following technologies:
1. Inet transfer control (MSINET.OCX)
2. Windows Media Player Control (wmp.dll)
3. Common Controls 6.0 (mscomctl.ocx)
4. Common controls multimedia control (mci32.ocx)
5. Google Cloud SDK (see readme file)

It also uses code from the following sources:
1. JSONBAG by Robert D. Riemersma, Jr. (dilettante)
2. GetCommandOutPut by Mattias Sjögren

Name:  ss.jpg
Views: 226
Size:  57.4 KB


GoogleCloudTTS.zip
Attached Images
 
Attached Files

Getting the selected text in the code window (with an add-in)

$
0
0
I have lots of Doc IDs as comments in my vb project eg
Code:

'see doc#25 for more info
And i wanted to be able to quickly show the document.

This code below will show you the selected text and then you can parse it out and respond to any number of things you might find


  1. Create a new project
  2. Select "AddIn" from list of project types
  3. Add a timer to the form frmAddIn
  4. set the timer interval to 300
  5. Add this code to timer1_timer() event


Code:

   
    Dim startLine As Long, startCol As Long
    Dim endLine As Long, endCol As Long
    Dim sContent As String, tmp As String, l As Long
   
    On Error Resume Next
    VBInstance.ActiveCodePane.GetSelection startLine, startCol, endLine, endCol
    On Error GoTo 0

    If startLine <> 0 Then
        For l = startLine To endLine
            tmp = VBInstance.ActiveCodePane.CodeModule.Lines(l, 1)
            If l = endLine Then tmp = Left(tmp, endCol - 1)
            If l = startLine Then tmp = Right(tmp, (Len(tmp) - startCol) + 1)
            sContent = sContent & IIf(Len(sContent) > 0, Chr(10), "") & _
                      tmp
        Next l
    End If
    Debug.Print sContent & "    " & Timer

  1. Run the addIn project
  2. Open or Start another project "Standard Exe"
  3. Click the "add-ins" menu
  4. Click the "My AddIn" sub menu
  5. Open a code window and highlight some code and you will see the highlighted text in the immediate window of the AddIn project


note: I'm also looking for a way to detect what text is under the cursor when hovering over some code. If anyone knows of a way to do this, let me know.

VB6 - Transit Time Tester V2

$
0
0
Attached is an upgraded version of Transit Time Tester utilizing a subset of SimpleSock.

Users sometimes want to know how accessible a certain site is and how long it takes to get to it. The "ping" command has traditionally been used for that, but there are problems using this utility. The difficulty is created by the way that some routers handle Internet Control Message Protocol (ICMP) packets. These routers give ICMP packets the lowest priority, so the round trip time displayed is highly questionable.

The TTL in "ping" packets does not actually represent a "Time To Live". It is a hop counter. To prevent a packet from going into an endless loop, the TTL is decremented as it goes through each router. If the counter gets to zero, the router is supposed to send a message back to the originator. "Tracert" utilizes this feature. The TTL is incremented for each ping packet that it sends out, so in theory it can track the packet as it goes through each router. Some routers have the feature turned off to prevent "Ping Floods" or if they are deemed too busy to handle them.

One would expect that the return time would increase as the TTL is incremented. But that is often not the case, due to the fact that routers give these packets a lower priority and delay them.

"Ping", (as well as "Tracert") utilize UDP packets, which do not establish a connection with the far end. Transit Time Tester uses TCP packets, which are initiated using a 3-way handshake. The client sends a SYN request, the server responds with a SYN-ACK, and the client completes the connection with an ACK. Transit Time Tester measures the time required to receive the SYN-ACK, and prevents the connection from being established by forcing an error.

When it came time to write this description, the network was not that busy and the return times pretty well matched the ping times. Fortunately I had some historical data that represented the case.

Using the "Ping command:
C:\>ping 96.53.96.50
Pinging 96.53.96.50 with 32 bytes of data:
Reply from 96.53.96.50: bytes=32 time=52ms TTL=58
Reply from 96.53.96.50: bytes=32 time=50ms TTL=58
Reply from 96.53.96.50: bytes=32 time=52ms TTL=58
Reply from 96.53.96.50: bytes=32 time=49ms TTL=58
Ping statistics for 96.53.96.50:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 49ms, Maximum = 52ms, Average = 50ms

Using "Transit Time Tester" as shown below yielded an average time of 47 ms. The "Ping" was returned by the router in front of the server (one less hop), and clearly demonstrates that the TCP packets had a higher priority.

For the domain, you can use the domain name, the domain IP Address, or just copy and paste the URL. If the URL is used, the port is automatically adjusted to 80.

J.A. Coutts
Attached Images
 
Attached Files

[VB6] Multithreaded Connect 4 AI

$
0
0
This AI uses The trick's multi threading module to search the game tree using the negamax algorithm. My multi threading implementation is not very efficient, as it creates one thread per column, meaning it can use at most 7 threads, less if columns are full. This still results in a 3-4x speedup over the single threaded version, which you can toggle between. The program will work within the IDE, but multi threading is disabled.

The main thread is not loaded at all during the search, meaning that you can drag the program around smoothly while it is calculating a move. This is accomplished by sending Windows messages from the threads, which the main thread receives and uses to calculate a final move.

While compiling, you can enable all advanced optimizations. I have included two versions. The first one is the standard option, and uses an older version of modMultiThreading that requires a tlb file. The second version does not require a tlb file, but is much slower, even in single threaded mode. If you have any questions about this program, feel free to ask me.
Connect 4 MT.zip
Connect 4 MT NO TLB.zip
Attached Files

Fast Call COM object (activex.dll) ,Run Windows API

$
0
0
How to test the method of the COM object (activex.dll) in real time and run the windows api?
【Organizing, testing the project, and uploading examples after completion】

Method 1: Use VBS to create new objects or call the API library to call the WINDOWS function library
Method 2: Use VB6's Add-in plug-in method to dynamically create a project, create an object variable, and run
Method 3: The createobject ("excel.application") method creates a new Excel vba module, automatically adds code, and runs

It would be nice if each file could have a manual like PHP online tutorial.
Each process method and function can be directly tested without running into EXE.
Each method and function are listed in the manual, and you can run the test with one click to see the effect.

It's like there are tens of thousands of windows api, such as findwindow, messageboxa.
Make a table, write a description of the parameter types required by each API, add some test data, and you can run it directly to see the effect.
To achieve the same EXCEL formula, run windows api, Activex.Class1.Method (parameter 1, parameter 2) as a formula and run it immediately.

PHP Tutorial | Rookie Tutorial
https://www.runoob.com/php/php-tutorial.html
Rookie Tutorial Online Editor
https://www.runoob.com/try/runcode.p...intro&type=php
----------------
<! DOCTYPE html>
<html>
<body>

<? php
echo "Hello World!";
?>

</ body>
</ html>

There is a button "click to run code" on the page
-------------

Vb6 OpenOffice sdk(com.sun.star.ServiceManager)

$
0
0
need install jdk first

OpenOffice_sdk http://www.openoffice.org/api/basic/...l/tutorial.pdf
JDK1.8
32bit jdk https://www.7down.com/soft/267473.html
OpenOffice4.1.7 https://www.openoffice.org/download/

HKEY_CLASSES_ROOT\com.sun.star.ServiceManager
CLSID:{82154420-0FBF-11d4-8313-005004526AB4}
C:\Program Files (x86)\OpenOffice 4\program\soffice.exe -nodefault -nologo

Code:

Option Explicit

Private Sub Command1_Click()
NewExcelWord
'good_新建一个Excel和Word文档
End Sub

Private Sub Command3_Click()
'新建Excel类表格
'NewExcel
Dim mNoArgs()
Dim oSpreadsheetDocument As Object
Dim oTextDocument As Object
'Using StarOffice API - Basics 19
Dim oSM As Object
Set oSM = CreateObject("com.sun.star.ServiceManager")
Dim oDesktop
Set oDesktop = oSM.CreateInstance("com.sun.star.frame.Desktop")
'oDesktop = createUnoService("com.sun.star.frame.Desktop")
Dim sUrl
sUrl = "private:factory/scalc"
Set oSpreadsheetDocument = _
oDesktop.loadComponentFromURL(sUrl, "_blank", 0, mNoArgs())
 

 'GetCell = oSheet.getCellByPosition(nColumn, nRow)
 Dim oSheet As Object
 Set oSheet = oSpreadsheetDocument.getSheets().getByIndex(0)
 Dim Row As Long, Col As Long
 Row = 2
 Col = 2
 
  Dim s As String
 For Row = 1 To 3
 For Col = 1 To 5
 
 'oSheet.getCellByPosition(Col - 1, Row - 1).Value = Row & Col
 s = "v" & Row & Col
 
 'oSheet.getCellByPosition(Col - 1, Row - 1).v = Row & Col' long,value
 oSheet.getCellByPosition(Col - 1, Row - 1).String = s '
 Next
 Next

End Sub

Sub NewExcelWord()
Dim mNoArgs()
Dim oSpreadsheetDocument As Object
Dim oTextDocument As Object
'Using StarOffice API - Basics 19
Dim oSM As Object
Set oSM = CreateObject("com.sun.star.ServiceManager")
Dim oDesktop
Set oDesktop = oSM.CreateInstance("com.sun.star.frame.Desktop")
'oDesktop = createUnoService("com.sun.star.frame.Desktop")
Dim sUrl
sUrl = "private:factory/scalc"
Set oSpreadsheetDocument = _
oDesktop.loadComponentFromURL(sUrl, "_blank", 0, mNoArgs())
sUrl = "private:factory/swriter"
Set oTextDocument = _
oDesktop.loadComponentFromURL(sUrl, "_blank", 0, mNoArgs)
End Sub

Private Sub Command4_Click()
 'OpenWord
 '打开一个WORD文件
Dim mFileProperties(0) ' As New com.sun.star.beans.PropertyValue
Dim sUrl As String
Dim oSM As Object
Set oSM = CreateObject("com.sun.star.ServiceManager")
Dim oDesktop
Dim oDocument
Set oDesktop = oSM.CreateInstance("com.sun.star.frame.Desktop")

sUrl = "file:///" & App.Path & "\002word.doc"
sUrl = Replace(sUrl, "\", "/")
sUrl = GetFileName(App.Path & "\002word.doc")

'mFileProperties(0).Name = "FilterName"
'mFileProperties(0).Value = "scalc: Text - txt - csv (StarCalc)"
Set oDocument = oDesktop.loadComponentFromURL(sUrl, "_blank", 0, mFileProperties())
End Sub
Function GetFileName(ByVal sUrl As String) As String
sUrl = "file:///" & sUrl
sUrl = Replace(sUrl, "\", "/")
GetFileName = sUrl
End Function

Private Sub Command5_Click()
 'Open Excel File
 '打开一个Excel文件,GOOD
Dim mFileProperties(0) ' As New com.sun.star.beans.PropertyValue
Dim sUrl As String
Dim oSM As Object
Set oSM = CreateObject("com.sun.star.ServiceManager")
Dim oDesktop
Dim oDocument
Set oDesktop = oSM.CreateInstance("com.sun.star.frame.Desktop")

sUrl = GetFileName(App.Path & "\001excel.xls")

Set oDocument = oDesktop.loadComponentFromURL(sUrl, "_blank", 0, mFileProperties())
End Sub

vb Fast Crc32 (crc32str,Crc32File)

$
0
0
Running speed test record: average time,Evaluation object
====================
use CbsPersist_20200521111942.log(161m),not 7z format

time(ms) TestObject
125.76 Crc32_Wqweto
281.03 Crc32ByAsm
326.17 Crc32Api
458.95 Crc32_LaVolpe
461.22 Crc32FromByte
====================
(USE 320M File,7z format)

----------------Advanced optimization:
249.41 Crc32_Wqweto
555.39 Crc32ByAsm
648.79 Crc32Api

905.41 Crc32_LaVolpe
906.42 Crc32FromByte
----------------Pentium Pro(Tm) optimization:
573.88 Crc32ByAsm UsedTime(Ms)
665.31 Crc32Api UsedTime(Ms)
737.25 Crc32FromByte UsedTime(Ms)
739.31 Crc32_LaVolpe UsedTime(Ms)
====================
Why is this forum picture compressed automatically? The total capacity of attachments uploaded at the same time is also pitiful?
Name:  FunctionSpeedTesting.jpg
Views: 104
Size:  47.6 KB
method1:use api RtlComputeCrc32
Code:

Private Declare Function RtlComputeCrc32 Lib "ntdll.dll" ( _
    ByVal dwInitial As Long, _
    ByVal pData As Long, _
    ByVal iLen As Long) As Long

Public Function Crc32Api ( tBuff() As Byte) as long   
    Crc32Api = RtlComputeCrc32(0, VarPtr(tBuff(0)), UBound(tBuff) + 1)
End Function

Public Function GetStringCRC32(ByVal InString As String) As String
'123456789=CBF43926
    Dim lRet As Long, tBuff() As Byte
   
    tBuff = StrConv(InString, vbFromUnicode)
   
    lRet = RtlComputeCrc32(0, VarPtr(tBuff(0)), UBound(tBuff) + 1)
    GetStringCRC32 = Hex(lRet)
End Function

method2:
Code:

'call InitCrc32 'First
Dim CRC32Table(255) As Long


Private Declare Function MultiByteToWideChar Lib "kernel32 " (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32 " (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
Private Const CP_ACP = 0 ' default to ANSI code page
Private Const CP_UTF8 = 65001 ' default to UTF-8 code page

'string to UTF8
Public Function EncodeToBytes(ByVal sData As String) As Byte() ' Note: Len(sData) > 0
Dim aRetn() As Byte
Dim nSize As Long
nSize = WideCharToMultiByte(CP_UTF8, 0, StrPtr(sData), -1, 0, 0, 0, 0) - 1
If nSize = 0 Then Exit Function
ReDim aRetn(0 To nSize - 1) As Byte
WideCharToMultiByte CP_UTF8, 0, StrPtr(sData), -1, VarPtr(aRetn(0)), nSize, 0, 0
EncodeToBytes = aRetn
Erase aRetn
End Function

Function Crc32FromByte(B() As Byte) As Long
    Dim i As Long, iCRC As Long
    iCRC = &HFFFFFFFF
    For i = 0 To UBound(B)
        iCRC = (((iCRC And &HFFFFFF00) \ &H100) And &HFFFFFF) Xor CRC32Table((iCRC And &HFF) Xor B(i))
    Next
    Crc32FromByte = iCRC Xor &HFFFFFFFF
End Function

Function crc32byte(B() As Byte) As long
    Dim i As Long, iCRC As Long, lngA As Long, ret As Long
    dim bytT As Byte, bytC As Byte
   
    iCRC = &HFFFFFFFF
    For i = 0 To UBound(B)
        bytC = B(i)
        bytT = (iCRC And &HFF) Xor bytC
        lngA = ((iCRC And &HFFFFFF00) \ &H100) And &HFFFFFF
        iCRC = lngA Xor CRC32Table(bytT)
    Next
    ret = iCRC Xor &HFFFFFFFF
    crc32byte =ret
End Function

'string's CRC32
Public Function crc32str(item As String) As String
    Dim i As Long, iCRC As Long, lngA As Long, ret As Long
    Dim B() As Byte, bytT As Byte, bytC As Byte
    B = StrConv(item, vbFromUnicode)
   
    iCRC = &HFFFFFFFF
    For i = 0 To UBound(B)
        bytC = B(i)
        bytT = (iCRC And &HFF) Xor bytC
        lngA = ((iCRC And &HFFFFFF00) \ &H100) And &HFFFFFF
        iCRC = lngA Xor CRC32Table(bytT)
    Next
    ret = iCRC Xor &HFFFFFFFF
    crc32str = Right("00000000" & Hex(ret), 8)
End Function

Public Function Crc32File(sFilePath As String, Optional Block As Long = 1024) As Long ' String
'改进后180M左右以上的文件更快了,超过“GetFileCRC32_MapFile”
    Dim hFile As Long, i As Long, iCRC As Long, lngA As Long, Size As Long, ret As Long
    Dim bytT As Byte, bytC As Byte
    Dim sSize As Currency, total As Currency, Ub As Long
    total = FileLen(sFilePath)
    If total = 0 Then Exit Function 'Len(Dir(sFilePath))
    If total < 0 Then total = total + 256 ^ 4
    sSize = Block * 1024
    hFile = FreeFile
    Open sFilePath For Binary Access Read As #hFile
    iCRC = &HFFFFFFFF
'    Dim sSize2 As Long
'    sSize2 = sSize + 1
    'Dim sSizeX As Long
    'sSizeX = sSize - 1

    Ub = sSize - 1
    ReDim B(Ub) As Byte
 
'sSize=8,sSizeX=7
    While total >= sSize '>=8  '722-725
    'While total > sSizeX  '>7
    'While total > sSize - 1 '慢去 '713-715
        Get #hFile, , B
        For i = 0 To Ub
            bytC = B(i)
            bytT = (iCRC And &HFF) Xor bytC
            lngA = ((iCRC And &HFFFFFF00) \ &H100) And &HFFFFFF
            iCRC = lngA Xor CRC32Table(bytT)
        Next
        total = total - sSize
    Wend
   
    If total > 0 Then '余下区块
        Ub = total - 1
        ReDim B(Ub) As Byte
        Get #hFile, , B
        For i = 0 To Ub
            bytC = B(i)
            bytT = (iCRC And &HFF) Xor bytC
            lngA = ((iCRC And &HFFFFFF00) \ &H100) And &HFFFFFF
            iCRC = lngA Xor CRC32Table(bytT)
        Next
    End If
   
 
   
    Close #hFile
    ret = iCRC Xor &HFFFFFFFF
    Crc32File = ret
    'Crc32File = Right("00000000" & Hex(ret), 8)
End Function
'CRC32 Table
Public Function InitCrc32(Optional ByVal Seed As Long = &HEDB88320, Optional ByVal Precondition As Long = &HFFFFFFFF) As Long
    Dim i As Integer, j As Integer, CRC32 As Long, Temp As Long
    For i = 0 To 255
        CRC32 = i
        For j = 0 To 7
            Temp = ((CRC32 And &HFFFFFFFE) \ &H2) And &H7FFFFFFF
            If (CRC32 And &H1) Then CRC32 = Temp Xor Seed Else CRC32 = Temp
        Next
        CRC32Table(i) = CRC32
    Next
    InitCrc32 = Precondition
End Function

METHOD3: GetCrcByASM.CLS
Code:

Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Sub CpyMem4 Lib "msvbvm60.dll" Alias "GetMem4" (Source As Any, Destination As Any)

Dim ASMBL() As Byte
Dim Table(0 To 255) As Long
Function Crc32ByAsm(Data() As Byte) As Long
'0为下标的数组,原来函数名:ChecksumDataEx
    Dim CRC32 As Long
    CRC32 = &HFFFFFFFF
    On Local Error GoTo ErrCB
    CallWindowProc VarPtr(ASMBL(0)), VarPtr(CRC32), VarPtr(Data(0)), VarPtr(Table(0)), UBound(Data) + 1
ErrCB:
    Crc32ByAsm = Not CRC32
End Function

Function ChecksumFileEx(Path As String) As Long
On Error GoTo ErrFC
Dim FreeF As Integer, Data() As Byte
FreeF = FreeFile
Open Path For Binary Access Read As #FreeF
ReDim Data(0 To LOF(FreeF) - 1) As Byte
Get #FreeF, , Data
Close #FreeF
ChecksumFileEx = Crc32ByAsm(Data)
ErrFC:
End Function
Function ChecksumFile(Path As String) As String
ChecksumFile = Hex(ChecksumFileEx(Path))
End Function

Function ChecksumTextEx(Text As String) As Long
If Len(Text) = 0 Then Exit Function
ChecksumTextEx = Crc32ByAsm(StrConv(Text, vbFromUnicode))
End Function
Function ChecksumText(Text As String) As String
ChecksumText = Hex(ChecksumTextEx(Text))
End Function


Function Crc32ByAsm2(Data() As Byte) As Long '非0下标
Dim CRC32 As Long
CRC32 = &HFFFFFFFF 'CRC32 初始值(必须)
On Local Error GoTo ErrCB
Dim DLen As Long
DLen = UBound(Data) - LBound(Data) + 1
CallWindowProc VarPtr(ASMBL(0)), VarPtr(CRC32), VarPtr(Data(LBound(Data))), VarPtr(Table(0)), DLen
ErrCB:
Crc32ByAsm2 = Not CRC32
End Function

Function ChecksumData(Data() As Byte) As String
ChecksumData = Hex(Crc32ByAsm(Data))
End Function

Function LngToBin(ipLong As Long) As Byte()
Dim tB() As Byte
ReDim tB(1 To 4)
CpyMem4 ipLong, tB(1)
LngToBin = tB
End Function
Function BinToLng(ipBin4() As Byte) As Long
CpyMem4 ipBin4(LBound(ipBin4)), BinToLng
End Function

Sub IntAsm()
Dim i As Long, j As Long

Const ASM As String = "5589E557565053518B45088B008B750C8B7D108B4D1431DB8A1E30C3C1E80833049F464975F28B4D088901595B585E5F89EC5DC21000"

' Decoded ASM source from HIEW 6.86 (Hacker's View)
'
' 55 PUSH BP
' 89E5 MOV BP,SP
' 57 PUSH DI
' 56 PUSH SI
' 50 PUSH AX
' 53 PUSH BX
' 51 PUSH CX
' 8B4508 MOV AX,DI[08]
' 8B00 MOV AX,BX[SI]
' 8B750C MOV SI,DI[0C]
' 8B7D10 MOV DI,DI[10]
' 8B4D14 MOV CX,DI[14]
' 31DB XOR BX,BX
' 8A1E30C3 MOV BL,0C330
' C1E808 SHR AX,008 <-.
' 3304 XOR AX,[SI] |
' 9F LAHF |
' 46 INC SI |
' 49 DEC CX |
' 75F2 JNE 000000018 -'
' 8B4D08 MOV CX,DI[08]
' 8901 MOV BX[DI],AX
' 59 POP CX
' 5B POP BX
' 58 POP AX
' 5E POP SI
' 5F POP DI
' 89EC MOV SP,BP
' 5D POP BP
' C21000 RETN 00010

ReDim ASMBL(0 To 53) 'Len(ASM) \ 2 - 1
For i = 1 To Len(ASM) - 1 Step 2
ASMBL(j) = Val("&H" & Mid(ASM, i, 2))
j = j + 1
Next i

Dim vCRC32 As Long, vB As Boolean
Const vXor32 As Long = &HEDB88320
For i = 0 To 255
vCRC32 = i
For j = 8 To 1 Step -1
vB = vCRC32 And 1
vCRC32 = ((vCRC32 And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
If vB Then vCRC32 = vCRC32 Xor vXor32
Next j
Table(i) = vCRC32
Next i
End Sub
Private Sub Class_Initialize()
IntAsm
End Sub

method 4:
Code:

Function Crc32_LaVolpe(Buffer() As Byte) As Long
Dim crc32val As Long, i As Long
crc32val = &HFFFFFFFF
For i = 0 To UBound(Buffer)
crc32val = (((crc32val And &HFFFFFF00) \ &H100&) And &HFFFFFF) Xor CRC32Table((crc32val And &HFF) Xor Buffer(i))
Next i
Crc32_LaVolpe = crc32val Xor &HFFFFFFFF
End Function

Attached Images
 

Friend in Class1-VB6 calls multiple methods to run speed test

$
0
0
Optimized for vb6 running speed
call function Fastest c=Bas_Sum(a,b)
call Friend is quick than "public function",The operating speed is 4.6 times faster
-----------
Class_OBJ 452.38 (dim a as class1 ,call a.Sum(**))
Class_Friend_Ptr 70.38
Class_Friend 80.65(call a.FrinedSum)
----------
call objptr like stdcall :cUniversalDLLCalls.CallFunction_COM(***),The operating speed is 1 times faster(up 100%)

Pointer call function address of COM object:
call com dll(activex.dll).FrinedSum(***), Speed increased by 5.6 times
(465.77 pk 70.57)
It takes 827 seconds to call activex.exe, which is 14000 times more than the time to directly call the process

Unfortunately, this seems to be no way. It is like operating the "EXCEL.APPLICATION" object in VB6 and controlling the third-party process of excel.exe. It is very slow. Unless running in EXCEL VBA, it is also about 4 times slower than VB6, but it is slower than ActiveX.EXE with 14,000 times is still much better.
This is just a theoretical number and has not been tested specifically, but calling activex.exe is really slow.
=====================
method1:Friend Function FrinedSum(ByRef a As Long, ByRef b As Long) As Long
method2:Public Function Sum(ByRef a As Long, ByRef b As Long) As Long
method3:Public Function Bas_Sum in moudle.bas
method4:Public Sub BasSub_Sum in moudle.bas

com dll=(class1.cls in comdll1.dll)
actexe=(class1.cls in activex1.exe)
class1.cls in same vb project
call function sum(a,b)
call sub sum(a,b,returnvalue)
The main methods of testing

Code:

TestCount = 1000000*20
Sub Test_Exe1_MySum_object(id As Long)
dim Exe1 as new activex1_exe.Class1
Dim i As Long
For i = 1 To TestCount
    a1 = 3
    b1 = 4
    'Call Exe1_MySum2(ThisExe1, a1, b1, Ret) 'by objptr stdcall
    Ret = Exe1.Sum(a1, b1)
next
end sub

Public Function Bas_Sum(ByRef a As Long, ByRef b As Long) As Long 'method3
 
Bas_Sum = a + b
a = a * a
b = b * b
End Function
Public Sub BasSub_Sum(ByRef a As Long, ByRef b As Long, ByRef Value1 As Long) 'method4
 
Value1 = a + b
a = a * a
b = b * b
End Sub

class1.cls
Code:

Option Explicit
 Public Event Sum2(ByRef id As Long)   

Public Sub Test()
MsgBox "ComDll.lib-test"
End Sub
Public Sub TEST2()
MsgBox "ComDll.lib-test2"
End Sub
Public Function Sum(ByRef a As Long, ByRef b As Long) As Long
 
Sum = a + b
a = a * a
b = b * b
End Function
 
Public Sub test3()
Dim i As Long
Dim v2 As Long
Dim V1 As Long
For i = 1 To 1
V1 = i
v2 = i
 
RaiseEvent Sum2(v2)
 
Next
End Sub
Friend Function FrinedSum(ByRef a As Long, ByRef b As Long) As Long
 
MsgBox "FrinedSum"
FrinedSum = a + b
a = a * a
b = b * b
End Function
Friend Function FrinedSum2(ByRef a As Long, ByRef b As Long) As Long
 
MsgBox "Class_FrinedSum2"
FrinedSum2 = a + b
a = a * a
b = b * b
End Function

Alt+NumPad input for Unicode TextBox with surrogate pair support

$
0
0
When using Alt+NumPad for Unicode input I get a bogus character in Notepad/Notepad++ and all other Unicode TextBox implementations that I tried. WordPad and InkEdit, on the other hand. works OK, including surrogate pairs.

Test summary:
Alt+128512 (&H1F600) WordPad/InkEdit , Notepad/Notepad++/TextBoxW/ucText Nothing
Alt+173569 (&H2A601) WordPad/InkEdit , Notepad/Notepad++TextBoxW/ucText ☺ (&H263A, 9786)
Alt+931 (&H03A3) WordPad/InkEdit Σ , Notepad/Notepad++/TextBoxW/ucText ú (&HFA, 250)

Here is sample code that overrides the internal Alt+NumPad behavior:
1. Assumes you have a subclassed Unicode TextBox with source code that exposes Translate Accelerator.
2, Make sure NumLock is On before testing.
3. Tested with Segoe UI Regular.

Code:

Option Explicit

Private mbDeleteChar As Boolean

Private Function KeyPressed(ByVal KeyCode As KeyCodeConstants) As Boolean
  KeyPressed = CBool((GetAsyncKeyState(KeyCode) And &H8000&) = &H8000&)
End Function

Private Function ToSurrogatePair(ByVal i As Long) As String
  Dim Hi              As Integer, Lo As Integer
  On Error GoTo ErrHandler
  i = i - &H10000
  Hi = i \ &H400 + &HD800
  Select Case Hi
    Case &HD800 To &HDBFF
      Lo = i Mod &H400 + &HDC00
      Select Case Lo
        Case &HDC00 To &HDFFF
          'Debug.Print Hex(Hi), Hex(Lo)
          ToSurrogatePair = ChrW$(Hi) & ChrW$(Lo)
      End Select
  End Select
ErrHandler:
End Function

'Build string in Translate Accelerator WM_SYSKEYDOWN.
Friend Function TranslateAccel(pMsg As Msg) As Boolean
  Static mSysWord  As String
 
    Case WM_SYSKEYDOWN
      If KeyPressed(vbKeyMenu) Then 'Alt Pressed
        Select Case pMsg.wParam
          Case vbKeyNumpad0 To vbKeyNumpad9
            mSysWord = mSysWord & ChrW$(pMsg.wParam - 48)
        End Select
      End If
    Case WM_CHAR
      If Len(mSysWord) Then
        Dim i                As Long
        Dim s                As String
        On Error Resume Next
        i = CLng(mSysWord)
        Select Case i
          Case &HD800& To &HDBFF& 'Skip Reserved
          Case Is <= &HFFFF& '0 - 65535
            s = ChrW$(i)
          Case Is <= &H10FFFF 'Unicode max value
            s = ToSurrogatePair(i)
        End Select
        If Len(s) Then
          SelText = s 'Insert as SelText
          mSysWord = vbNullString 'Reset
          mbDeleteChar = True 'To delete bogus WM_CHAR that Alt+ generated internally.
        End If
        On Error GoTo 0
      End If

'Finally delete the bogus character that appears in WM_CHAR when Alt is released.
myWndProc:
    Case WM_CHAR
      If mbDeleteChar Then
        mbDeleteChar = False
        wParam = 0
      End If

Similar code was tested in Krools TextBoxW (use wParam in lieu pf pMsg.wParam and KeyChar = 0 in WindowProcControl) and it appears to be working OK here. TextBoxW.Zip atttached.

TextBoxW.zip
Attached Files

Vmware Sdk For vb6(VixCOM64.dll),vbs-CreateObject("VixCOM.VixLib")

$
0
0
Need VMWare VIX Automation Tools and SDK

Code:

'Reference
'C:\Windows\SysWOW64\regsvr32.exe ***\VixCOM64.dll
'Reference VixCOM64.dll TO vb6 Project
Dim lib As VixCOM.VixLib
Dim vmPath As String

Private Sub Form_Load()
vmPath = "***/Windows 7.vmx"

' Copyright 2006 VMware, Inc.
' All rights not expressly granted to you by VMware, Inc. are reserved.
'

' VixCOM VBScript Sample Script (powerOn)
'
' This demonstrates how to open a VM, power it on and power it off.
'
' This uses the Wait function to block after starting each
' asynchronous function. This effectively makes the asynchronous
' functions synchronous, because Wait will not return until the
' asynchronous function has completed.
'
' Instructions for Windows 2000 and later operating systems:
'
'  - there should be an accompanying file named 'powerOn.wsf'
'    It is placed in the same directory as this file during
'    product installation. This file is responsible for setting
'    up the Windows Script Host environment and loading the
'    VixCOM type library, thereby enabling this script to
'    reference symbolic constants such as VIX_API_VERSION
'
'  - in a command line window, type:
'    cscript //nologo powerOn.wsf
'
Dim results
'Dim lib
Dim job
Dim host
Dim vm As IVM2
Dim err
Dim useWorkstation
Dim hostType
Dim hostName
Dim hostUsername
Dim hostPassword

Dim poweronOption

' Certain arguments differ when using VIX with VMware Server 2.0 and
' VMware Workstation.
'
' Comment out this line to use this code with VMware Server 2.0.
useWorkstation = 1

If useWorkstation Then
  hostType = VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_WORKSTATION '=3
  hostName = Empty
  hostUsername = Empty
  hostPassword = Empty
  'vmPath = "***/Windows 7.vmx"
  poweronOption = VixCOM.Constants.VIX_VMPOWEROP_LAUNCH_GUI '=512
Else
  ' For VMware Server 2.0
  hostType = VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_VI_SERVER
  hostName = "https://192.20.30.40:8333/sdk"
  hostUsername = "Administrator"
  hostPassword = "password"
  vmPath = "[standard] winxppro/winxppro.vmx"
  poweronOption = VixCOM.Constants.VIX_VMPOWEROP_NORMAL
End If

Set lib = CreateObject("VixCOM.VixLib")

' Connect to the local installation of Workstation. This also intializes the VIX API.
Set job = lib.Connect(VixCOM.Constants.VIX_API_VERSION, hostType, hostName, 0, hostUsername, hostPassword, 0, Nothing, Nothing)

' results needs to be initialized before it's used, even if it's just going to be overwritten.
Set results = Nothing

' Wait waits until the job started by an asynchronous function call has finished. It also
' can be used to get various properties from the job. The first argument is an array
' of VIX property IDs that specify the properties requested. When Wait returns, the
' second argument will be set to an array that holds the values for those properties,
' one for each ID requested.
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
If err <> 0 Then QuitIfError (err)

' The job result handle will be first element in the results array.
Set host = results(0)

' Open the virtual machine with the given .vmx file.
Set job = host.OpenVM(vmPath, Nothing)
err = job.Wait(Array(VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE), results)
If CLng(err) <> 0 Then QuitIfError (err)


Set vm = results(0)
'MsgBox TypeName(vm)


' Power on the virtual machine we just opened. This will launch Workstation if it hasn't
' already been started.
Set job = vm.PowerOn(poweronOption, Nothing, Nothing)
' WaitWithoutResults is just like Wait, except it does not get any properties.
err = job.WaitWithoutResults()
If CLng(err) <> 0 Then QuitIfError (err)
'MsgBox "正在启动,启动完成后,点确定按钮"
MsgBox "Doing Start Vmware virtual machine,When Start Successfull,CLICK OK BUTTON", vbOKOnly

' Here you would do any operations on the guest inside the virtual machine.

' Power off the virtual machine. This will cause Workstation to shut down if it
' was not running previous to the call to PowerOn.
'If MsgBox("是否关闭?", vbYesNo) = vbYes Then
If MsgBox("Do You Want to Close Vmware virtual machine?", vbYesNo) = vbYes Then
Set job = vm.PowerOff(VixCOM.Constants.VIX_VMPOWEROP_NORMAL, Nothing)
err = job.WaitWithoutResults()
If CLng(err) <> 0 Then QuitIfError (err)

host.Disconnect
End If
'MsgBox "测试完成"
MsgBox "TestOk"

End Sub
Sub QuitIfError(errID)
On Error GoTo DoErr
MsgBox "errID:" & CLng(errID)
'  If lib.ErrorIndicatesFailure(err) Then
'      WScript.Echo ("Error: " & lib.GetErrorText(err, Empty))
'      WScript.Quit
'  End If
Exit Sub
DoErr:
MsgBox err.Description
End Sub

VB6 radial Progress-Control

$
0
0
Just another one of these circular Progress-UCs, which recently seem "all the rage" ... ;)

What's different with this one?
- it's really small (only about 80 Lines of Code), so no need to put this into a compiled OCX
- it's entirely GDI-based (just for fun, I've tried to avoid anything "Cairo or GDIPlus")
- it uses a single ChangeSettings-MethodCall ...instead having to set (or implement) a bunch of behaviour-Properties

Here is, what it looks like:


And here's the Zip with the DemoCode:
ucRadialProgress.zip

Have fun,

Olaf
Attached Files

[vb6] Virtual Pet Roach v1.2 (Updated 08/06/20)

$
0
0
Since I see the famouse "sheep.exe" I wanted to create something like a virtual pet... finally 2 decades later I found the time to do it.
This is a cockroach that roam the screen. It run outside the screen when touched with the cursor and if computer is left idle for certain time, start spawning more cockroachs until certain limit.
Animation of every limb and movement is made with detail and looks very realistic.

Also this code can be usefull te see how to interact with the mouse, how to calculate angles, idle detection , creating a systray and draw 8 bits transparency forms (32bpp)

Name:  VirtPet_Snap1.jpg
Views: 153
Size:  15.2 KB
Running wild over desktop windows

Name:  VirtPet_Snap2.jpg
Views: 155
Size:  40.0 KB
Debug movement screen enabled

PD: Also got a cool about screen effect.


Download: prjVirtualPet_v1.2_Src.zip


v1.1 - Memory leak completely fixed!!!!
v1.2 - Fixed display on HighDPI screen

TODO: Multi monitor support
Attached Images
  
Attached Files
Viewing all 1478 articles
Browse latest View live


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