注意读入数据的文件路径必须正确不然出现乱码:
代码如下
View Code
1 #include "stdafx.h" 2 #include <windows.h> 3 #include <windowsx.h> 4 #include "resource.h" 5 #include "MainDlg.h" 6 7 8 BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 9 { 10 switch(uMsg) 11 { 12 HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog); 13 HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand); 14 HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose); 15 } 16 17 return FALSE; 18 } 19 20 BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) 21 { 22 return TRUE; 23 } 24 25 void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) 26 { 27 switch(id) 28 { 29 30 case IDC_OPEN: 31 { 32 char str[256]; 33 FILE *fp; 34 fp = fopen("E:\\test.txt","r"); 35 fgets(str,sizeof(str),fp); 36 fclose(fp); 37 SetDlgItemText(hwnd,IDC_EDIT1,TEXT(str)); 38 } 39 break; 40 default: 41 break; 42 } 43 } 44 45 void Main_OnClose(HWND hwnd) 46 { 47 EndDialog(hwnd, 0); 48 }
运行结果: