写了一个窗口程序,计算器,磁盘信息获取,进制转换的但是结果出现乱码,有什么问题吗?
程序代码:
#include <windows.h> #include <windowsx.h> #include <string.h> #include "main.h" #include "dialogs.h" #include "resource.h" #include "rsrc.inc" BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { //BEGIN MESSAGE CRACK HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog); HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand); HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose); //END MESSAGE CRACK } return FALSE; } //////////////////////////////////////////////////////////////////////////////// // Main_OnInitDialog BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) { // Set app icons HICON hIcon = LoadIcon((HINSTANCE) GetWindowLong(hwnd, GWL_HINSTANCE) ,MAKEINTRESOURCE(IDI_ICONAPP)); SendMessage(hwnd, WM_SETICON, TRUE, (LPARAM)hIcon); SendMessage(hwnd, WM_SETICON, FALSE, (LPARAM)hIcon); // // Add initializing code here // return TRUE; } //////////////////////////////////////////////////////////////////////////////// // Main_OnCommand void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) { TCHAR cDriveExists[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int nLen=0; switch(id) { case IDC_BTNRESULT: //响应计算圆面积按钮 TCHAR cBanjing[256]; GetDlgItemText(hwnd,IDC_EDTRADIUS,cBanjing,sizeof(cBanjing)/sizeof(TCHAR)); double fBanjing,fZhouchang; fBanjing = atof(cBanjing); fZhouchang = 3.1415926*(fBanjing*fBanjing); TCHAR cZhouchang[256]; gcvt(fZhouchang,10,cZhouchang); //SetDlgItemText(hwnd,IDC_EDTZHOUCHANG,cZhouchang); SetDlgItemText(hwnd,IDC_STC,cZhouchang); break; case IDC_BTNCALCHELP: //响应圆面积帮助按钮 MessageBox(hwnd,TEXT("\n圆形面积计算公式:\n\n圆面积(s)=圆周率π(3.14)*半径(r)的平方。\t"),TEXT("计算公式"),MB_OK|MB_ICONASTERISK); break; case IDC_BTNGETDRIVERS: //获取用户磁盘信息按钮 DWORD dwMydrivers; dwMydrivers = GetLogicalDrives(); TCHAR cDrivers[256]; itoa(dwMydrivers,cDrivers,2); //转换为字符串 strrev(cDrivers); //反转字符串 TCHAR cDriverscn[256]; //MessageBox(hwnd,cDrivers,TEXT("调试"),MB_OK); //列出所有存在盘符 int i; for(i=0;i<strlen(cDrivers);i++) { if(cDrivers[i]=='1') { cDriverscn[nLen] = cDriveExists[i]; nLen++; } } cDriverscn[nLen]='\0'; SetDlgItemText(hwnd,IDC_EDTMYDRIVERS,cDriverscn); //判断是否存在D盘 if(cDrivers[4]='1') { SetDlgItemText(hwnd,IDC_EDTYESNOD,TEXT("有")); } else { SetDlgItemText(hwnd,IDC_EDTYESNOD,TEXT("无")); } //计算存在磁盘总数 TCHAR cSUM[256]; itoa(nLen,cSUM,10); SetDlgItemText(hwnd,IDC_EDTDRIVERSNUM,cSUM); break; default:break; } } //////////////////////////////////////////////////////////////////////////////// // Main_OnClose void Main_OnClose(HWND hwnd) { EndDialog(hwnd, 0); }
这个是程序的源代码!!算法不成熟!!
附上:VC6.0的工程
Calculator_DriveMessage.rar
(1.4 MB)