首页 > 代码库 > Windows API - GetUserName

Windows API - GetUserName

 1 #include <stdio.h> 2 #include <windows.h> 3  4 #define INFO_BUFFER_SIZE 32767 5  6 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 7 { 8     TCHAR  infoBuf[INFO_BUFFER_SIZE]; 9     DWORD  bufCharCount = INFO_BUFFER_SIZE;10     if( !GetUserName( infoBuf, &bufCharCount ) )11         {12             MessageBox(NULL, TEXT("无法获得用户名"),TEXT("错误"),MB_ICONSTOP|MB_OK);13         }14     else15         {16             char istr[INFO_BUFFER_SIZE];17             sprintf(istr,"欢迎使用本程序,当前用户名为:\r\n%s",infoBuf);18             MessageBox(NULL,TEXT(istr),"MSG",MB_OK);19         }20     return 0;21 }

 

Windows API - GetUserName