Solved

How to use the API:SHChangeNotify?

Posted on 2001-07-14
10
2,962 Views
Last Modified: 2008-03-17
The MSDN says:
SHChangeNotify


Notifies the system of an event that an application has performed. An application should use this function if it performs an action that may affect the Shell.

VOID SHChangeNotify(
    LONG wEventId,
    UINT uFlags,
    LPCVOID dwItem1,
    LPCVOID dwItem2
);

Parameters
wEventId
Describes the event that has occurred. Typically, only one event is specified at a time. If more than one event is specified, the values contained in the dwItem1 and dwItem2 parameters must be the same, respectively, for all specified events. This parameter can be one or more of the following values: SHCNE_ALLEVENTS  All events have occurred.  
SHCNE_ASSOCCHANGED  A file t...


But who can give me a example?
I want to Notify the system systemimage updated,but I don't know what can we set the value of dwItem1 and dwItem2.
0
Comment
Question by:MonkeyLin
10 Comments
 
LVL 20

Accepted Solution

by:
hes earned 100 total points
ID: 6281866
0
 

Author Comment

by:MonkeyLin
ID: 6282034
Thank you,hes.
I have seen the example before,but I still can't understand it.
0
 
LVL 5

Expert Comment

by:gwgaw
ID: 6282521
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6282692
In vb, that function looks so:

Declare Sub SHChangeNotify Lib "shell32" _
                        (ByVal wEventId As SHCN_EventIDs, _
                        ByVal uFlags As , _
                        ByVal dwItem1 As Long, _
                        ByVal dwItem2 As Long)

You need two structs (types for us) to pass the first two parameters:
Public Enum SHCN_EventIDs
  SHCNE_RENAMEITEM = &H1      ' (D) A nonfolder item has been renamed.
  SHCNE_CREATE = &H2                ' (D) A nonfolder item has been created.
  SHCNE_DELETE = &H4                ' (D) A nonfolder item has been deleted.
  SHCNE_MKDIR = &H8                  ' (D) A folder item has been created.
  SHCNE_RMDIR = &H10                ' (D) A folder item has been removed.
  SHCNE_MEDIAINSERTED = &H20     ' (G) Storage media has been inserted into a drive.
  SHCNE_MEDIAREMOVED = &H40      ' (G) Storage media has been removed from a drive.
  SHCNE_DRIVEREMOVED = &H80      ' (G) A drive has been removed.
  SHCNE_DRIVEADD = &H100              ' (G) A drive has been added.
  SHCNE_NETSHARE = &H200             ' A folder on the local computer is being shared via the network.
  SHCNE_NETUNSHARE = &H400        ' A folder on the local computer is no longer being shared via the network.
  SHCNE_ATTRIBUTES = &H800           ' (D) The attributes of an item or folder have changed.
  SHCNE_UPDATEDIR = &H1000          ' (D) The contents of an existing folder have changed, but the folder still exists and has not been renamed.
  SHCNE_UPDATEITEM = &H2000                  ' (D) An existing nonfolder item has changed, but the item still exists and has not been renamed.
  SHCNE_SERVERDISCONNECT = &H4000   ' The computer has disconnected from a server.
  SHCNE_UPDATEIMAGE = &H8000&              ' (G) An image in the system image list has changed.
  SHCNE_DRIVEADDGUI = &H10000               ' (G) A drive has been added and the shell should create a new window for the drive.
  SHCNE_RENAMEFOLDER = &H20000          ' (D) The name of a folder has changed.
  SHCNE_FREESPACE = &H40000                   ' (G) The amount of free space on a drive has changed.

#If (WIN32_IE >= &H400) Then
  ' (G) SHCNE_EXTENDED_EVENT:  the extended event is identified in dwItem1,
  ' packed in LPITEMIDLIST format (same as SHCNF_DWORD packing).
  '
  ' Unlike the standard events, the extended events are ORDINALs, so we
  ' don't run out of bits.  Extended events follow the SHCNEE_* naming
  ' convention.
  '
  ' The dwItem2 parameter varies according to the extended event.
  SHCNE_EXTENDED_EVENT = &H4000000
