30미만의 두 정수의 덧셈 안산 문제를 3초 간격으로 계속 출력 하라. 입력은 안받아도 되니 문제만 출력하라.
#include <windows.h>
#include <time.h> //랜덤 함수를 초기화 할때 사용하기 위해 시간을 사용하려고.
void sansu();
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_Inst;
LPCTSTR wndname=TEXT("GFP TIME");
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nShowCmd){
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_Inst=hInstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName=wndname;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&WndClass);
hWnd=CreateWindow(wndname,wndname,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nShowCmd);
while(GetMessage(&Message,NULL,0,0)){
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam){
HDC hdc;
PAINTSTRUCT ps;
SYSTEMTIME st;
static RECT table={100,100,400,120};
static TCHAR sTime[128];
srand((unsigned)time(NULL)); //랜덤 함수 초기화.
switch(iMessage){
case WM_DESTROY:
KillTimer(hWnd,1);
PostQuitMessage(0);
return 0;
case WM_CREATE:
SetTimer(hWnd,1,3000,NULL);
SendMessage(hWnd,WM_TIMER,1,0);
return 0;
case WM_TIMER:
GetLocalTime(&st);
wsprintf(sTime,TEXT("%d + %d"),rand()%29,rand()%29); //30미만의 정수중 난수를 돌림
InvalidateRect(hWnd,&table,true);
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
TextOut(hdc,100,100,sTime,lstrlen(sTime));
EndPaint(hWnd,&ps);
return 0;
}
return (DefWindowProc(hWnd,iMessage,wParam,lParam));
}