Nov 30th, 2011, 10:17 PM
#1
Thread Starter
Lively Member
Dock Bar
Basically I want to make a dock bar that is on the desktop, I want to be able to drag files into it and when the files are dragged in there icon appears and when you click the icon it opens the file, Thanks
Nov 30th, 2011, 10:37 PM
#2
Re: Dock Bar
here's the docked bar. i'll let you work out the dragdrop part:
Attached Files
Coding Examples:
Features:
Online Games:
Compiled Games:
Nov 30th, 2011, 11:20 PM
#3
Thread Starter
Lively Member
Re: Dock Bar
Originally Posted by
.paul.
here's the docked bar. i'll let you work out the dragdrop part:
I wouldn't know where to start :L *Hint Hint*
Dec 1st, 2011, 12:48 AM
#4
Re: Dock Bar
ok.
vb Code:
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices
Public Class mainform
Private Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
Private Structure APPBARDATA
Public cbSize As Integer
Public hWnd As IntPtr
Public uCallbackMessage As Integer
Public uEdge As Integer
Public rc As RECT
Public lParam As IntPtr
End Structure
Private Enum ABMsg As Integer
ABM_NEW = 0
ABM_REMOVE = 1
ABM_QUERYPOS = 2
ABM_SETPOS = 3
ABM_GETSTATE = 4
ABM_GETTASKBARPOS = 5
ABM_ACTIVATE = 6
ABM_GETAUTOHIDEBAR = 7
ABM_SETAUTOHIDEBAR = 8
ABM_WINDOWPOSCHANGED = 9
ABM_SETSTATE = 10
End Enum
Private Enum ABNotify As Integer
ABN_STATECHANGE = 0
ABN_POSCHANGED
ABN_FULLSCREENAPP
ABN_WINDOWARRANGE
End Enum
Private Enum ABEdge As Integer
ABE_LEFT = 0
ABE_TOP = 1
ABE_RIGHT = 2
ABE_BOTTOM = 3
End Enum
Private fBarRegistered As Boolean = False
Private Declare Function SHAppBarMessage Lib "shell32.dll" Alias "SHAppBarMessage" _
(ByVal dwMessage As Integer, <MarshalAs(UnmanagedType.Struct)> ByRef pData As _
APPBARDATA) As Integer
Private Declare Function GetSystemMetrics Lib "user32" Alias "GetSystemMetrics" _
(ByVal nIndex As Integer) As Integer
Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Integer, _
ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, _
ByVal bRepaint As Integer) As Integer
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" _
(ByVal lpString As String) As Integer
Private uCallBack As Integer
Dim icons As Integer = 0
Private Sub mainform_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim files() As String = DirectCast(e.Data.GetData(DataFormats.FileDrop, False), String())
For Each file As String In files
Dim pb As New PictureBox
pb.Size = New Size(32, 32)
pb.Location = New Point(12 + (icons * 44), 12)
pb.Tag = file
Dim icon As Icon = icon.ExtractAssociatedIcon(file)
pb.Image = icon.ToBitmap
pb.Cursor = Cursors.Hand
AddHandler pb.DoubleClick, AddressOf pb_DoubleClick
ToolTip1.SetToolTip(pb, file)
Me.Controls.Add(pb)
icons += 1
Next
End If
End Sub
Private Sub pb_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Process.Start(DirectCast(sender, PictureBox).Tag.ToString)
End Sub
Private Sub mainform_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragOver
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub mainform_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
RegisterBar()
End Sub
Private Sub appBar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(1024, 56)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
RegisterBar()
Me.Invalidate()
End Sub
Private Sub mainform_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawLine(New Pen(Color.White, 3), 0, 0, Me.Width, 0)
e.Graphics.DrawLine(New Pen(Color.White, 3), 0, 0, 0, Me.Height)
e.Graphics.DrawLine(New Pen(Color.Black, 3), 0, Me.Height - 3, Me.Width, Me.Height - 3)
e.Graphics.DrawLine(New Pen(Color.Black, 3), Me.Width - 3, 0, Me.Width - 3, Me.Height)
End Sub
Private Sub RegisterBar()
Dim abd As New APPBARDATA
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = Me.Handle
If Not fBarRegistered Then
uCallBack = RegisterWindowMessage("AppBarMessage")
abd.uCallbackMessage = uCallBack
Dim ret As Integer = SHAppBarMessage(CType(ABMsg.ABM_NEW, Integer), abd)
fBarRegistered = True
ABSetPos()
Else
SHAppBarMessage(CType(ABMsg.ABM_REMOVE, Integer), abd)
fBarRegistered = False
End If
End Sub
Private Sub ABSetPos()
Dim abd As New APPBARDATA()
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = Me.Handle
abd.uEdge = CInt(ABEdge.ABE_BOTTOM)
If abd.uEdge = CInt(ABEdge.ABE_LEFT) OrElse abd.uEdge = CInt(ABEdge.ABE_RIGHT) Then
abd.rc.top = 0
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
If abd.uEdge = CInt(ABEdge.ABE_LEFT) Then
abd.rc.left = 0
abd.rc.right = Size.Width
Else
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
abd.rc.left = abd.rc.right - Size.Width
End If
Else
abd.rc.left = 0
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
If abd.uEdge = CInt(ABEdge.ABE_TOP) Then
abd.rc.top = 0
abd.rc.bottom = Size.Height
Else
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
abd.rc.top = abd.rc.bottom - Size.Height
End If
End If
' Query the system for an approved size and position.
SHAppBarMessage(CInt(ABMsg.ABM_QUERYPOS), abd)
' Adjust the rectangle, depending on the edge to which the
' appbar is anchored.
Select Case abd.uEdge
Case CInt(ABEdge.ABE_LEFT)
abd.rc.right = abd.rc.left + Size.Width
Exit Select
Case CInt(ABEdge.ABE_RIGHT)
abd.rc.left = abd.rc.right - Size.Width
Exit Select
Case CInt(ABEdge.ABE_TOP)
abd.rc.bottom = abd.rc.top + Size.Height
Exit Select
Case CInt(ABEdge.ABE_BOTTOM)
abd.rc.top = abd.rc.bottom - Size.Height
Exit Select
End Select
' Pass the final bounding rectangle to the system.
SHAppBarMessage(CInt(ABMsg.ABM_SETPOS), abd)
' Move and size the appbar so that it conforms to the
' bounding rectangle passed to the system.
MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, True)
End Sub
Protected Overloads Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = uCallBack Then
Select Case m.WParam.ToInt32()
Case CInt(ABNotify.ABN_POSCHANGED)
ABSetPos()
Exit Select
End Select
End If
MyBase.WndProc(m)
End Sub
Protected Overloads Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style And (Not 12582912)
' WS_CAPTION
cp.Style = cp.Style And (Not 8388608)
' WS_BORDER
cp.ExStyle = 128 Or 8
' WS_EX_TOOLWINDOW | WS_EX_TOPMOST
Return cp
End Get
End Property
End Class
Coding Examples:
Features:
Online Games:
Compiled Games:
Dec 1st, 2011, 01:14 AM
#5
Thread Starter
Lively Member
Re: Dock Bar
Originally Posted by
.paul.
ok.
vb Code:
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices
Public Class mainform
Private Structure RECT
Public left As Integer
Public top As Integer
Public right As Integer
Public bottom As Integer
End Structure
Private Structure APPBARDATA
Public cbSize As Integer
Public hWnd As IntPtr
Public uCallbackMessage As Integer
Public uEdge As Integer
Public rc As RECT
Public lParam As IntPtr
End Structure
Private Enum ABMsg As Integer
ABM_NEW = 0
ABM_REMOVE = 1
ABM_QUERYPOS = 2
ABM_SETPOS = 3
ABM_GETSTATE = 4
ABM_GETTASKBARPOS = 5
ABM_ACTIVATE = 6
ABM_GETAUTOHIDEBAR = 7
ABM_SETAUTOHIDEBAR = 8
ABM_WINDOWPOSCHANGED = 9
ABM_SETSTATE = 10
End Enum
Private Enum ABNotify As Integer
ABN_STATECHANGE = 0
ABN_POSCHANGED
ABN_FULLSCREENAPP
ABN_WINDOWARRANGE
End Enum
Private Enum ABEdge As Integer
ABE_LEFT = 0
ABE_TOP = 1
ABE_RIGHT = 2
ABE_BOTTOM = 3
End Enum
Private fBarRegistered As Boolean = False
Private Declare Function SHAppBarMessage Lib "shell32.dll" Alias "SHAppBarMessage" _
(ByVal dwMessage As Integer, <MarshalAs(UnmanagedType.Struct)> ByRef pData As _
APPBARDATA) As Integer
Private Declare Function GetSystemMetrics Lib "user32" Alias "GetSystemMetrics" _
(ByVal nIndex As Integer) As Integer
Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Integer, _
ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, _
ByVal bRepaint As Integer) As Integer
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" _
(ByVal lpString As String) As Integer
Private uCallBack As Integer
Dim icons As Integer = 0
Private Sub mainform_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim files() As String = DirectCast(e.Data.GetData(DataFormats.FileDrop, False), String())
For Each file As String In files
Dim pb As New PictureBox
pb.Size = New Size(32, 32)
pb.Location = New Point(12 + (icons * 44), 12)
pb.Tag = file
Dim icon As Icon = icon.ExtractAssociatedIcon(file)
pb.Image = icon.ToBitmap
pb.Cursor = Cursors.Hand
AddHandler pb.DoubleClick, AddressOf pb_DoubleClick
ToolTip1.SetToolTip(pb, file)
Me.Controls.Add(pb)
icons += 1
Next
End If
End Sub
Private Sub pb_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Process.Start(DirectCast(sender, PictureBox).Tag.ToString)
End Sub
Private Sub mainform_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragOver
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub mainform_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
RegisterBar()
End Sub
Private Sub appBar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(1024, 56)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
RegisterBar()
Me.Invalidate()
End Sub
Private Sub mainform_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawLine(New Pen(Color.White, 3), 0, 0, Me.Width, 0)
e.Graphics.DrawLine(New Pen(Color.White, 3), 0, 0, 0, Me.Height)
e.Graphics.DrawLine(New Pen(Color.Black, 3), 0, Me.Height - 3, Me.Width, Me.Height - 3)
e.Graphics.DrawLine(New Pen(Color.Black, 3), Me.Width - 3, 0, Me.Width - 3, Me.Height)
End Sub
Private Sub RegisterBar()
Dim abd As New APPBARDATA
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = Me.Handle
If Not fBarRegistered Then
uCallBack = RegisterWindowMessage("AppBarMessage")
abd.uCallbackMessage = uCallBack
Dim ret As Integer = SHAppBarMessage(CType(ABMsg.ABM_NEW, Integer), abd)
fBarRegistered = True
ABSetPos()
Else
SHAppBarMessage(CType(ABMsg.ABM_REMOVE, Integer), abd)
fBarRegistered = False
End If
End Sub
Private Sub ABSetPos()
Dim abd As New APPBARDATA()
abd.cbSize = Marshal.SizeOf(abd)
abd.hWnd = Me.Handle
abd.uEdge = CInt(ABEdge.ABE_BOTTOM)
If abd.uEdge = CInt(ABEdge.ABE_LEFT) OrElse abd.uEdge = CInt(ABEdge.ABE_RIGHT) Then
abd.rc.top = 0
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
If abd.uEdge = CInt(ABEdge.ABE_LEFT) Then
abd.rc.left = 0
abd.rc.right = Size.Width
Else
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
abd.rc.left = abd.rc.right - Size.Width
End If
Else
abd.rc.left = 0
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
If abd.uEdge = CInt(ABEdge.ABE_TOP) Then
abd.rc.top = 0
abd.rc.bottom = Size.Height
Else
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
abd.rc.top = abd.rc.bottom - Size.Height
End If
End If
' Query the system for an approved size and position.
SHAppBarMessage(CInt(ABMsg.ABM_QUERYPOS), abd)
' Adjust the rectangle, depending on the edge to which the
' appbar is anchored.
Select Case abd.uEdge
Case CInt(ABEdge.ABE_LEFT)
abd.rc.right = abd.rc.left + Size.Width
Exit Select
Case CInt(ABEdge.ABE_RIGHT)
abd.rc.left = abd.rc.right - Size.Width
Exit Select
Case CInt(ABEdge.ABE_TOP)
abd.rc.bottom = abd.rc.top + Size.Height
Exit Select
Case CInt(ABEdge.ABE_BOTTOM)
abd.rc.top = abd.rc.bottom - Size.Height
Exit Select
End Select
' Pass the final bounding rectangle to the system.
SHAppBarMessage(CInt(ABMsg.ABM_SETPOS), abd)
' Move and size the appbar so that it conforms to the
' bounding rectangle passed to the system.
MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, True)
End Sub
Protected Overloads Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = uCallBack Then
Select Case m.WParam.ToInt32()
Case CInt(ABNotify.ABN_POSCHANGED)
ABSetPos()
Exit Select
End Select
End If
MyBase.WndProc(m)
End Sub
Protected Overloads Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style And (Not 12582912)
' WS_CAPTION
cp.Style = cp.Style And (Not 8388608)
' WS_BORDER
cp.ExStyle = 128 Or 8
' WS_EX_TOOLWINDOW | WS_EX_TOPMOST
Return cp
End Get
End Property
End Class
Amazing. Thank you so much!
Dec 1st, 2011, 01:24 AM
#6
Re: Dock Bar
if you want to know what changes i made:
set mainForm.allowdrop = true handled mainForm_DragOver + mainForm_DragDrop in the dragover event it only shows dragging allowed for files in dragdrop, if dragged data is file(s), it creates a new picturebox for each file + sets the appropriate properties (size, location, tag, image, cursor), extracting the associated icon for image + adds a handler for doubleclick in the pb_doubleclick event it runs the file in it's default editor/viewer
Coding Examples:
Features:
Online Games:
Compiled Games:
Dec 1st, 2011, 10:59 PM
#7
Thread Starter
Lively Member
Re: Dock Bar
Originally Posted by
.paul.
if you want to know what changes i made:
set mainForm.allowdrop = true handled mainForm_DragOver + mainForm_DragDrop in the dragover event it only shows dragging allowed for files in dragdrop, if dragged data is file(s), it creates a new picturebox for each file + sets the appropriate properties (size, location, tag, image, cursor), extracting the associated icon for image + adds a handler for doubleclick in the pb_doubleclick event it runs the file in it's default editor/viewer
What do you mean what changes you made?
Dec 1st, 2011, 11:15 PM
#8
Re: Dock Bar
Originally Posted by
_TANK_
What do you mean what changes you made?
the differences between the zipped project in post#2 + the code in post#4
i forgot to mention i changed the docking from right edge to bottom edge too...
Coding Examples:
Features:
Online Games:
Compiled Games:
Dec 2nd, 2011, 12:16 AM
#9
Thread Starter
Lively Member
Re: Dock Bar
Originally Posted by
.paul.
the differences between the zipped project in post#2 + the code in post#4
i forgot to mention i changed the docking from right edge to bottom edge too...
So I download your docked bar and in the code put your code?
Dec 2nd, 2011, 12:22 AM
#10
Re: Dock Bar
Originally Posted by
_TANK_
So I download your docked bar and in the code put your code?
yep. that's about it.
Coding Examples:
Features:
Online Games:
Compiled Games:
Dec 4th, 2011, 01:41 AM
#11
Thread Starter
Lively Member
Re: Dock Bar
Originally Posted by
.paul.
yep. that's about it.
When I try dragging a file into it it gives me the (\) Cursor Image thing. Why is this happening?
Dec 4th, 2011, 05:37 AM
#12
Re: Dock Bar
you mean a file from explorer?
you're not trying to drag an open application to it?
Coding Examples:
Features:
Online Games:
Compiled Games:
Dec 4th, 2011, 06:15 AM
#13
Re: Dock Bar
did you set mainForm .AllowDrop = true in your properties window?
Coding Examples:
Features:
Online Games:
Compiled Games:
Dec 4th, 2011, 12:43 PM
#14
Thread Starter
Lively Member
Re: Dock Bar
Originally Posted by
.paul.
did you set mainForm .AllowDrop = true in your properties window?
Nope >_< I feel so stupid. Thanks
Also how can I change the length to say 500 pixels but each time a new file is dragged in the bar gets wider?
Dec 4th, 2011, 02:02 PM
#15
Thread Starter
Lively Member
Re: Dock Bar
Originally Posted by
.paul.
did you set mainForm .AllowDrop = true in your properties window?
How can I make the program remember the programs over restart?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width