Monday, April 19, 2010

drawing text

DRAWING Text

Step1: Select File- >New- >Projects- > Win32 Application-> Ok- > Empty project-> Ok

Step2: Select File- >New- >Files- >C++ Source File -> Ok

Step3:Define WNDCLASS structure and Register

Step4:Creating the window based on the WNDCLASS and displaying.

Step5:Message Loop – Retrieve and dispatch the messages to the window procedure

Step6:Window Procedure

a) WM_LBUTTONDOWN:

i)set the flag variable to 1.

b)WM_MOUSEMOVE:

i)Get the Device context handle and the coordinates of the client.

ii)Set the pixel as any one of the colours.

c)WM_LBUTTONUP:

reset the flag variable to zero.

d)WM_DESTROY

Post quit Message that generates WM_QUIT

e) Default:

Other messages are handled by the default window procedure.

CODE:

#include

int flag=0;

long _stdcall wproc(HWND,UINT,UINT,long);

WNDCLASS a;

int WINAPI WinMain(HINSTANCE i,

HINSTANCE j,

char *k,

int l)

{

HWND h;

MSG m;

a.style=CS_HREDRAW|CS_VREDRAW;

a.hInstance=i;

a.lpszClassName="c1";

a.lpfnWndProc=wproc;

a.hbrBackground=HBRUSH(GetStockObject(WHITE_BRUSH));

RegisterClass(&a);

h=CreateWindow("c1","title",WS_OVERLAPPEDWINDOW,10,10,150,300,0,0,i,0);

ShowWindow(h,l);

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

{DispatchMessage(&m);}

return 0;

}

long _stdcall wproc(HWND hwnd,UINT x,UINT y,long z)

{

HDC hdc;

switch(x)

{

case WM_LBUTTONDOWN:

flag=1;

break;

case WM_MOUSEMOVE:

if(flag==1)

{

hdc=GetDC(hwnd);

SetPixel(hdc,LOWORD(z),HIWORD(z),RGB(255,0,0));

ReleaseDC(hwnd,hdc);

}

break;

case WM_LBUTTONUP:

flag=0;

break;

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

return DefWindowProc(hwnd,x,y,z);

}

return 0;}

No comments:

Post a Comment