Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 14

MOBILE COMPUTING

Practical 1:
“Graphic representation”

Steps

1) Click on new file select WCE Application, Give the name to the project, select next
then click finish.

2) Then in class view select the Global, in global select the WINMAIN.

3) Then write the below code below #define MAX_LOADSTRING 100

enum Shapes { LINE, CIRCLE, RECTANGLE, ELLIPSE};

Shapes shapes;
Shapes g_flag_shapes;

void DrawShapes(HWND hWnd);

4) Then write the below code in switch (message) in switch(wm id) below the file exit
case

case ID_SHAPES_LINE:
g_flag_shapes = LINE;

DrawShapes(hWnd);
break;

case ID_SHAPES_CIRCLE:
g_flag_shapes = CIRCLE;
DrawShapes(hWnd);
break;

case ID_SHAPES_RECTANGLE:

g_flag_shapes = RECTANGLE;
DrawShapes(hWnd);
break;

case ID_SHAPES_ELLIPSE:
g_flag_shapes = ELLIPSE;

DrawShapes(hWnd);
break;
5) Now write the method of shapes after completion of case WM_DESTROY:

void DrawShapes(HWND hWnd)


{
HDC hdc;

hdc = GetDC(hWnd);

switch(g_flag_shapes)
{
case LINE :
LineTo(hdc, 100, 100);

break;

case CIRCLE :
Ellipse(hdc, 45,50,60,60);

break;

case RECTANGLE :
Rectangle(hdc, 45, 50, 95, 100);
break;

case ELLIPSE :
Ellipse(hdc, 45, 50,60, 60);
break;
}
ReleaseDC(hWnd, hdc);

6) Now go to the Resource tab, in this tab go to menu folder, in that select IDM_MENU

7) After Help menu make menu name shapes, in shape make Line,, Circle, Rectangle,
Ellipse as shown below:
8) Now open the property window of the Line menu & copy the ID Shown below &
paste in the case you have written in step 4.

9) Repeat the above step for Circle, Rectangle, Ellipse.

10) Execute your program by pressing f5 and get O/P.


Practical 2:
“Bouncing Ball”

Steps

1) Click on new file select WCE Application, Give the name to the project, select next
then click finish.

2) Then in class view select the Global, in global select the WINMAIN.

3) After include statement define the timer & intialize some variables.

#define ID_TIMER 1
int cx=0,cy=0,xi=2,yi=2;

4) Then inside the switch(wmId) after the code of help menu write the code for start &
stop menu

case ID_START:
SetTimer(hWnd,ID_TIMER,30,NULL);
Break;
case ID_STOP:
KillTimer(hWnd,ID_TIMER);
break;

5) Then inside the WM_PAINT case write the following code after the drawstring code

Rectangle(hdc,0,0,300,300);
if(cx<0||cx>150)
xi=-xi;
if(cy<0||cy>148)
yi=-yi;
cx=cx+xi;
cy=cy+yi;
SelectObject(hdc,hbr);
Ellipse(hdc,cx,cy,cx+30,cy+30);
DeleteObject(hbr);dd

6) Then write the code for the timer case as below

case WM_TIMER:
InvalidateRect(hWnd,NULL,FALSE);
break;
7) Then select the resource tab in that select menu & add additional menu of start & stop
as shown below:

8) Now open the property window of the Line menu & copy the ID Shown below &
paste in the case you have written in step 4.

9) Repeat the above step for Stop.

10) Execute your program by pressing f5 and get O/P.


Practical 3:
“ Change Background Color Using Timer “

Steps

1) Click on new file select WCE Application, Give the name to the project, select next
then click finish.

2) Then in class view select the Global, in global select the WINMAIN.

3) In WM_CREATE case write the code for the starting of the timer as below:

SetTimer (hWnd,1,300,NULL);
return 0;

4) Then after the end of the WM_CREATE case write the Timer case & in that write the
code for timer in this case

case WM_TIMER:
RECT rt1;
HBRUSH hbr;
hdc=GetDC(hWnd);
hbr=CreateSolidBrush (RGB(rand(),rand(),rand()));
SelectObject (hdc,hbr);
GetClientRect (hWnd,&rt1);
FillRect (hdc,&rt1,hbr);
return 0;

5) Then in the WM_DESTOY case write the code for the ending of timer as below:

KillTimer (hWnd,1);
break;

6)Execute the code by pressing F5.


Practical 4:
“Control Button”

1) Click on new file select WCE Application, Give the name to the project, select next
then click finish.

2) Then in class view select the Global, in global select the WINMAIN.

3) Then initialize the variables that you are going to use for the defining of buttons.

HWND hn,hn1,hn2;

4) Then inside the create case write the following code:

hn = CreateWindow (TEXT("Edit"),TEXT("This"),WS_CHILD|WS_VISIBLE|
WS_BORDER,10,50,100,20,hWnd,NULL,NULL,NULL);
SetFocus(hn);
hn1 = CreateWindow
(TEXT("Button"),L"PushButton",WS_CHILD|WS_VISIBLE|
WS_BORDER,30,60,130,30,hWnd,NULL,NULL,NULL);
SetFocus (hn1);
hn2 = CreateWindow
(TEXT("Button"),L"RadioButton",WS_CHILD|WS_VISIBLE|
WS_BORDER,90,120,150,60,hWnd,NULL,NULL,NULL);
SetFocus (hn2);

5) The above code will build 3 buttons on the mobile.

6) Execute the code by pressing F5.


Practical 5:
“Change Rect/Ellipse Colour Using Timer”

Step:

1) Click on new file select WCE Application, Give the name to the project, select next
then click finish.

