DavidCrow,
Thanks for the vote of 1, I have returned the favor.
Actually, you should not answer questions if you do not know the answer. In fact, by registering for MPR notifications you can detect connections and disconnections of network resources, including type RESOURCEDISPLAYTYPE_NETWORK which equates to a cat-5 cable being plugged and thus connecting to a network resource.
Here is some sample code:
Enjoy.
<br />
#define UNICODE<br />
#define _UNICODE<br />
<br />
#include <windows.h><br />
#include "npapi.h"<br />
<br />
BOOL FormatAddFlags(DWORD, LPTSTR);<br />
BOOL FormatNetResource(LPNETRESOURCE, LPTSTR);<br />
<br />
DWORD dwCounter = 0;<br />
<br />
BOOL APIENTRY DllMain(HANDLE hModule, DWORD reason, LPVOID lpResv)<br />
{<br />
return TRUE;<br />
<br />
}<br />
<br />
DWORD APIENTRY AddConnectNotify(LPNOTIFYINFO lpNotifyInfo,<br />
LPNOTIFYADD lpAddInfo)<br />
{<br />
<br />
TCHAR sz[1024], sz1[1024];<br />
<br />
<br />
if (lpNotifyInfo->dwNotifyStatus == NOTIFY_PRE) {<br />
lstrcpy(sz, TEXT("Pre-Add:"));<br />
dwCounter++;<br />
lpNotifyInfo->lpContext = (VOID *)dwCounter;<br />
} else if (lpNotifyInfo->dwNotifyStatus == NOTIFY_POST) {<br />
wsprintf(sz, TEXT("Post-Add (%x):"), <br />
lpNotifyInfo->dwOperationStatus);<br />
} else {<br />
lstrcpy(sz, TEXT("Other-Add:"));<br />
}<br />
<br />
wsprintf(sz1, TEXT("Context=%x"), <br />
(DWORD)lpNotifyInfo->lpContext);<br />
lstrcat(sz, sz1);<br />
<br />
if (FormatAddFlags(lpAddInfo->dwAddFlags, sz1)) {<br />
lstrcat(sz, sz1);<br />
}<br />
<br />
<br />
if (FormatNetResource(&(lpAddInfo->NetResource), sz1)) {<br />
lstrcat(sz, sz1);<br />
}<br />
<br />
MessageBox(lpAddInfo->hwndOwner, sz, TEXT("Connect"), MB_OK);<br />
<br />
return WN_SUCCESS;<br />
<br />
}<br />
<br />
DWORD APIENTRY CancelConnectNotify(LPNOTIFYINFO lpNotifyInfo,<br />
LPNOTIFYCANCEL lpCancelInfo)<br />
{<br />
<br />
TCHAR sz[1024], sz1[1024];<br />
<br />
<br />
if (lpNotifyInfo->dwNotifyStatus == NOTIFY_PRE) {<br />
lstrcpy(sz, TEXT("Pre-Cancel:"));<br />
dwCounter++;<br />
lpNotifyInfo->lpContext = (VOID *)dwCounter;<br />
} else if (lpNotifyInfo->dwNotifyStatus == NOTIFY_POST) {<br />
wsprintf(sz, TEXT("Post-Cancel (%x):"), <br />
lpNotifyInfo->dwOperationStatus);<br />
} else {<br />
lstrcpy(sz, TEXT("Other-Cancel:"));<br />
}<br />
<br />
wsprintf(sz1, TEXT("Context=%x"), <br />
(DWORD)lpNotifyInfo->lpContext);<br />
lstrcat(sz, sz1);<br />
<br />
if (lpCancelInfo->lpName != NULL) {<br />
lstrcat(sz, TEXT(", Name="));<br />
lstrcat(sz, lpCancelInfo->lpName);<br />
}<br />
<br />
if (lpCancelInfo->lpProvider != NULL) {<br />
lstrcat(sz, TEXT(", Provider="));<br />
lstrcat(sz, lpCancelInfo->lpProvider);<br />
}<br />
<br />
if (lpCancelInfo->dwFlags & CONNECT_UPDATE_PROFILE) {<br />
lstrcat(sz, TEXT(", Flags=PersistentCancel"));<br />
} else {<br />
wsprintf(sz1, TEXT(", Flags=(%x)"), lpCancelInfo->dwFlags);<br />
lstrcat(sz, sz1);<br />
}<br />
<br />
if (lpCancelInfo->fForce) {<br />
lstrcat(sz, TEXT(", Force=TRUE"));<br />
} else {<br />
lstrcat(sz, TEXT(", Force=FALSE"));<br />
}<br />
<br />
MessageBox(NULL, sz, TEXT("Connect"), MB_OK);<br />
<br />
return WN_SUCCESS;<br />
<br />
}<br />
<br />
<br />
BOOL FormatAddFlags(DWORD dwAddFlags, LPTSTR psz)<br />
{<br />
TCHAR szTemp[MAX_PATH];<br />
<br />
lstrcpy(psz, TEXT(", AddFlags="));<br />
<br />
if (dwAddFlags & CONNECT_TEMPORARY) {<br />
lstrcat(psz, TEXT("Temporary "));<br />
}<br />
if (dwAddFlags & CONNECT_INTERACTIVE) {<br />
lstrcat(psz, TEXT("Interactive "));<br />
}<br />
if (dwAddFlags & CONNECT_PROMPT) {<br />
lstrcat(psz, TEXT("Prompt "));<br />
}<br />
if (dwAddFlags & CONNECT_UPDATE_PROFILE) {<br />
lstrcat(psz, TEXT("UpdateProfile "));<br />
} <br />
if (dwAddFlags & CONNECT_UPDATE_RECENT) {<br />
lstrcat(psz, TEXT("UpdateRecent "));<br />
}<br />
<br />
wsprintf(szTemp, TEXT("(%x)"), dwAddFlags);<br />
lstrcat(psz, szTemp);<br />
<br />
<br />
return TRUE;<br />
<br />
}<br />
<br />
BOOL FormatNetResource(LPNETRESOURCE lpNetResource, LPTSTR psz)<br />
{<br />
<br />
TCHAR szTemp[MAX_PATH];<br />
<br />
*psz = 0;<br />
<br />
<br />
switch(lpNetResource->dwScope) {<br />
case RESOURCE_CONNECTED:<br />
lstrcpy(psz, TEXT(", Scope=Connected"));<br />
break;<br />
<br />
case RESOURCE_GLOBALNET:<br />
lstrcpy(psz, TEXT(", Scope=GlobalNet"));<br />
break;<br />
<br />
case RESOURCE_CONTEXT:<br />
lstrcpy(psz, TEXT(", Scope=Context"));<br />
break;<br />
<br />
default:<br />
wsprintf(szTemp, TEXT(", Scope=%x"), lpNetResource->dwScope);<br />
lstrcpy(psz, szTemp);<br />
break;<br />
}<br />
<br />
<br />
switch(lpNetResource->dwType) {<br />
case RESOURCETYPE_DISK:<br />
lstrcat(psz, TEXT(", Type=Disk"));<br />
break;<br />
<br />
case RESOURCETYPE_PRINT:<br />
lstrcat(psz, TEXT(", Type=Printer"));<br />
break;<br />
<br />
case RESOURCETYPE_ANY:<br />
lstrcat(psz, TEXT(", Type=Any"));<br />
break;<br />
<br />
default:<br />
wsprintf(szTemp, TEXT(", Type=%x"), lpNetResource->dwType);<br />
lstrcat(psz, szTemp);<br />
break;<br />
}<br />
<br />
<br />
switch(lpNetResource->dwDisplayType) {<br />
case RESOURCEDISPLAYTYPE_NETWORK:<br />
lstrcat(psz, TEXT(", DisplayType=Network"));<br />
break;<br />
<br />
case RESOURCEDISPLAYTYPE_DOMAIN:<br />
lstrcat(psz, TEXT(", DisplayType=Domain"));<br />
break;<br />
<br />
case RESOURCEDISPLAYTYPE_SERVER:<br />
lstrcat(psz, TEXT(", DisplayType=Server"));<br />
break;<br />
<br />
case RESOURCEDISPLAYTYPE_SHARE:<br />
lstrcat(psz, TEXT(", DisplayType=Share"));<br />
break;<br />
<br />
case RESOURCEDISPLAYTYPE_DIRECTORY:<br />
lstrcat(psz, TEXT(", DisplayType=Directory"));<br />
break;<br />
<br />
case RESOURCEDISPLAYTYPE_GENERIC:<br />
lstrcat(psz, TEXT(", DisplayType=Generic"));<br />
break;<br />
<br />
default:<br />
wsprintf(szTemp, TEXT(", DisplayType=%x"), <br />
lpNetResource->dwDisplayType);<br />
lstrcat(psz, szTemp);<br />
break;<br />
}<br />
<br />
<br />
lstrcat(psz, TEXT(", Usage="));<br />
<br />
if (lpNetResource->dwUsage & RESOURCEUSAGE_CONNECTABLE) {<br />
lstrcat(psz, TEXT("Connectable "));<br />
}<br />
if (lpNetResource->dwUsage & RESOURCEUSAGE_CONTAINER) {<br />
lstrcat(psz, TEXT("Container "));<br />
}<br />
if (lpNetResource->dwUsage & RESOURCEUSAGE_NOLOCALDEVICE) {<br />
lstrcat(psz, TEXT("NoLocalDevice "));<br />
}<br />
if (lpNetResource->dwUsage & RESOURCEUSAGE_SIBLING) {<br />
lstrcat(psz, TEXT("Sibling "));<br />
}<br />
if (lpNetResource->dwUsage & RESOURCEUSAGE_ATTACHED) {<br />
lstrcat(psz, TEXT("Attached "));<br />
}<br />
<br />
wsprintf(szTemp, TEXT("(%x)"), lpNetResource->dwUsage);<br />
lstrcat(psz, szTemp);<br />
<br />
<br />
if (lpNetResource->lpLocalName != NULL) {<br />
lstrcat(psz, TEXT(", LocalName="));<br />
lstrcat(psz, lpNetResource->lpLocalName);<br />
}<br />
<br />
if (lpNetResource->lpRemoteName != NULL) {<br />
lstrcat(psz, TEXT(", RemoteName="));<br />
lstrcat(psz, lpNetResource->lpRemoteName);<br />
}<br />
<br />
if (lpNetResource->lpComment != NULL) {<br />
lstrcat(psz, TEXT(", Comment="));<br />
lstrcat(psz, lpNetResource->lpComment);<br />
}<br />
<br />
if (lpNetResource->lpProvider != NULL) {<br />
lstrcat(psz, TEXT(", Provider="));<br />
lstrcat(psz, lpNetResource->lpProvider);<br />
}<br />
<br />
return TRUE;<br />
}<br />
<br />
|