Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:1k
源码类别:

VC书籍

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Unit1.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. //---------------------------------------------------------------------------
  10. __fastcall TForm1::TForm1(TComponent* Owner)
  11.         : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TForm1::Button1Click(TObject *Sender)
  16. {
  17.   TNetResource NetResource;
  18.   NetResource.dwScope=RESOURCE_GLOBALNET;
  19.   NetResource.dwType=RESOURCETYPE_DISK;
  20.   NetResource.dwUsage=RESOURCEUSAGE_CONNECTABLE;
  21.   NetResource.lpLocalName="M:";
  22.   NetResource.lpRemoteName="\\WXH\C";
  23.   NetResource.lpProvider="";
  24.   if(WNetAddConnection2(&NetResource,"","",CONNECT_UPDATE_PROFILE)==NO_ERROR)
  25.   {
  26.     ShowMessage("网络驱动器映射成功!");
  27.   }
  28.   else
  29.   {
  30.     ShowMessage("网络驱动器映射不成功!");
  31.   }
  32. }
  33. //---------------------------------------------------------------------------
  34. void __fastcall TForm1::Button2Click(TObject *Sender)
  35. {
  36.   AnsiString ass;
  37.   ass="M:";
  38.   if(WNetCancelConnection2(ass.c_str(),CONNECT_UPDATE_PROFILE,True)==NO_ERROR)
  39.   {
  40.     ShowMessage("网络驱动器的映射成功断开!");
  41.   }
  42.   else
  43.   {
  44.     ShowMessage("网络驱动器的映射没有断开成功!");
  45.   }
  46. }
  47. //---------------------------------------------------------------------------