Category Archives: Microsoft

Monitor Mouse and Keyboard Activity

With just a little bit of API goodness, you can monitor mouse and keyboard activity. Option Explicit ‘===========================================================’TYPE’===========================================================Private Type POINTAPIx As Integery As IntegerEnd Type’===========================================================’API’===========================================================Private Declare Sub GetCursorPos Lib “user32.dll” (lpPoint As POINTAPI)Private Declare Function GetAsyncKeyState Lib “user32.dll” (ByVal vKey As Long) As Integer’===========================================================’Variables’===========================================================Private posOld As POINTAPIPrivate posNew As POINTAPI ‘===========================================================’InputCheck’===========================================================Public Function InputCheck() As Boolean    Dim i As Integer… Read More »

User Loop Break

If you have a long-running loop, you might want to give the user the ability to break out of the loop, in case they’ve changed their mind. This bit of code shows how to do that. Module Private Declare Function GetAsyncKeyState Lib “user32.dll” _    (ByVal vKey As Long) As Integer ‘//ESCAPEConst VK_ESCAPE = &H1B’//Button ClickConst VK_LBUTTON = &H1 Usage… Read More »

Kill a Program Process

This will allow you kill running tasks or processes, provided the account you are running it under has the permissions to do so. This could be useful if you want to write your own version of Task Manager. ‘——————————————————-Type PROCESSENTRY32    dwSize As Long    cntUsage As Long    th32ProcessID As Long    th32DefaultHeapID As Long    th32ModuleID As Long    cntThreads As Long    th32ParentProcessID As Long    pcPriClassBase As Long    dwFlags As Long    szexeFile… Read More »

Implement chm Help in Visual Basic

Give your app a more polished appearance by using .chm files for your help system. First place a existing chm File in the project path. You must know what name your htm pages have to work correct. Module Option ExplicitPrivate Declare Function HtmlHelpTopic Lib “hhctrl.ocx” Alias _    “HtmlHelpA” (ByVal hWnd As Long, ByVal lpHelpFile As String, _    ByVal wCommand As… Read More »

Move a non-caption form using no API, no DLL

Paste the following code in a module and call it from the mousemove routine of the form that you like to move as: mousemove [form.name],x,y,button. Drag the form to move it, use same calling code if you need to move the form dragging over a control in the form (pay attention to click_routine potential conflict). Sub moveform(ff As Form,… Read More »

Form Management

This module will help you manage the minimize/maximize buttons, the forms system menu, and the position of your form. Option Explicit Private Declare Function DeleteMenu Lib “user32.dll” (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As LongPrivate Declare Function GetSystemMenu Lib “user32.dll” (ByVal hWnd As Long, ByVal bRevert As Long) As LongPrivate Declare Function… Read More »

Progress Bar Inside Status Bar

This great chunk of code shows how to leverage the Windows API to put a progress bar inside of a status bar, on an MDI form. Option Explicit’*******************************************************************’API’******************************************************************* ‘SetParentPrivate Declare Function SetParent Lib “user32.dll” _   (ByVal hWndChild As Long, _ByVal hWndNewParent As Long) As Long’SendMessagePrivate Declare Function SendMessage Lib “user32.dll” Alias “SendMessageA” _   (ByVal hWnd As Long, _   ByVal wMsg As… Read More »

Add a OnMoving Event to your Forms

With this example, you can have “stuff happen” when a form is moved on the screen. Option Explicit ‘API TypesPublic Type RECT   Left As Long   Top As Long   Right As Long   Bottom As LongEnd Type ‘API ConstantsConst WM_MOVING = 534Const GWL_WNDPROC = (-4) ‘API declarationsPrivate Declare Function SetWindowLong Lib “user32.dll” Alias “SetWindowLongA” (ByVal hWnd As Long, ByVal nindex As Long, ByVal dwnewlong… Read More »

Layered Windows in VB6

Makes a nice layered window effect, with adjustable transparency. Option ExplicitDeclare Function GetWindowLong Lib “user32.dll” Alias “GetWindowLongA” (ByVal hWnd As Long, ByVal nIndex As Long) As LongDeclare Function SetWindowLong Lib “user32.dll” Alias “SetWindowLongA” (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongDeclare Function SetLayeredWindowAttributes Lib “user32.dll” (ByVal hWnd As Long, ByVal crKey As… Read More »

INI File Class

This class module will allow you to easily work with INI files. This will let you store settings and preferences for your program that are persistent between runs. You can download the attachment above, or copy and paste the below chunk of code to a new class module in your project. Option Explicit ‘APIPrivate Declare Function GetPrivateProfileInt Lib… Read More »