Search Tools Links Login

Writing Shells - pt1


The first of my tutorials on writting Shells (like explorer) in VB

Original Author: Nick Ridley

Code

Writing A Shell


(Part1) By Nick Ridley


Date: 20/11/2001


Contents:


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_FINDSTRINGEXACT = &H1A2

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

.Clear

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)color="#008040"> ' 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:


fEnumWindows


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_SHOWMINIMIZED = 2

Public Const SW_SHOWMAXIMIZED = 3

Public Const SW_SHOWNOACTIVATE = 4

Public Const SW_SHOW = 5

Public Const SW_MINIMIZE = 6

Public Const SW_SHOWMINNOACTIVE = 7

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

i = HWND_TOPMOST

Case 2

i = HWND_TOP

Case 3

i = HWND_NOTOPMOST

Case 4

i = HWND_BOTTOM

End Select



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

frm.Top / 15, frm.Width / 15, _

frm.Height / 15, SWP_SHOWWINDOW Or SWP_NOACTIVATE



End Function



Public Sub SetFGWindow(ByVal hwnd As Long, Show As Boolean)

If Show Then

If IsIconic(hwnd) Then

ShowWindow hwnd, SW_RESTORE

Else

BringWindowToTop hwnd

End If

Else

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.


I HIGHLY RECOMEND YOU DOWNLOAD MY SAMPLE


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


http://www.spyderhackers.co.uk


http://www.spyderhackers.com


nick@spyderhackers.com


About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 79 times

Categories

Visual Basic 6

Attachments

Writting_S3629811202001.zip
Posted: 9/3/2020 3:45:00 PM
Size: 5,110 bytes


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.