Windows API 學習之 GetUserName,apigetusername
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 else
15 {
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 }