#pragma comment(linker, "/ENTRY:Entry")
#pragma comment(linker, "/subsystem:windows")
#include <winsock2.h>
#pragma comment(lib,"ws2_32.lib")
#include <commctrl.h>
#pragma comment(lib,"comctl32.lib")
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND h_list;
HWND h_Static;
WSADATA wsa;
DWORD dwLen=0;
int nRet;
LPWSAPROTOCOL_INFO pInfo;
switch (uMsg)
{
case WM_CREATE:
InitCommonControls();
h_list = CreateWindowEx(0,L"SysListView32",0,WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL,0,0,994,500,hWnd,0,GetModuleHandle(0),0);
SendMessage(h_list,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT,LVS_EX_FULLROWSELECT);
LV_COLUMN lvc;
RtlZeroMemory(&lvc,sizeof(lvc));
lvc.mask = LVCF_TEXT+LVCF_WIDTH;
lvc.pszText = L"ServiceFlags1";
lvc.cx = 80;
SendMessage(h_list, LVM_INSERTCOLUMN, 0, (LPARAM)&lvc);
lvc.cx = 200;
lvc.pszText = L"ProviderFlags";
SendMessage(h_list,LVM_INSERTCOLUMN, 1, (LPARAM)&lvc);
lvc.cx = 260;
lvc.pszText = L"ProviderId";
SendMessage(h_list,LVM_INSERTCOLUMN, 2, (LPARAM)&lvc);
lvc.cx = 100;
lvc.pszText = L"CatalogEntryId";
SendMessage(h_list,LVM_INSERTCOLUMN, 3, (LPARAM)&lvc);
lvc.cx = 120;
lvc.pszText = L"Entry type";
SendMessage(h_list,LVM_INSERTCOLUMN, 4, (LPARAM)&lvc);
lvc.cx = 120;
lvc.pszText = L"Protocol Chain length";
SendMessage(h_list,LVM_INSERTCOLUMN, 5, (LPARAM)&lvc);
lvc.cx = 50;
lvc.pszText = L"Version";
SendMessage(h_list,LVM_INSERTCOLUMN, 6, (LPARAM)&lvc);
lvc.cx = 100;
lvc.pszText = L"AddressFamily";
SendMessage(h_list,LVM_INSERTCOLUMN, 7, (LPARAM)&lvc);
lvc.cx = 80;
lvc.pszText = L"MaxSockAddr";
SendMessage(h_list,LVM_INSERTCOLUMN, 8, (LPARAM)&lvc);
lvc.cx = 80;
lvc.pszText = L"MinSockAddr";
SendMessage(h_list,LVM_INSERTCOLUMN, 9, (LPARAM)&lvc);
lvc.cx = 120;
lvc.pszText = L"SocketType";
SendMessage(h_list,LVM_INSERTCOLUMN, 10, (LPARAM)&lvc);
lvc.cx = 180;
lvc.pszText = L"Protocol";
SendMessage(h_list,LVM_INSERTCOLUMN, 11, (LPARAM)&lvc);
lvc.cx = 120;
lvc.pszText = L"ProtocolMaxOffset";
SendMessage(h_list,LVM_INSERTCOLUMN, 12, (LPARAM)&lvc);
lvc.cx = 120;
lvc.pszText = L"NetworkByteOrder";
SendMessage(h_list,LVM_INSERTCOLUMN, 13, (LPARAM)&lvc);
lvc.cx = 90;
lvc.pszText = L"SecurityScheme";
SendMessage(h_list,LVM_INSERTCOLUMN, 14, (LPARAM)&lvc);
lvc.cx = 90;
lvc.pszText = L"MessageSize";
SendMessage(h_list,LVM_INSERTCOLUMN, 15, (LPARAM)&lvc);
lvc.cx = 550;
lvc.pszText = L"Protocol";
SendMessage(h_list,LVM_INSERTCOLUMN, 16, (LPARAM)&lvc);
LV_ITEM lvi;
RtlZeroMemory(&lvi,sizeof(lvi));
WSAStartup(MAKEWORD(2,2),&wsa);
WSAEnumProtocols(NULL,NULL,&dwLen);
pInfo=(LPWSAPROTOCOL_INFO)HeapAlloc(GetProcessHeap(), 0,dwLen);
nRet=WSAEnumProtocols(NULL,pInfo,&dwLen);
for(int i=0;i<nRet;i++)
{
lvi.iItem = i;
lvi.mask = LVIF_TEXT;
wchar_t temp[MAX_PATH] = {0};
wsprintf(temp,L"0x%08x",pInfo[i].dwServiceFlags1);
lvi.pszText = temp;
lvi.iSubItem = 0;
SendMessage(h_list,LVM_INSERTITEM,0,(LPARAM)&lvi);
if (pInfo[i].dwProviderFlags == PFL_MULTIPLE_PROTO_ENTRIES)
{
lvi.pszText = L"PFL_MULTIPLE_PROTO_ENTRIES";
}
else if (pInfo[i].dwProviderFlags == PFL_RECOMMENDED_PROTO_ENTRY)
{
lvi.pszText = L"PFL_RECOMMENDED_PROTO_ENTRY";
}
else if (pInfo[i].dwProviderFlags == PFL_HIDDEN)
{
lvi.pszText = L"PFL_HIDDEN";
}
else if (pInfo[i].dwProviderFlags == PFL_MATCHES_PROTOCOL_ZERO)
{
lvi.pszText = L"PFL_MATCHES_PROTOCOL_ZERO";
}
else if (pInfo[i].dwProviderFlags == 0x00000010)
{
lvi.pszText = L"PFL_NETWORKDIRECT_PROVIDER";
}
else
{
wsprintf(temp,L"值为:0x%08x",pInfo[i].dwProviderFlags);
lvi.pszText = temp;
}
lvi.iSubItem = 1;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
WCHAR GuidString[40] = { 0 };
StringFromGUID2(pInfo[i].ProviderId, (LPOLESTR) & GuidString, 39);
lvi.pszText = GuidString;
lvi.iSubItem = 2;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
wsprintf(temp,L"0x%08x",pInfo[i].dwCatalogEntryId);
lvi.pszText = temp;
lvi.iSubItem = 3;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
if (pInfo[i].ProtocolChain.ChainLen == 1)
{
lvi.pszText = L"Base Service Provider";
}
else
{
lvi.pszText = L"Layered Chain Entry";
}
lvi.iSubItem = 4;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
wsprintf(temp,L"0x%08x",pInfo[i].ProtocolChain.ChainEntries);
lvi.pszText = temp;
lvi.iSubItem = 5;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
wsprintf(temp,L"%d",pInfo[i].iVersion);
lvi.pszText = temp;
lvi.iSubItem = 6;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
wsprintf(temp,L"%d",pInfo[i].iAddressFamily);
lvi.pszText = temp;
lvi.iSubItem = 7;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
wsprintf(temp,L"%d",pInfo[i].iMaxSockAddr);
lvi.pszText = temp;
lvi.iSubItem = 8;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
wsprintf(temp,L"%d",pInfo[i].iMinSockAddr);
lvi.pszText = temp;
lvi.iSubItem = 9;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
if (pInfo[i].iSocketType == 1)
{
lvi.pszText = L"SOCK_STREAM";
}
else if (pInfo[i].iSocketType == 2)
{
lvi.pszText = L"SOCK_DGRAM";
}
else if (pInfo[i].iSocketType == 3)
{
lvi.pszText = L"SOCK_RAW";
}
else if (pInfo[i].iSocketType == 4)
{
lvi.pszText = L"SOCK_RDM";
}
else if (pInfo[i].iSocketType == 5)
{
lvi.pszText = L"SOCK_SEQPACKET";
}
else
{
lvi.pszText = L"未知";
}
lvi.iSubItem = 10;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
if (pInfo[i].iProtocol == 1)
{
lvi.pszText = L"IPPROTO_ICMP";
}
else if (pInfo[i].iProtocol == 2)
{
lvi.pszText = L"IPPROTO_IGMP";
}
else if (pInfo[i].iProtocol == 3)
{
lvi.pszText = L"BTHPROTO_RFCOMM";
}
else if (pInfo[i].iProtocol == 6)
{
lvi.pszText = L"IPPROTO_TCP";
}
else if (pInfo[i].iProtocol == 17)
{
lvi.pszText = L"IPPROTO_UDP";
}
else if (pInfo[i].iProtocol == 58)
{
lvi.pszText = L"IPPROTO_ICMPV6";
}
else if (pInfo[i].iProtocol == 113)
{
lvi.pszText = L"IPPROTO_RM";
}
else
{
wsprintf(temp,L"未知,其值为0x%08x",pInfo[i].iProtocol);
lvi.pszText = temp;
}
lvi.iSubItem = 11;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
wsprintf(temp,L"0x%08x",pInfo[i].iProtocolMaxOffset);
lvi.pszText = temp;
lvi.iSubItem = 12;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
wsprintf(temp,L"0x%08x",pInfo[i].iNetworkByteOrder);
lvi.pszText = temp;
lvi.iSubItem = 13;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
wsprintf(temp,L"0x%08x",pInfo[i].iSecurityScheme);
lvi.pszText = temp;
lvi.iSubItem = 14;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
wsprintf(temp,L"0x%08x",pInfo[i].dwMessageSize);
lvi.pszText = temp;
lvi.iSubItem = 15;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
lvi.pszText = pInfo[i].szProtocol;
lvi.iSubItem = 16;
SendMessage(h_list,LVM_SETITEM,0,(LPARAM)&lvi);
}
WSACleanup();
if (pInfo) HeapFree(GetProcessHeap(),0,pInfo);
h_Static = CreateWindowEx(WS_EX_CLIENTEDGE,L"Static",0,WS_CHILD | WS_VISIBLE | SS_LEFT | WS_GROUP,0,500,994,150,hWnd,0,GetModuleHandle(0),0);
SendMessage(h_Static,WM_SETTEXT,0,(LPARAM)L"email:leguanyuan at 126 dot com\n\
homepage:http://correy.webs.com\n\
没啥技术含量,但还有点用处。\n\
虽然EnumProtocols函数已经过时,但仍有参考的价值。\n\
AddressFamily列的数字代表的含义,请查看相关的资料\n\
不足之处,敬请指导。");/*注意上面的格式,不可以添加空格和注释。*/
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd, uMsg, wParam, lParam));
}
return(0);
}
void Entry()
{
WNDCLASSEX sWndClassEx = {48,3,WindowProc,0,0,GetModuleHandle(0),0,LoadCursor(0,IDC_ARROW),(HBRUSH)6,0,L"correy",0};
ATOM a = RegisterClassEx(&sWndClassEx);
ShowWindow(CreateWindowEx(0,L"correy",L"made by correy",0x0Ca0000,CW_USEDEFAULT,CW_USEDEFAULT,999,666,0,0, GetModuleHandle(0),0),1);
MSG sMsg;
while (GetMessage(&sMsg, 0, 0, 0))
{
DispatchMessage(&sMsg);
}
ExitProcess(0);
}
//made at 2011.11.24
没有评论:
发表评论