#End If     ' WIN32_IE >= &H0400

  SHCNE_ASSOCCHANGED = &H8000000       ' (G) A file type association has changed.

  SHCNE_DISKEVENTS = &H2381F                  ' Specifies a combination of all of the disk event identifiers. (D)
  SHCNE_GLOBALEVENTS = &HC0581E0        ' Specifies a combination of all of the global event identifiers. (G)
  SHCNE_ALLEVENTS = &H7FFFFFFF
  SHCNE_INTERRUPT = &H80000000              ' The specified event occurred as a result of a system interrupt.
                                                                            ' It is stripped out before the clients of SHCNNotify_ see it.
End Enum

' Notification flags

' uFlags & SHCNF_TYPE is an ID which indicates what dwItem1 and dwItem2 mean
Public Enum SHCN_ItemFlags
  SHCNF_IDLIST = &H0                ' LPITEMIDLIST
  SHCNF_PATHA = &H1               ' path name
  SHCNF_PRINTERA = &H2         ' printer friendly name
  SHCNF_DWORD = &H3             ' DWORD
  SHCNF_PATHW = &H5              ' path name
  SHCNF_PRINTERW = &H6        ' printer friendly name
  SHCNF_TYPE = &HFF
  ' Flushes the system event buffer. The function does not return until the system is
  ' finished processing the given event.
  SHCNF_FLUSH = &H1000
  ' Flushes the system event buffer. The function returns immediately regardless of
  ' whether the system is finished processing the given event.
  SHCNF_FLUSHNOWAIT = &H2000

#If UNICODE Then
  SHCNF_PATH = SHCNF_PATHW
  SHCNF_PRINTER = SHCNF_PRINTERW
#Else
  SHCNF_PATH = SHCNF_PATHA
  SHCNF_PRINTER = SHCNF_PRINTERA
#End If

End Enum

The code was extracted from http://www.mvps.org/btmtz/shnotify/ as hes commented.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6282695
By the way, it the zip file that comes with that article there is usage and explanation of this function.
Good Luck.
0
 

Author Comment

by:MonkeyLin
ID: 6282832
I want to know, in this case what is the value of dwItem1 and dwItem2:SHChangeNotify SHCNE_UPDATEDIR,SHCNF_PATH(the path is "d:\1"),...
0
 

Author Comment

by:MonkeyLin
ID: 6282864
Is that right?Thank you!
SHChangeNotify SHCNE_UPDATEIMAGE, SHCNF_DWORD, -1, Null
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6284154
It could be, i didn't have the time to read and understand that article.
Anyway, i think that using vbNull instead of Null would be better for VB runtime
0
 

Expert Comment

by:roylow
ID: 6633656
Urgent Comment

I am trying to use SHChangeNotify to refresh a custom folder icon programmatically after I have made the necessary changes to desktop.ini. The alternative is:
"Select folder in Explorer and press F5" which works but is inconvenient and inelegant.

I have tried Richie Simonetti's answer without success.

Can anyone help me, I have lots of points!!!

The code for PCMag's "folders" utility which works brilliantly in doing this is written in Pascal and the three lines which are crucial are:


SHChangeNotify(SHCNE_ATTRIBUTES, SHCNF_PATH OR SHCNF_FLUSH, pszPath, nil);
SHChangeNotify(SHCNE_UPDATEIMAGE, SHCNF_DWORD, Pointer(SFI.iIcon), nil);
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST , nil, nil);

The variable pszpath seems to be a pointer to a null terminated string and is a Long.
I think I need to use a "PIDL" value for this which indicates my folder such as the value returned by:
SHGetSpecialFolderLocation
Unfortunately, there does not appear to be an equivalent for "Non-Special" folders.

The variable Pointer(SFI.iIcon) looks to be the same as psfib.iIcon obtained from a call such as
    Finfo = SHGetFileInfo(MyFolder, dwFileAttributes, psfib, cbFileInfo, uFlags) where psfib is declared As SHFILEINFOBYTE

The third line seems ok after replacing "nil" with 0.
0
 

Author Comment

by:MonkeyLin
ID: 6661155
roylow:
I think you could try this to refresh the custom folder icon :
Private Const WM_WININICHANGE = &H1A
Private Const WM_SETTINGCHANGE = WM_WININICHANGE
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg
As Long, ByVal wParam As Long, lParam As Any) As Long
  whwnd = FindWindow("progMan", "program manager")
  SendMessage whwnd, WM_SETTINGCHANGE, 0, 0



0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question