Windows CE BasicsWindows CE
is an operating system optimised for the embedded devices.It is a
subset of its parent OS windows which runs on desktops.Not all the
win32 API's are supprted by windows CE.But it has sufficient of them
to carry out most basic of oprations.If you have previously worked on
windows than working with windows CE is not that different.Only you
need to take of some new functions and procedures.And you need to
optimize your code so that it consumes less resources and executes in
shorter time.
WHERE to
START
Make sure
you know about the basics of windows CE.Like
1.WinCE
supports UNICODE programming model.
2.Study
about the GDI of Windows CE.GDI is the part of GWES(Graphics
Windowing and Event subsystem) which takes care of your all drawing
needs from drawing a single line to AlphaBlendind an bitmap image.
3.you
should know the basic flow of the program.When you build a non empty
smartdevice project from your visual studio,it will generate a code
which contains the basic skeleton of windows CE application.
a.Winmain
is the starting point of the program
int
WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int
nCmdShow)
b.Before
we create a window we need register its windows Class, which is done
by myregisterclass
function.Here
we can modify the styles of the window,background color etc.By
default background color is White.If we use HOLLOW_BRUSH instead of
WHITE_BRUSH than it will not paint our window.It will produce a
transparent window.We have to take care about painting and erasing
the window.
ATOM
MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;
wc.style
= CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc
= WndProc;
wc.cbClsExtra
= 0;
wc.cbWndExtra
= 0;
wc.hInstance
= hInstance;
wc.hIcon
= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NONAME));
wc.hCursor
= 0;
wc.hbrBackground
= (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName
= 0;
wc.lpszClassName
= szWindowClass;
return
RegisterClass(&wc);
}
c.After u
register you window class,it creates a window using CreateWindow
API.This function returns a handle to that window which is termed as
window handle(HWND).In this function we can give the initial position
,width and height of our window.
hWnd
= CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance,
NULL);
d.Than we
encounter the Message Loop.This is the Main part of the Code.Here all
the meesages sent by the os are dispatched and sent to Windows
Procedure.
while
(GetMessage(&msg, NULL, 0, 0))
{
if
(!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
f.As
explained before windows procedure is the one which gets all the
messages sent by the os.SO here we can see the switch statements are
used to take custom actions to the messages sent by the OS.There are
huge set of messages that u may receive from the OS.We need not to
take care about all of them.The DefWndProc at the default case
statement takes care about the unhandled windows messages
default:
return
DefWindowProc(hWnd, message, wParam, lParam);
}
return
0;
Now you
know the basic skeleton of the windows CE.Few more random important
points for the beginners.
1.Make
sure u delete all the HDC(handle to the Device Context) that u
created using createcompatibleDC api.If u got HDC from GetDC api u
should release the DC by calling releaseDC api.
2.If u r
trying to load a image into your application either from resource or
from remote path.Make sure that your image is 24bit bit wide .BMP
file.Winodows CE doesnt support loadind 32bit wide bmp images.U can
load images by either LoadImage() or ShloadBitmap() api's
3.AlphaBlend()
function returns zero if the size of the source provided in the
function mismatches with the original size of the source.What I mean
to say is that you cannot partially alphablend the source.
4.In order
to have flicker free controls in windows CE use Off-Screen DC.Do all
your drawings onto to an off-screen DC.Than later transfer the
contents from offscreen DC into the main DC usin BitBlt
function.Create off-Screen DC using createcompatibleDC function and
laod a compatible bitmap into it.Make sure you delete your Off-Screen
DC after you use it.
5.Windows
CE doesnt support alphablended windows.So we need to simulate the
alhablending effect.This can be achieved by capturing the screen
image using GetDC(NULL) and alpha blendind that with our windows
HDC.GetDC(NULL) returns the HDC of the current ScreenMake sure you
release the HDC which you got from GetDC function .
5.How to
remove the window startup animation?
Use
WS_EX_NOANIMATION flag in your createwindowEx function.This will
remove the animation and it will also remove the applications
reference from the task manager and taskbar.
6.How to
get our window on top of full screen video?
Use
WS_EX_TOPMOST flag in your createWindowEx function.
7.Child
Window X,Y position is with respect to parent window X,Y positions not with screen's X,Y positions.