下面是我的源程序,如果我在运行这个程序的时候更改A.TXT的内容,要最小化或者拖动后,显示的文字才会作出更新,我原本设计的是鼠标左键一点击就会重新读入a.txt的内容,并且在窗口作出更新
#include "windows.h"
#include "stdio.h" LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(DKGRAY_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_INFORMATION);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="WGH_normal_window";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd; hwnd=CreateWindow("WGH_normal_window","GZS32 STRDP自动检查程序",
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
0,0,
600,400,
NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
// SetTimer(hwnd,2000,1000,NULL); MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
PAINTSTRUCT ps;
static char* p=0;
switch(uMsg)
{
UpdateWindow(hwnd);
case WM_LBUTTONDOWN:
case WM_PAINT:
{
FILE* fp= fopen( "a.txt", "r");//打开文件的名字
fseek( fp , 0 , SEEK_END );
long len = ftell( fp );
fseek(fp,0,SEEK_SET );
p = new char[len];
fread(p,1,len,fp);
fwrite(p,1,len,fp);
fclose(fp); HDC hdc = BeginPaint(hwnd, &ps);
RECT rt;
GetClientRect(hwnd, &rt);
DrawText(hdc, p, strlen(p), &rt, DT_LEFT);
EndPaint(hwnd, &ps);
ReleaseDC(hwnd,hdc);
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
PostMessage(hwnd,WM_PAINT,NULL,NULL);
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货