// T3.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
char text[100];
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR lpCmdLine,int nShowCmd)
{
HWND hWnd;
WNDCLASSEX wc;
MSG msg;
HMENU hMenu;
wc.cbClsExtra=0;
wc.cbSize=sizeof(WNDCLASSEX);
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor=LoadCursor(hInstance,IDC_CROSS );
wc.hIcon=LoadIcon(hInstance,IDI_APPLICATION);
wc.hIconSm=0;
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.lpszClassName="MyWndClass";
wc.lpszMenuName="";
wc.style=0;
if(!RegisterClassEx(&wc)) return 1;
hMenu=LoadMenu(hInstance,LPSTR(IDR_MENU1));
hWnd=CreateWindow(wc.lpszClassName,"T2 Program",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,200,300,NULL,hMenu,hInstance,NULL);
ShowWindow(hWnd,SW_NORMAL);
UpdateWindow(hWnd);
memset(text,0,100);
wsprintf(text,"%s","Initializing......");
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hDC;
RECT rect;
static unsigned showType=0;
switch(msg){
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
switch(LOWORD(wParam)){
case ID_SHOWTEXT:
wsprintf(text,"%s","hello,world!");
showType=1;
GetClientRect(hWnd,&rect);
InvalidateRect(hWnd,&rect,true);
break;
case ID_CIRCLE:
showType=2;
GetClientRect(hWnd,&rect);
InvalidateRect(hWnd,&rect,true);
break;
case ID_QUIT:
PostQuitMessage(0);
}
break;
case WM_PAINT:
hDC=BeginPaint(hWnd,&ps);
RECT rect;
GetClientRect(hWnd,&rect);
switch(showType){
case 0:
DrawText(hDC,text,strlen(text),&rect,DT_LEFT);
break;
case 1:
DrawText(hDC,text,strlen(text),&rect,DT_LEFT);
break;
case 2:
RECT rect;
GetClientRect(hWnd,&rect);
Ellipse(hDC,0,0,rect.right,rect.bottom);
break;
}
EndPaint(hWnd,&ps);
break;
case WM_SIZE:
GetClientRect(hWnd,&rect);
InvalidateRect(hWnd,&rect,true);
break;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}
return 0;
}