2) Then in class view select the Global, in global select the WINPROC.

3) In WM_CREATE: write the following code:

SetTimer (hWnd,1,300,NULL);
return 0;

4) The create the case for timer & write the following code in it:

case WM_TIMER:
RECT rt1;
HBRUSH hbr;
hdc=GetDC(hWnd);
hbr=CreateSolidBrush (RGB(rand(),rand(),rand()));
SelectObject (hdc,hbr);
Rectangle(hdc,100,100,200,200);
DeleteObject(hbr);
hbr=CreateSolidBrush (RGB(rand(),rand(),rand()));
SelectObject (hdc,hbr);
Ellipse(hdc,200,200,300,300);
DeleteObject(hbr);
ReleaseDC(hWnd,hdc);
return 0;

5) Then in WM_DESTROY write the following code for Killing the timer

KillTimer (hWnd,1);

6) Execute the program by pressing the f5.


Practical 6:
“Menu”

Steps:

1) Click on new file select WCE Application, Give the name to the project, select next
then click finish.

2) Then in class view select the Global, in global select the WINPROC.

3) Then go in Resource tab ,in resource tab go to Dialog folder in that left click & select
the insert dialog.

4) A dialog box will appear containing 2 command buttons. Now insert text box & label
as required.

5) in that select menu & add additional menu of Form & Appl as shown below:

6) Then in globals initinstance add the following code

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

7) Then add the following code in the WNDPROC after the file exit case

case ID_FORM_APP:
DialogBox(hInst, (LPCTSTR)IDD_DIALOG1, hWnd, (DLGPROC)Form);
break;

8) Then Execute the code by pressing F5.


Practical 7:
“Moving from one form to other”

Step:

1) Click on new file select WCE Application, Give the name to the project, select
next then click finish.

2) Then go to the Resource tab & go to the dialog folder.

3) Left click the dialog folder insert one dialog, insert label and text as required.

4) Insert one more dialog & insert label & text as required.

5) Now go to Menu folder & add new menu as below:

6) Now go to the Class Tab & go to the Initinstance & in forward declaration write
following code:
LRESULT CALLBACK Form (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Stream (HWND, UINT, WPARAM, LPARAM);

7) Then go in WndProc in switch(WmId) write the following code below file exit:

case ID_FORM_APPLN:
DialogBox(hInst, (LPCTSTR)IDD_FORM, hWnd, (DLGPROC)Form);
break;

8) Then write the following code for the Form dialog & Stream dialog after the
About code:

LRESULT CALLBACK Form(HWND hDlg, UINT message, WPARAM wParam,


LPARAM lParam)
{
RECT rt, rt1;
int DlgWidth, DlgHeight; // dialog width and height in pixel units
int NewPosX, NewPosY;
HWND hWnd;

switch (message)
{
case WM_INITDIALOG:
// trying to center the About dialog
if (GetWindowRect(hDlg, &rt1)) {
GetClientRect(GetParent(hDlg), &rt);
DlgWidth = rt1.right - rt1.left;
DlgHeight = rt1.bottom - rt1.top ;
NewPosX = (rt.right - rt.left - DlgWidth)/2;
NewPosY = (rt.bottom - rt.top - DlgHeight)/2;

// if the About box is larger than the physical screen


if (NewPosX < 0) NewPosX = 0;
if (NewPosY < 0) NewPosY = 0;
SetWindowPos(hDlg, 0, NewPosX, NewPosY,
0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
DialogBox(hInst, (LPCTSTR)IDD_STREAM, hDlg,
(DLGPROC)Stream);
return TRUE;
}
else if (LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}

LRESULT CALLBACK Stream(HWND hDlg, UINT message, WPARAM wParam,


LPARAM lParam)
{
RECT rt, rt1;
int DlgWidth, DlgHeight; // dialog width and height in pixel units
int NewPosX, NewPosY;

switch (message)
{
case WM_INITDIALOG:
// trying to center the About dialog
if (GetWindowRect(hDlg, &rt1)) {
GetClientRect(GetParent(hDlg), &rt);
DlgWidth = rt1.right - rt1.left;
DlgHeight = rt1.bottom - rt1.top ;
NewPosX = (rt.right - rt.left - DlgWidth)/2;
NewPosY = (rt.bottom - rt.top - DlgHeight)/2;

// if the About box is larger than the physical screen


if (NewPosX < 0) NewPosX = 0;
if (NewPosY < 0) NewPosY = 0;
SetWindowPos(hDlg, 0, NewPosX, NewPosY,
0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
return TRUE;

case WM_COMMAND:
if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) ==
IDCANCEL))
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}

9) The execute the code by pressing F5 .


Practical 8
“ Rectangle & Ellipse ”

Steps:

1) Click on new file select WCE Application, Give the name to the project, select next
then click finish.

2) Then in class view select the Global, in global select the WINPROC.

3) Then write the Following code in the WM_PAINT:

Rectangle(hdc,45,50,90,95);
Ellipse(hdc,110,110,160,160);

4) Then execute the code by pressing F5.


Practical 9
“ Change Background Colour “

Steps:

1) Click on new file select WCE Application, Give the name to the project, select next
then click finish.

2) Then in class view select the Global, in global select the WINPROC.

3) Then write the Following code in the WM_PAINT:

HBRUSH hbr;
hdc = BeginPaint(hWnd, &ps);
hdc=GetDC(hWnd);
hbr=CreateSolidBrush (RGB(rand(),rand(),rand()));
SelectObject (hdc,hbr);
GetClientRect(hWnd, &rt);
FillRect (hdc,&rt,hbr);;

4) Then execute the code by pressing F5.

You might also like