I'm sorry to trouble you once again but somebody must know how to get
a list of the desktop icons and their respective positions.
I know that I have to look into shell but I have no idea how to do
it...!
Regards
I've found this bit of vb code but I don't know how to translate it
into C# (Don't know if it works)
Public Class GetIcons
Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000
Public Const OPEN_ALWAYS = 4
Public Const FILE_ATTRIBUTE_ NORMAL = &H80
Public Const SECTION_MAP_WRI TE = &H2
Public Const FILE_MAP_WRITE = SECTION_MAP_WRI TE
'NOT documented in Win32api.txt
Public Const PAGE_READWRITE As Long = &H4
Const LVM_GETTITEMCOU NT& = (&H1000 + 4)
Const LVM_SETITEMPOSI TION& = (&H1000 + 15)
Const LVM_FIRST = &H1000
Const LVM_GETITEMPOSI TION = (LVM_FIRST + 16)
Const LVM_GETITEMTEXT = LVM_FIRST + 45
'damn hell of a lot of declares
'copymemory *3 avoid byval in code - bug? works this way
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMem ory"
_
(ByVal hpvDest As Any, ByVal hpvSource As Any, ByVal cbCopy As
Long)
Private Declare Sub CopyMemoryOne Lib "kernel32" Alias
"RtlMoveMem ory" _
(ByVal hpvDest&, ByVal hpvSource As Any, ByVal cbCopy As Long)
Private Declare Sub CopyMemoryTwo Lib "kernel32" Alias
"RtlMoveMem ory" _
(ByVal hpvDest As Any, ByVal hpvSource&, ByVal cbCopy As Long)
Public Declare Function SendMessage Lib "user32" Alias
"SendMessag eA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long,
ByVal lParam _
As Any) As Long
Declare Function SendMessageByLo ng& Lib "user32" Alias
"SendMessag eA" _
(ByVal hwnd&, ByVal wMsg&, ByVal wParam&, ByVal lParam&)
Private Declare Function FindWindow& Lib "user32" Alias
"FindWindow A" _
(ByVal lpClassName As String, ByVal lpWindowName As String)
Private Declare Function FindWindowEx& Lib "user32" Alias _
"FindWindow ExA" (ByVal hWndParent As Long, ByVal hWndChildAfter _
As Long, ByVal lpClassName As String, ByVal lpWindowName As String)
'declares for printing to the desktop or other window for debug
purposes
Public Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal
_
hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As _
String, ByVal nCount As Long) As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As
Long
Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long,
_
ByVal hdc As Long) As Long
Public Declare Function InvalidateRect Lib "user32" (ByVal hwnd As
Long, _
ByVal lpRect As Any, ByVal bErase As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)
'declares for memory-mapped files
Public Declare Function CreateFile Lib "kernel32" Alias
"CreateFile A" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, ByVal lpSecurityAttri butes As Any, _
ByVal dwCreationDispo sition As Long, ByVal dwFlagsAndAttri butes As
_
Long, ByVal hTemplateFile As Long) As Long
' changed lpFileMappigAtt ributes to Any, makes life much easier
Public Declare Function CreateFileMappi ngTwo Lib "kernel32" Alias _
"CreateFileMapp ingA" (ByVal hFile As Long, ByVal
lpFileMappigAtt ributes _
As Any, ByVal flProtect As Long, ByVal dwMaximumSizeHi gh As Long, _
ByVal dwMaximumSizeLo w As Long, ByVal lpName As String) As Long
Public Declare Function MapViewOfFile Lib "kernel32" (ByVal _
hFileMappingObj ect As Long, ByVal dwDesiredAccess As Long, ByVal _
dwFileOffsetHig h As Long, ByVal dwFileOffsetLow As Long, ByVal _
dwNumberOfBytes ToMap As Long) As Long
Public Declare Function UnmapViewOfFile Lib "kernel32" (ByVal
lpBaseAddress As Any) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject
As Long) As Long
Public Declare Function FlushViewOfFile Lib "kernel32" (ByVal
lpBaseAddress As Long, ByVal dwNumberOfBytes ToFlush As Long) As Long
'type declarations
Public Structure LV_ITEM ' might need this if we ever figure out
Dim mask As Long ' how to retrieve the text
Dim iItem As Long
Dim iSubItem As Long
Dim State As Long
Dim stateMask As Long
Dim pszText As Long
Dim cchTextMax As Long
Dim iImage As Long
Dim lParam As Long ' I think we might need a second
Dim iIndent As Long ' memory mapped file
End Structure
Public Structure POINTAPI
Dim x As Long
Dim y As Long
End Structure
Dim c As POINTAPI
Public IconPosition() As POINTAPI
Public IconPosition2() As POINTAPI
Public TempIconPositio n2 As POINTAPI
'dimension some variables
Dim pNull As Long
Dim MyValue%, MyValue2%
Dim sFileName As String
Dim CurrentDirector y As String
Dim hdesk&, i%
Global icount&
Public Sub FindIcons()
'no error trapping done quick and dirty code
'this is Proof of Concept Code
'a problem for the reader <g>
pNull = 0
hdesk = FindWindow("pro gman", vbNullString)
hdesk = FindWindowEx(hd esk, 0, "shelldll_defvi ew",
vbNullString)
hdesk = FindWindowEx(hd esk, 0, "syslistview32" , vbNullString)
'hdesk is the handle of the Desktop's listview
icount = SendMessageByLo ng(hdesk, LVM_GETTITEMCOU NT, 0, 0&)
'bail if we get a zero count
If icount = 0 Then MsgBox("Error occurred: No icons found", _
vbOKOnly, "PauliesPet ") : Unload(Form1) : End
'tell me how many icons we found
Form1.Text1.Tex t = Str(icount) + " icons detected "
'redimension arrays
ReDim IconPosition(ic ount) As POINTAPI
ReDim IconPosition2(i count) As POINTAPI
'///// create a memory-mapped file /////
CurrentDirector y = App.Path
If Right$(CurrentD irectory, 1) <> "\" Then _
CurrentDirector y = CurrentDirector y + "\"
sFileName = CurrentDirector y + "TEMPPPPP.P PP"
' Open file
hFile = CreateFile(sFil eName, GENERIC_READ Or GENERIC_WRITE, 0, _
ByVal pNull, OPEN_ALWAYS, FILE_ATTRIBUTE_ NORMAL, _
pNull)
' get handle
hFileMap = CreateFileMappi ngTwo(hFile, ByVal pNull, PAGE_READWRITE, _
0, 16, "MyMapping" )
' Get pointer to memory representing file
pFileMap = MapViewOfFile(h FileMap, FILE_MAP_WRITE, 0, 0, 0)
For i = 0 To icount - 1
'lparam is mem-map file Pointer
Call SendMessageByLo ng(hdesk, LVM_GETITEMPOSI TION, i,
pFileMap)
'copy returned to our POINTAPI (c.x,c.y)
CopyMemoryTwo(c , pFileMap, 8)
'show me where the icons are
Form1.List1.Add Item(Str(i + 1) + " x-" + Str(c.x) + " y-" _
+ Str(c.y))
'put value in our arrays
IconPosition(i) = c
'back up array for swapping later
IconPosition2(i ) = c
Next i
'Release resources back to windows
FlushViewOfFile (pFileMap, 8)
UnmapViewOfFile (pFileMap)
CloseHandle(hFi leMap)
CloseHandle(hFi le)
End Sub
Sub RefreshDesktop( )
' refresh the whole desktop , we'll just invalidate everything
xcc% = InvalidateRect( 0, ByVal 0, 0)
End Sub
Sub RefreshIconPosi tions()
For i = 0 To icount - 1
'reset our icon switching array
IconPosition2(i ) = IconPosition(i)
'Set icon postions back to what we found originally
Call SendMessageByLo ng(hdesk, LVM_SETITEMPOSI TION, i, _
CLng(IconPositi on(i).x + IconPosition(i) .y * &H10000))
Next i
End Sub
End Class 1 4495
Hi Henrik,
You did get the 2 links I posted, didn't you? The VB.Net you've posted is
using the Windows API, just like the C++ articles and tutorials I posted. I
also posted a link to the MSDN Windows Shell Programming SDK. You'd be
better off using the C++ articles if you want to use C# to do this.
It's really not that diffidult, if you know what to do. You basically use
interop to do it, with Platform Invoke. Here are a couple of sections of the
online .Net SDK that tell you how, and some examples as well:
Consuming Unmanaged DLL Functions http://msdn.microsoft.com/library/de...lfunctions.asp
Marshalling Data With Platform Invoke http://msdn.microsoft.com/library/de...forminvoke.asp
Platform Invoke Data Types http://msdn.microsoft.com/library/de...edatatypes.asp
Create a Class to Hold DLL Functions http://msdn.microsoft.com/library/de...lfunctions.asp
Creating Prototypes in Managed Code http://msdn.microsoft.com/library/de...anagedcode.asp
Miscellaneous Marshalling Examples http://msdn.microsoft.com/library/de...ingsamples.asp
Platform Invoke Tutorial http://msdn.microsoft.com/library/de...ketutorial.asp
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
We got a sick zebra a hat,
you ultimate tuna.
"Henrik" <do******@hotma il.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com... I'm sorry to trouble you once again but somebody must know how to get a list of the desktop icons and their respective positions.
I know that I have to look into shell but I have no idea how to do it...!
Regards
I've found this bit of vb code but I don't know how to translate it into C# (Don't know if it works)
Public Class GetIcons
Public Const GENERIC_READ = &H80000000 Public Const GENERIC_WRITE = &H40000000 Public Const OPEN_ALWAYS = 4 Public Const FILE_ATTRIBUTE_ NORMAL = &H80 Public Const SECTION_MAP_WRI TE = &H2 Public Const FILE_MAP_WRITE = SECTION_MAP_WRI TE
'NOT documented in Win32api.txt Public Const PAGE_READWRITE As Long = &H4
Const LVM_GETTITEMCOU NT& = (&H1000 + 4) Const LVM_SETITEMPOSI TION& = (&H1000 + 15) Const LVM_FIRST = &H1000 Const LVM_GETITEMPOSI TION = (LVM_FIRST + 16) Const LVM_GETITEMTEXT = LVM_FIRST + 45
'damn hell of a lot of declares 'copymemory *3 avoid byval in code - bug? works this way Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMem ory" _ (ByVal hpvDest As Any, ByVal hpvSource As Any, ByVal cbCopy As Long) Private Declare Sub CopyMemoryOne Lib "kernel32" Alias "RtlMoveMem ory" _ (ByVal hpvDest&, ByVal hpvSource As Any, ByVal cbCopy As Long) Private Declare Sub CopyMemoryTwo Lib "kernel32" Alias "RtlMoveMem ory" _ (ByVal hpvDest As Any, ByVal hpvSource&, ByVal cbCopy As Long)
Public Declare Function SendMessage Lib "user32" Alias "SendMessag eA" _ (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam _ As Any) As Long Declare Function SendMessageByLo ng& Lib "user32" Alias "SendMessag eA" _ (ByVal hwnd&, ByVal wMsg&, ByVal wParam&, ByVal lParam&)
Private Declare Function FindWindow& Lib "user32" Alias "FindWindow A" _ (ByVal lpClassName As String, ByVal lpWindowName As String) Private Declare Function FindWindowEx& Lib "user32" Alias _ "FindWindow ExA" (ByVal hWndParent As Long, ByVal hWndChildAfter _ As Long, ByVal lpClassName As String, ByVal lpWindowName As String)
'declares for printing to the desktop or other window for debug purposes Public Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal _ hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As _ String, ByVal nCount As Long) As Long Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, _ ByVal hdc As Long) As Long Public Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, _ ByVal lpRect As Any, ByVal bErase As Long) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'declares for memory-mapped files Public Declare Function CreateFile Lib "kernel32" Alias "CreateFile A" _ (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _ ByVal dwShareMode As Long, ByVal lpSecurityAttri butes As Any, _ ByVal dwCreationDispo sition As Long, ByVal dwFlagsAndAttri butes As _ Long, ByVal hTemplateFile As Long) As Long ' changed lpFileMappigAtt ributes to Any, makes life much easier Public Declare Function CreateFileMappi ngTwo Lib "kernel32" Alias _ "CreateFileMapp ingA" (ByVal hFile As Long, ByVal lpFileMappigAtt ributes _ As Any, ByVal flProtect As Long, ByVal dwMaximumSizeHi gh As Long, _ ByVal dwMaximumSizeLo w As Long, ByVal lpName As String) As Long Public Declare Function MapViewOfFile Lib "kernel32" (ByVal _ hFileMappingObj ect As Long, ByVal dwDesiredAccess As Long, ByVal _ dwFileOffsetHig h As Long, ByVal dwFileOffsetLow As Long, ByVal _ dwNumberOfBytes ToMap As Long) As Long Public Declare Function UnmapViewOfFile Lib "kernel32" (ByVal lpBaseAddress As Any) As Long Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Public Declare Function FlushViewOfFile Lib "kernel32" (ByVal lpBaseAddress As Long, ByVal dwNumberOfBytes ToFlush As Long) As Long
'type declarations Public Structure LV_ITEM ' might need this if we ever figure out Dim mask As Long ' how to retrieve the text Dim iItem As Long Dim iSubItem As Long Dim State As Long Dim stateMask As Long Dim pszText As Long Dim cchTextMax As Long Dim iImage As Long Dim lParam As Long ' I think we might need a second Dim iIndent As Long ' memory mapped file End Structure
Public Structure POINTAPI Dim x As Long Dim y As Long End Structure
Dim c As POINTAPI Public IconPosition() As POINTAPI Public IconPosition2() As POINTAPI Public TempIconPositio n2 As POINTAPI
'dimension some variables Dim pNull As Long Dim MyValue%, MyValue2% Dim sFileName As String Dim CurrentDirector y As String Dim hdesk&, i% Global icount& Public Sub FindIcons()
'no error trapping done quick and dirty code 'this is Proof of Concept Code 'a problem for the reader <g> pNull = 0 hdesk = FindWindow("pro gman", vbNullString) hdesk = FindWindowEx(hd esk, 0, "shelldll_defvi ew", vbNullString) hdesk = FindWindowEx(hd esk, 0, "syslistview32" , vbNullString) 'hdesk is the handle of the Desktop's listview icount = SendMessageByLo ng(hdesk, LVM_GETTITEMCOU NT, 0, 0&) 'bail if we get a zero count If icount = 0 Then MsgBox("Error occurred: No icons found", _ vbOKOnly, "PauliesPet ") : Unload(Form1) : End 'tell me how many icons we found Form1.Text1.Tex t = Str(icount) + " icons detected " 'redimension arrays ReDim IconPosition(ic ount) As POINTAPI ReDim IconPosition2(i count) As POINTAPI
'///// create a memory-mapped file /////
CurrentDirector y = App.Path If Right$(CurrentD irectory, 1) <> "\" Then _ CurrentDirector y = CurrentDirector y + "\"
sFileName = CurrentDirector y + "TEMPPPPP.P PP" ' Open file hFile = CreateFile(sFil eName, GENERIC_READ Or GENERIC_WRITE, 0, _ ByVal pNull, OPEN_ALWAYS, FILE_ATTRIBUTE_ NORMAL, _ pNull) ' get handle hFileMap = CreateFileMappi ngTwo(hFile, ByVal pNull, PAGE_READWRITE, _ 0, 16, "MyMapping" ) ' Get pointer to memory representing file pFileMap = MapViewOfFile(h FileMap, FILE_MAP_WRITE, 0, 0, 0)
For i = 0 To icount - 1 'lparam is mem-map file Pointer Call SendMessageByLo ng(hdesk, LVM_GETITEMPOSI TION, i, pFileMap) 'copy returned to our POINTAPI (c.x,c.y) CopyMemoryTwo(c , pFileMap, 8) 'show me where the icons are Form1.List1.Add Item(Str(i + 1) + " x-" + Str(c.x) + " y-" _ + Str(c.y)) 'put value in our arrays IconPosition(i) = c 'back up array for swapping later IconPosition2(i ) = c Next i
'Release resources back to windows FlushViewOfFile (pFileMap, 8) UnmapViewOfFile (pFileMap) CloseHandle(hFi leMap) CloseHandle(hFi le)
End Sub
Sub RefreshDesktop( )
' refresh the whole desktop , we'll just invalidate everything xcc% = InvalidateRect( 0, ByVal 0, 0)
End Sub
Sub RefreshIconPosi tions()
For i = 0 To icount - 1 'reset our icon switching array IconPosition2(i ) = IconPosition(i) 'Set icon postions back to what we found originally Call SendMessageByLo ng(hdesk, LVM_SETITEMPOSI TION, i, _ CLng(IconPositi on(i).x + IconPosition(i) .y * &H10000)) Next i
End Sub End Class This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Vigneshwar Pilli via DotNetMonster.com |
last post by:
string connectionString1 = "server=(local); user=sa;password=sa;
database=sonic";
System.Data.SqlClient.SqlConnection dbConnection1 = new
System.Data.SqlClient.SqlConnection(connectionString1);
System.Data.SqlClient.SqlCommand dbCommand1 = new
System.Data.SqlClient.SqlCommand();
|
by: Blaine |
last post by:
Does anyone know how I can hide a form from the TaskManager?
I've set the ShowInTaskbar to False, but when using Alt-TAB to switch
between applications, it appears as a blank icon. I can set it as a
SizableToolWindow, but then I no longer have the minimize button on the
caption.
Is there a way to mimic a (FormBorder) sizable tool window (so it doesn't
appear in the tasklist) and still show the Min, Max and Close control
buttons? (Or...
|
by: Henrik |
last post by:
I need to get a list of clickable objects on the desktop and their
positions.
I have written a small program in C# and by using the Win32 function:
WindowFromPoint -function I get a handle to the desktop but now I'm
stuck.
For those who need to see the code -look below
IntPtr hWnd = Win32.WindowFromPoint(Cursor.Position);
With the handle I can get alot of cool information such as: Caption,
|
by: Zubair.NET! |
last post by:
Hi, I am in a situation where I need to upload different File Types in
an application, and based on their MIME-Type, I need to show their
respective icons.
The question is: Does anyone know how to read Windows Icons (.ico) from
ASP.NET based on their MIME-Type and convert them to (.gif)
I need a urgent answer to this.
Thanks in anticipation!
|
by: Daz |
last post by:
Hi everyone.
I am trying to make a program which handles about 70 different objects,
of the same type. The properties are as follows:
std::string ItemName
int ItemType
int Calories
int Weight
int Density
| |
by: Jon Slaughter |
last post by:
I'm trying to create a windows explorer like app and the problem I'm having
is getting the proper icon for the folders and items.
In windows explorer there are many different icons and most seem to be in
the shell32.dll. The problem is that there also seems to be custom icons
that are installed by applications.
For example, "My Music" In My Documents has an icon that is different from
the normal folders. I have installed an application...
|
by: =?Utf-8?B?QnJpYW5L?= |
last post by:
I use Xp home SP2.
I recently scanned a document and saved to desktop. as i did the save all
the desktop icons disappeared,including the scanned dociment.
The all reside in the desktop folder inc' the scanned doc. My
screen(desktop) shows XP's lovely sky and countyside and nothing else. The
screen is no longer interactive. I have no icons, mouse click left or right
or both does nothing.
|
by: cal |
last post by:
Hi group,
Wich one is the class to handle desktop icons?
I want to modify for example the file path the Icon points to.
of course, its the path of the file u open when u doubleclick the icon.
Are there managed classes available ?, thanks, Carlos.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |