Page 1 of 1

PostPosted: Fri Jan 24, 2003 12:43 am
by jdallamby
Can some kind soul point me to examples for modifying the font, fontsize
color etc used by the controls such as buttons end edits. I assume it is sendmsg, but can't find much info on control specific parameters

PostPosted: Fri Jan 24, 2003 8:21 am
by guy
The font is easy to change from PocketC. The colour is somewhat more difficult.

For the font you fill in a structure called a LOGFONT and then create a font from it. You then send a WM_SETFONT message to the control with sendmsg().

To do this you need the Windows CE API add-in library for PocketC which you can download from my signature below (it's free). There is an example program in there, font.pc, that sets the font on a static control:

Code: Select all
// Include standard Windows definitions

#include   "/pocketc/windows.h"

// Define a control ID for our test control

#define   ID_STATIC   100

main() {

   HFONT      hFont ;      // Font handle of our font
   LOGFONT      rLogfont ;   // Font structure to create font

//   Create a control to display text in the new font

   createctrl("STATIC", "", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_NOTIFY, 0, 40, 40, 200, 150, ID_STATIC) ;

//   Define the font that we want

   rLogfont.lfHeight      = 14 ;
   rLogfont.lfWidth      = 0 ;
   rLogfont.lfEscapement      = 0 ;
   rLogfont.lfOrientation      = 0 ;
   rLogfont.lfWeight      = FW_EXTRABOLD ;
   rLogfont.lfItalic      = TRUE ;
   rLogfont.lfUnderline      = FALSE ;
   rLogfont.lfStrikeOut      = FALSE ;
   rLogfont.lfCharSet      = ANSI_CHARSET ;
   rLogfont.lfOutPrecision      = OUT_DEFAULT_PRECIS ;
   rLogfont.lfClipPrecision   = CLIP_DEFAULT_PRECIS ;
   rLogfont.lfQuality      = DEFAULT_QUALITY ;
   rLogfont.lfPitchAndFamily   = DEFAULT_PITCH | FF_DONTCARE ;
   rLogfont.lfFaceName      = "Tahoma" ;

   Create the font and get a handle to it

   hFont = CreateFontIndirect(&rLogfont) ;

//   Set the font for the control


//   Put some text on the control

   editset(ID_STATIC, "Test text") ;

//   That's it. Normally you delete the font at the end of the program
//   but we'll leave it and let the user exit from the PocketC file menu

//   DeleteObject(hFont) ;


The HFONT and LOGFONT data types are #defined in the header file. HFONT is an int and LOGFONT is a struct.

WM_SETFONT is documented in the Microsoft online library at:

The CreateFontIndirect() function is documented at:

To change the the colour of a control you have to intercept Windows drawing of the control and change the colours that windows is going to use. If you use createctrl() and the standard PocketC event() loop to handle events then it's not possible to do this.

CEAPI provides a mechanism for defining the text, background and fill colours to be given to Windows when it is about to draw a control. In order to use this mechanism you have to create your controls with the real CreateWindow() API function and use a real Windows event loop using the GetMessage() and DispatchMessage() functions. This requires a substantial rewrite to existing programs, although new programs shouldn't be very much more difficult to write using a Windows event loop rather than a PocketC event loop.

There is an example program, winapp.pc, included with CEAPI that creates a button and colours it blue with white text. winapp contains a standard Windows event loop. Some of the menu code in winapp for the PocketPC requires an updated version of CEAPI which I should be releasing within a few days. There will be an announcement on the CEAPI forum and to the CEAPI mailing list when the update is available. Without the update the menus don't show up on PocketPC machines.

PocketC CE API interface:
PCForm and CE API forum: