求windows界面没显示问题,附代码?
#include<windows.h>代码单步调试进入死循环(while这块),求怎么弄哦?
static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
static TCHAR szAppName[] = TEXT ("读取.txt文件") ;
void DataManage(char *,DWORD );
byte Buff[64];
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;
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,
NULL,
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);
DataManage((char*)lpBuff,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));
DrawText(hdc,(LPCTSTR)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) ;
}
void DataManage(char *p,DWORD len)
{
int j=0;
for(DWORD i=0;i<len;i++,++p)
{
if((((*p)>=0x30)&((*p)<=0x46)))
{
if((*(p+1)>=0x30)&(*(p+1)<=0x46))
{
Buff[j]=((int)*p)*16+(int)(*(p+1));i++;j++;++p;continue;
}
else
{
Buff[j]=(int)*p;j++;continue;
}
}
else
p++;continue;
}
Buff[len]='\0';
}
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;
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,
NULL,
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);
DataManage((char*)lpBuff,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));
DrawText(hdc,(LPCTSTR)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 ;//此类的都应该是break;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;//DefWindowProc这个函数是默认的窗口处理函数,我们可以把不关心的消息都丢给它来处理。
}
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);
DataManage((char*)lpBuff,length); //datamanege调用数据处理数组
}
}
#include<windows.h>最终的效果是 绿色12-AE-5-6A- EBA(这是一种内部密码方式?臆测)
static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
static TCHAR szAppName[] = TEXT ("读取.txt文件") ;
void DataManage(char *,DWORD );
byte Buffs[64];
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;
switch (message)
{
case WM_CREATE:
{
HANDLE h;
hdc=GetDC(hwnd);
h=CreateFile(TEXT("E:\\data.txt"), //里面数据格式为 12-AE-5-6A-
GENERIC_READ,
0,
NULL,
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);
DataManage((char*)lpBuff,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,( char * )lpBuff,-1,&rect,DT_WORDBREAK
[解决办法]
DT_EDITCONTROL );
rect.left += 400;
DrawTextA( hdc , ( char * ) Buffs ,-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) ;
}
void DataManage(char *p,DWORD len)
{
int j=0;
for(DWORD i=0;i<len;i++,++p)
{
if((((*p)>=0x30)&((*p)<=0x46)))
{
if((*(p+1)>=0x30)&(*(p+1)<=0x46))
{
Buffs[j]=((int)*p)*16+(int)(*(p+1));i++;j++;++p;continue;
}
else
{
Buffs[j]=(int)*p;j++;continue;
}
}
else
p++;continue;
}
Buffs[len]='\0';
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC dc = BeginPaint(hwnd, &ps);
RECT rc;
GetClientRect(hwnd, &rc);
HBRUSH br = CreateSolidBrush(RGB(200,240,200));
FillRect(dc, &rc, br);
LOGFONT lf = { 0 };
strcpy_s(lf.lfFaceName, "微软雅黑");
lf.lfHeight = 30;
HFONT font = CreateFontIndirect(&lf);
SelectObject(dc, font);
SetTextColor(dc, RGB(0,0,255));
SetBkMode(dc, TRANSPARENT);
DrawText(dc, "Hello World", -1, &rc, DT_SINGLELINE
[解决办法]
DT_VCENTER
[解决办法]
DT_CENTER);
DeleteObject(br);
DeleteObject(font);
EndPaint(hwnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR cmd, int nCmdShow)
{
try{
WNDCLASS wc = { sizeof(WNDCLASS) };
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpfnWndProc = WndProc;
wc.lpszClassName = "[Win32标准应用程序]";
wc.style = CS_VREDRAW
[解决办法]
CS_HREDRAW;
ATOM atom = RegisterClass(&wc);
if(atom == 0)
throw 1;
HWND hwnd = CreateWindow(wc.lpszClassName, "Windows32 Application",
WS_VISIBLE
[解决办法]
WS_POPUP
[解决办法]
WS_CAPTION
[解决办法]
WS_SYSMENU, 100, 50, 700, 500, NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
throw 2;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG msg;
while(true)
{
BOOL bRet = GetMessage(&msg, NULL, 0, 0);
if(bRet == -1)
continue;// Error Message
else if(bRet)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
break;// Exit
}
}
}catch(...){}
return 0;
}
#include<windows.h>
#include <stdio.h>
#include <stdlib.h>
static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
static TCHAR szAppName[] = TEXT ("读取.txt文件") ;
void DataManage( char * data ,DWORD length );
char InData[64];
char OutData[64];
int iResult[3];//这个数组根据你的长度来吧,或者用vector<int>
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;
switch (message)
{
case WM_CREATE:
{
FILE * pFile = fopen( "E:\\data.txt" , "rb" );
if ( NULL != pFile )
{
fread( InData , sizeof( char ) , 64 , pFile );
fseek( pFile , 0 , SEEK_SET );
fscanf( pFile , "%x-%x-%x" , iResult , iResult + 1 , iResult + 2 );
fclose( pFile );
pFile = NULL;
sprintf( OutData , "%d-%d-%d" , iResult[0] , iResult[1] , iResult[2] );
}
return 0;
}
case WM_SIZE:
{
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
}
return 0 ;
case WM_PAINT:
{
RECT rect ;
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
InflateRect(&rect, -5, -5);
SetTextColor(hdc, RGB(34, 120, 34));
DrawTextA( hdc, InData ,-1,&rect,DT_WORDBREAK
[解决办法]
DT_EDITCONTROL );
rect.left += 400;
DrawTextA( hdc , OutData ,-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) ;
}