Click here to Skip to main content
15,891,136 members
Articles / Desktop Programming / MFC

Network Message

Rate me:
Please Sign up or sign in to vote.
2.57/5 (8 votes)
1 Dec 2004 36K   818   13   4
Netsend message in LAN

Introduction

This application is used as net send message in Windows. This application retrieves all the usernames in LAN into a listbox and user can select any username and sendmessage. By this application, no need to remember all the usernames in LAN.

C++
void CNetworkDlg::DisplayUsers()
{
    m_list.ResetContent();
    nUsers=0;
        CString str;
    
    struct HostInfo
    {
        char *csName;
        char *csAdr;
        char *csComment;
    };
    struct hostent *host;
    struct in_addr *ptr;    
    DWORD dwScope = RESOURCE_CONTEXT;
    NETRESOURCE *NetResource = NULL;
    HANDLE hEnum;
    WNetOpenEnum(dwScope, NULL, NULL, NULL, &hEnum);
    WSADATA wsaData;
    WSAStartup(MAKEWORD(2,2),&wsaData);
    UINT item = 0;
    if (hEnum)
    {
        DWORD Count = 0xFFFFFFFF;
        DWORD BufferSize = 2048*8;
        LPVOID Buffer = new char[2048*8];
        
        WNetEnumResource(hEnum, &Count, Buffer, &BufferSize);
        
        NetResource = (NETRESOURCE*)Buffer;
        
        char szHostName[200];
        
        for (UINT i = 0; i < BufferSize/sizeof(NETRESOURCE); 
                                            i++, NetResource++)
        {
            if (NetResource->dwUsage == RESOURCEUSAGE_CONTAINER 
                && NetResource->dwType == RESOURCETYPE_ANY)
            {
                if (NetResource->lpRemoteName)
                {
                    CString strFullName = NetResource->lpRemoteName;
                    
                    char buf[512];
                    
                    if (0 == strFullName.Left(2).Compare("\\\\"))
                        strFullName = 
                          strFullName.Right(strFullName.GetLength()-2);
                    m_list.AddString(strFullName);
                    nUsers++;                                        
                }
            }
            WNetCloseEnum(hEnum);
        }    
        WSACleanup();
        CString st;
        st.Format("Total Users:%d",nUsers);
        SetDlgItemText(IDC_STATIC1,st);
                }
}

History

  • 2nd December, 2004: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
India India
I am working at Virinchi Technologies as programmer in vc++,COM & symbian c++. My hobbies are painting, and play chess and carams.

Comments and Discussions

 
GeneralUI for net send Pin
Msftone21-Jan-05 23:09
Msftone21-Jan-05 23:09 
GeneralHI Eswar Pin
ThatsAlok3-Dec-04 19:21
ThatsAlok3-Dec-04 19:21 
GeneralFull Progam Pin
Anonymous2-Dec-04 2:54
Anonymous2-Dec-04 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.