Writing Shells - pt1

Submitted on: 1/21/2015 4:01:00 AM
By: Nick Ridley (from psc cd)  
Level: Beginner
User Rating: By 4 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 459
     The first of my tutorials on writting Shells (like explorer) in VB

This article has accompanying files

Writing A Shell

(Part1) By Nick Ridley

Date: 20/11/2001


1- Introduction
2- Getting started
3- Taskbar buttons
4- Next Issue

1 - Introduction

I have stated to write these tutorials to try and get some more people into writing shells in VB. I know that I am not the best shell writer but I do know how to get started in making one and these tutorials are meant to give newbies that boost of info they need so they will start.

Nick Ridley

2- Getting started

Before you even start to make your shell decide on some things first:

1- Will it be free or commercial?
2- Will it be open source?
3- What colour scheme will you use?
4- What versions of window will it be compatible with

Decide on all of these things and then write them down on a bit of paper. Below start a brainstorm of the word SHELL and come up with as much info. Now finalise what you want in light of this info and decide on a name. Write down all this on a bit of paper and stick it to your monitor or something. Get some paper and a pen and keep this handy at all times to write down ideas. You may also need a calculator to do any sums and stuff.

Now you have most the info you will need, now we can start.

You must now:

Create your project
Do your splash screen
Design the place were the task buttons will be

3- The task buttons

Now we will move on to task listing:

I have re written some parts of a .bas file I got of PSC (I think this is made up of Softshell and RepShell) and you must now add this to your project:

NOTE: I did not fully write this, this is a rewritten version of what was in softshell and repshell, although I have re-written some of it

[BEGIN TaskListing.bas]

'I hope this bit encourages you newbies to
'start new shells (use this to make a taskbar)

Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Const LB_ADDSTRING = &H180
Public Const LB_ERR = (-1)

Public Const GW_OWNER = 4
Public Const GWL_EXSTYLE = (-20)

Public Const WS_EX_APPWINDOW = &H40000
Public Const WS_EX_TOOLWINDOW = &H80

Public Declare Function IsZoomed Lib "user32" (ByVal hwnd As Long) As Boolean
Public Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long

Public Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Public Const DI_NORMAL = &H3

Public Declare Function GetClassLong Lib "user32" Alias "GetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Integer) As Long

Public Const WM_GETICON = &H7F
Public Const GCL_HICON = (-14)
Public Const GCL_HICONSM = (-34)
Public Const WM_QUERYDRAGICON = &H37

Public Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long

'This is used to get icons from windows >>>>
Public Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long

Public Function fEnumWindows(lst As ListBox) As Long
With lst
frmTasks.lstNames.Clear ' replace this as neccessary
Call EnumWindows(AddressOf fEnumWindowsCallBack, .hwnd)
fEnumWindows = .ListCount
End With
End Function

Private Function fEnumWindowsCallBack(ByVal hwnd As Long, ByVal lParam As Long) As Long

Dim lExStyle As Long, bHasNoOwner As Boolean, sAdd As String, sCaption As String

If IsWindowVisible(hwnd) Then
bHasNoOwner = (GetWindow(hwnd, GW_OWNER) = 0)
lExStyle = GetWindowLong(hwnd, GWL_EXSTYLE)

If (((lExStyle And WS_EX_TOOLWINDOW) = 0) And bHasNoOwner) Or _
((lExStyle And WS_EX_APPWINDOW) And Not bHasNoOwner) Then
sAdd = hwnd: sCaption = GetCaption(hwnd)
Call SendMessage(lParam, LB_ADDSTRING, 0, ByVal sAdd)
Call SendMessage(frmTasks.lstNames.hwnd, LB_ADDSTRING, 0, ByVal sCaption) ' replace this as neccessary
End If
End If

fEnumWindowsCallBack = True
End Function

Public Function GetCaption(hwnd As Long) As String
Dim mCaption As String, lReturn As Long
mCaption = Space(255)
lReturn = GetWindowText(hwnd, mCaption, 255)
GetCaption = Left(mCaption, lReturn)
End Function

[END TaskListing.bas]

If you are not going to download the sample project you will need to write your own function to use this. In my project i have included a function to do this.

Basically the functions do this:


lst = the list box were the window hWnd's will be held

You will also need to change a few lines (these are marked) to suit your project, You do not need to directly call the rest of the functions.

You may also find this useful to set FG windows and make your taskbar stay on top:

[BEGIN modWindows.bas]

Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Const HWND_BOTTOM = 1
Public Const HWND_NOTOPMOST = -2
Public Const HWND_TOP = 0
Public Const HWND_TOPMOST = -1

Public Const SWP_NOACTIVATE = &H10
Public Const SWP_SHOWWINDOW = &H40

Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Const SW_HIDE = 0
Public Const SW_NORMAL = 1
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10

Public Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Boolean

Public Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long

Public Function WindowPos(frm As Object, setting As Integer)
'Change positions of windows, make top most etc...

Dim i As Integer
Select Case setting
Case 1
Case 2
Case 3
Case 4
End Select

SetWindowPos frm.hwnd, i, frm.Left / 15, _
frm.Top / 15, frm.Width / 15, _

End Function

Public Sub SetFGWindow(ByVal hwnd As Long, Show As Boolean)
If Show Then
If IsIconic(hwnd) Then
ShowWindow hwnd, SW_RESTORE
BringWindowToTop hwnd
End If
ShowWindow hwnd, SW_MINIMIZE
End If
End Sub

[END modWindows.bas]

Now you can either use this info to build your own project or use mine.


This DOES NOT cover everything

4- Next Issue:

In the next issue I plan to describe how to make a start menu (hopefully in more detail than this) describing how to get icons from files and how to make menus appear and disappear. And in further issues i will describe how to make a system tray for example.

I hope you find this useful and PLEASE VOTE and LEAVE COMMENTS. What annoys me is when people read your code and use it but dont vote so please show your appreciation and even if you vote poor every vote counts.

Thanx for reading

Nick Ridley

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net

Other 7 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)

To post feedback, first please login.