Convert image to string

Convert image to base64 encoded string and vice versa. Like Resource.resx file does. Can be used with settings file.

    Private Sub saveImageToSettings()
        My.Settings.imageSettingAsString = getBase64String(PictureBox1.Image)
    End Sub

    Private Sub getImageFromString()
        PictureBox1.Image = getImageFromBase64String(My.Settings.imageSettingAsString)
    End Sub

Continue reading

Using Explorer Form in

Adding directory structure to explorer form to use it like Windows Explorer:

Right click your project in Solution Explorer and click Add > Add New Item | Select Explorer Form from the list and Click ok, [keep default name if you dont know changing it in further code]

When new Form is added to your project, double click it and replace whole code with the following. Result of which will be like this-

Continue reading

Restore minimized window from

    Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal nCmdShow As Int32) As Boolean

    Enum SW As Int32
        Hide = 0
        Normal = 1
        ShowMinimized = 2
        ShowMaximized = 3
        ShowNoActivate = 4
        Show = 5
        Minimize = 6
        ShowMinNoActive = 7
        ShowNA = 8
        Restore = 9
        ShowDefault = 10
        ForceMinimize = 11
        Max = 11
    End Enum

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles Button1.Click

        Dim hWnd As IntPtr = Process.GetProcessById(12345).MainWindowHandle
        ShowWindow(hWnd, SW.Restore)

    End Sub

Flash Taskbar button

Flash Taskbar button when window is inactive or at background. Click button and minimize window to test this sample.

Public Class Form1
    Public Structure FLASHWINFO
        Public cbSize As Int32
        Public hwnd As IntPtr
        Public dwFlags As Int32
        Public uCount As Int32
        Public dwTimeout As Int32
    End Structure

    Private Declare Function FlashWindowEx Lib "user32.dll" (ByRef pfwi As FLASHWINFO) As Int32

    Public Const FLASHW_STOP = 0        ' Stop flashing. The system restores the window to its original state.
    Public Const FLASHW_CAPTION = &H1   ' Flash the window caption.
    Public Const FLASHW_TRAY = &H2      ' Flash the taskbar button.
    Public Const FLASHW_ALL = &H3       ' Flash both the window caption and taskbar button.
    Public Const FLASHW_TIMER = &H4     ' Flash continuously, until the FLASHW_STOP flag is set.
    Public Const FLASHW_TIMERNOFG = &HC ' Flash continuously until the window comes to the foreground.

    Public Sub FlashIcon(ByVal Handle%, ByVal Flags%)
        Dim flash As New FLASHWINFO
        flash.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(flash) '/// size of structure in bytes
        flash.hwnd = Handle '/// Handle to the window to be flashed
        flash.dwFlags = Flags
        flash.dwTimeout = 500 '/// speed of flashes in MilliSeconds ( can be left out )
        FlashWindowEx(flash) '/// flash the window
    End Sub

    Dim WithEvents tmr As New Timer
    Dim count As Integer = 0
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        tmr.Interval = 1000
    End Sub
    Private Sub test(ByVal sender As Object, ByVal e As EventArgs) Handles tmr.Tick
        If count >= 5 Then
            FlashIcon(MyBase.Handle, FLASHW_TRAY + FLASHW_TIMERNOFG)
        End If
        count += 1
    End Sub
End Class

Retrieve Information using domaintools api

Retrieve network information of computer connected to internet, using iptools xml api.

domaintools provides nice XML file with client network information. One can easily access this file to retrieve the information.

Imports System.Xml
Imports System.IO
Imports System.Net

Public Class Form1
    Dim domainTools As New Dictionary(Of String, String)

    Private Sub retrieveInformation()

        Dim xmlDoc As New XmlDocument

        Dim webRequest As WebRequest = webRequest.Create("")
        Dim webResponse As WebResponse = webRequest.GetResponse
        Dim webStream As Stream = webResponse.GetResponseStream


        For Each element As XmlNode In xmlDoc.DocumentElement.ChildNodes
            domainTools.Add(element.Name, element.InnerText)

        'domainTools dictionary now holds all the information
        'Usage :

    End Sub

End Class

Get only Foreground processes

        Dim processes() As Process
        processes = Process.GetProcesses()
        For Each p As Process In processes
            If Not p.MainWindowHandle = 0 Then
                'p is a foreground process
                'do anything with p here.
            End If