16,473
社区成员
发帖
与我相关
我的任务
分享
#include<windows.h>
static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
static TCHAR szAppName[] = TEXT ("读取.txt文件") ;
byte DataManage(char ,DWORD );
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd=CreateWindow (szAppName,
TEXT ("The Hello Program"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL) ;
ShowWindow (hwnd, SW_SHOWNORMAL) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
static int cxClient, cyClient;
DWORD dwread;
static BOOL read;
static HLOCAL lpBuff;
byte Buff;
switch (message)
{
case WM_CREATE:
{
HANDLE h;
hdc=GetDC(hwnd);
h=CreateFile(TEXT("E:\\data.txt"), //里面数据格式为 12-AE-5-6A-
GENERIC_READ, //文件进行何种操作 读操作
0, //文件是否共享,o表示不共享
NULL, //文件安全属性,通常设置为0
OPEN_EXISTING, //文件存在就读取,否则创建
FILE_ATTRIBUTE_READONLY,
0);
if(h!=INVALID_HANDLE_VALUE)
{
DWORD length=GetFileSize(h,NULL);
lpBuff = LocalAlloc(GPTR, sizeof(char) * (length + 1));//分配内存
if(lpBuff!=NULL)
{
read=ReadFile(h,lpBuff,length,&dwread, 0);
static char lpBuff1=(char)lpBuff;
Buff=DataManage(lpBuff1,length); //datamanege调用数据处理数组
}
}
ReleaseDC(hwnd,hdc);
return 0;
}
case WM_SIZE:
{
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
}
return 0 ;
case WM_PAINT:
{
if(read)
{
RECT rect ;
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
InflateRect(&rect, -5, -5);
SetTextColor(hdc, RGB(34, 120, 34));
DrawTextA(hdc,(LPCSTR)lpBuff,-1,&rect,DT_WORDBREAK | DT_EDITCONTROL ) ;
DrawText(hdc,(LPCWSTR)Buff,-1,&rect,DT_WORDBREAK | DT_EDITCONTROL ) ;
EndPaint (hwnd, &ps) ;
}
return 0 ;
}
case WM_DESTROY:
if (lpBuff != NULL)
{
LocalFree(lpBuff);
}
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
byte DataManage(char lpBuff1,DWORD length)
{
byte Buff2[64];
int j=0;
for(DWORD i=0;i<length+1;i++)
{
if(lpBuff1[i]>=0x30||lpBuff1[i]<=0x46)
{
if(lpBuff1[i+1]>=0x30||lpBuff1[i+1]<=0x46)
{
Buff2[j]=((int)lpBuff1[i])*16+(int)lpBuff1[i+1];i++;j++;break;
}
else
{
Buff2[j]=(int)lpBuff1[i];j++;break;
}
}
else
break;
}
return Buff2[64];
}
#include<windows.h>
static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
static TCHAR szAppName[] = TEXT ("读取.txt文件") ;
byte DataManage(char *,DWORD );
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd=CreateWindow (szAppName,
TEXT ("The Hello Program"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL) ;
ShowWindow (hwnd, SW_SHOWNORMAL) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
static LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
static int cxClient, cyClient;
DWORD dwread;
static BOOL read;
static void * lpBuff; //原来HANDLE和HLOCAL就是void*。
byte Buff;
switch (message)
{
case WM_CREATE:
{
HANDLE h;
hdc=GetDC(hwnd);
h=CreateFile(TEXT("E:\\data.txt"), //里面数据格式为 12-AE-5-6A-
GENERIC_READ, //文件进行何种操作 读操作
0, //文件是否共享,o表示不共享
NULL, //文件安全属性,通常设置为0
OPEN_EXISTING, //文件存在就读取,否则创建
FILE_ATTRIBUTE_READONLY,
0);
if(h!=INVALID_HANDLE_VALUE)
{
DWORD length=GetFileSize(h,NULL);
//lpBuff = LocalAlloc(GPTR, sizeof(char) * (length + 1));//分配内存
if(lpBuff!=NULL)
{
read=ReadFile(h,lpBuff,length,&dwread, 0);
static char *lpBuff1;//=(char*)lpBuff;
lpBuff1=(char*)lpBuff;
Buff=DataManage(lpBuff1,length); //datamanege调用数据处理数组
}
}
ReleaseDC(hwnd,hdc);
return 0;
}
case WM_SIZE:
{
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
}
return 0 ;
case WM_PAINT:
{
if(read)
{
RECT rect ;
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
InflateRect(&rect, -5, -5);
SetTextColor(hdc, RGB(34, 120, 34));
DrawTextA(hdc,(LPCSTR)lpBuff,-1,&rect,DT_WORDBREAK | DT_EDITCONTROL ) ;
DrawText(hdc,(LPCWSTR)Buff,-1,&rect,DT_WORDBREAK | DT_EDITCONTROL ) ;
EndPaint (hwnd, &ps) ;
}
return 0 ;
}
case WM_DESTROY:
if (lpBuff != NULL)
{
LocalFree(lpBuff);
}
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
byte DataManage(char *p,DWORD length)
{
byte Buff2[64];
int j=0;
for(DWORD i=0;i<length+1;i++)
{
if(((*p)>=0x30)&(*p)<=0x46)
{
if((*(p+1)>=0x30)&(*(p+1)<=0x46))
{
Buff2[j]=((int)*p)*16+(int)(*(p+1));i++;j++;++p;break;
}
else
{
Buff2[j]=(int)*p;j++;p++;break;
}
}
else
p++;break;
}
return Buff2[64];
}
这是最新版的,程序没报错,就是没结果?