You are on page 1of 5

#include<windows.

h>

#include"resource.h"

#define IDM_STOP 1

#define IDM_START 2

LRESULT CALLBACK r(HWND,UINT,WPARAM,LPARAM);

int _stdcall WinMain(HINSTANCE i,HINSTANCE j,LPSTR k,int l)

HWND h;

MSG m;

WNDCLASS w;

if(!j)

w.cbClsExtra=0;

w.cbWndExtra=0;

w.hbrBackground=NULL;

w.hCursor=NULL;

w.hIcon=LoadIcon (i, MAKEINTRESOURCE (IDI_ICON1)) ;

w.hInstance=i;

w.lpfnWndProc=r;

w.lpszClassName=TEXT("Class");

w.lpszMenuName=NULL;

w.style=CS_HREDRAW | CS_VREDRAW;
if(!RegisterClass(&w))

return 0;

h=CreateWindow(TEXT("Class"),TEXT("m"),WS_OVERLAPPEDWINDOW,0,0,1,1,NULL,
NULL,i,NULL);

ShowWindow(h,l);

while(GetMessage(&m,NULL,0,0))

TranslateMessage(&m);

DispatchMessage(&m);

return(int)( m.wParam);

LRESULT CALLBACK r(HWND h,UINT m,WPARAM w,LPARAM l)

HMENU hSysMenu;

static int nTimer=0,nXpos,nYpos, nXvel=1,nYvel=1,nScreenX, nScreenY,nIconY,


nIconX;

POINT *pMinMaxInfo;

switch(m)

case WM_CREATE:

hSysMenu=GetSystemMenu(h,NULL);

AppendMenu(hSysMenu, MF_SEPARATOR, 0,NULL);


AppendMenu(hSysMenu,MF_STRING,IDM_STOP,TEXT("Stop"));

AppendMenu(hSysMenu,MF_STRING,IDM_START,TEXT("Start"));

DeleteMenu(hSysMenu, SC_MAXIMIZE, MF_BYCOMMAND);

DeleteMenu(hSysMenu, SC_RESTORE, MF_BYCOMMAND);

DeleteMenu(hSysMenu, SC_SIZE, MF_BYCOMMAND);

nScreenX=GetSystemMetrics(SM_CXSCREEN);

nScreenY=GetSystemMetrics(SM_CYSCREEN);

nIconX=GetSystemMetrics(SM_CXICON);

nIconY=GetSystemMetrics(SM_CYICON);

break;

case WM_SYSCOMMAND:

switch(w)

case IDM_START:

if(nTimer==0)

nTimer=SetTimer(h,1,100, NULL);

if(nTimer==0)

MessageBox(h, TEXT("No timers Left"),


TEXT("Message"),MB_OK);

return 0;

case IDM_STOP:

if(nTimer)

KillTimer(h,1);

nTimer=0;
}

return 0;

default:

return DefWindowProc(h, m, w, l);

case WM_MOVE:

nXpos=LOWORD(l);

nYpos=HIWORD(l);

break;

case WM_SIZE:

ShowWindow(h, SW_SHOWMINIMIZED);

break;

case WM_TIMER:

nXpos+=nXvel;

nYpos+=nYvel;

if(nXpos<=0 || nXpos>=nScreenX-nIconX)

nXvel*=-1;

if(nYpos<=0 || nYpos>=nScreenY-nIconY)

nYvel*=-1;

MoveWindow(h,nXpos,nYpos,1,1,TRUE);

break;

case WM_DESTROY:

if(nTimer)

KillTimer(h,1);

PostQuitMessage(0);

break;
default:

return DefWindowProc(h,m,w,l);

return 0;