Jump to content
  • Advertisement
Sign in to follow this  
CRAZY COCONUT COW

Quick way to make my variable display font larger in CE

This topic is 4416 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In CE, So I got a dynamic variable x=time() displayed nicely in my dialog using SetDlgItemInt, but my boss wants the number display(font) to be huge. So I went off to the Forger's tutorial and copy some DC and font code into my source code. I compiled with evc++ and 70 errors come out. I thought CE API is exactly the same as WIndows 2000? The project needs to be completed fast and my windows api understanding is sketchy, Is there any fast code to make my variable x display font larger? Or I must use Device Context? Links? **************I add this stuff from Forger's code into my program HFONT g_hfFont = NULL; BOOL g_bOpaque = TRUE; COLORREF g_rgbText = RGB(0, 0, 0); COLORREF g_rgbBackground = RGB(255, 255, 255); COLORREF g_rgbCustom[16] = {0}; void DoSelectFont(HWND hwnd) { CHOOSEFONT cf = {sizeof(CHOOSEFONT)}; LOGFONT lf; GetObject(g_hfFont, sizeof(LOGFONT), &lf); cf.Flags = CF_EFFECTS | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS; cf.hwndOwner = hwnd; cf.lpLogFont = &lf; cf.rgbColors = g_rgbText; if(ChooseFont(&cf)) { HFONT hf = CreateFontIndirect(&lf); if(hf) { g_hfFont = hf; } else { MessageBox(hwnd, "Font creation failed!", "Error", MB_OK | MB_ICONEXCLAMATION); } g_rgbText = cf.rgbColors; } } void DoSelectColour(HWND hwnd) { CHOOSECOLOR cc = {sizeof(CHOOSECOLOR)}; cc.Flags = CC_RGBINIT | CC_FULLOPEN | CC_ANYCOLOR; cc.hwndOwner = hwnd; cc.rgbResult = g_rgbBackground; cc.lpCustColors = g_rgbCustom; if(ChooseColor(&cc)) { g_rgbBackground = cc.rgbResult; } } void DrawClientSize(HDC hdc, RECT* prc, HFONT hf) { char szSize[100]; char szTitle[] = "These are the dimensions of your client area:"; HFONT hfOld = SelectObject(hdc, hf); SetBkColor(hdc, g_rgbBackground); SetTextColor(hdc, g_rgbText); if(g_bOpaque) { SetBkMode(hdc, OPAQUE); } else { SetBkMode(hdc, TRANSPARENT); } DrawText(hdc, szTitle, -1, prc, DT_WORDBREAK); wsprintf(szSize, "{%d, %d, %d, %d}", prc->left, prc->top, prc->right, prc->bottom); DrawText(hdc, szSize, -1, prc, DT_SINGLELINE | DT_CENTER | DT_VCENTER); SelectObject(hdc, hfOld); } *********************In winproc I add case ID_FORMAT_TEST: { HFONT hf; HDC hdc; long lfHeight; hdc = GetDC(NULL); lfHeight = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72); ReleaseDC(NULL, hdc); hf = CreateFont(lfHeight, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, "Times New Roman"); if(hf) { DeleteObject(g_hfFont); g_hfFont = hf; } else { MessageBox(hwnd, "Font creation failed!", "Error", MB_OK | MB_ICONEXCLAMATION); } InvalidateRect(hwnd, NULL, TRUE); UpdateWindow(hwnd); } break; case ID_FORMAT_BACKGROUNDCOLOUR: DoSelectColour(hwnd); InvalidateRect(hwnd, NULL, TRUE); UpdateWindow(hwnd); break; case ID_FORMAT_OPAQUE: g_bOpaque = !g_bOpaque; InvalidateRect(hwnd, NULL, TRUE); UpdateWindow(hwnd); break; } break; case WM_INITMENUPOPUP: CheckMenuItem((HMENU)wParam, ID_FORMAT_OPAQUE, MF_BYCOMMAND | ( g_bOpaque ? MF_CHECKED : MF_UNCHECKED)); break; case WM_PAINT: { RECT rcClient; PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rcClient); DrawClientSize(hdc, &rcClient, g_hfFont); EndPaint(hwnd, &ps); } ********errors I got 'CHOOSEFONT' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(16) : error C2146: syntax error : missing ';' before identifier 'cf' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(16) : error C2065: 'cf' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(16) : error C2059: syntax error : '{' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(17) : error C2275: 'LOGFONTW' : illegal use of this type as an expression C:\Windows CE Tools\wce300\Pocket PC 2002\include\wingdi.h(70) : see declaration of 'LOGFONTW' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(17) : error C2146: syntax error : missing ';' before identifier 'lf' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(17) : error C2065: 'lf' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(21) : error C2224: left of '.Flags' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(21) : error C2065: 'CF_EFFECTS' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(21) : error C2065: 'CF_INITTOLOGFONTSTRUCT' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(21) : error C2065: 'CF_SCREENFONTS' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(22) : error C2224: left of '.hwndOwner' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(23) : error C2224: left of '.lpLogFont' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(24) : error C2224: left of '.rgbColors' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(26) : warning C4013: 'ChooseFont' undefined; assuming extern returning int C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(28) : warning C4133: 'function' : incompatible types - from 'int *' to 'const struct tagLOGFONTW *' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(35) : warning C4133: 'function' : incompatible types - from 'char [22]' to 'const unsigned short *' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(35) : warning C4133: 'function' : incompatible types - from 'char [6]' to 'const unsigned short *' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(38) : error C2224: left of '.rgbColors' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(44) : error C2065: 'CHOOSECOLOR' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(44) : error C2146: syntax error : missing ';' before identifier 'cc' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(44) : error C2065: 'cc' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(44) : error C2059: syntax error : '{' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(46) : error C2224: left of '.Flags' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(46) : error C2065: 'CC_RGBINIT' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(46) : error C2065: 'CC_FULLOPEN' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(46) : error C2065: 'CC_ANYCOLOR' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(47) : error C2224: left of '.hwndOwner' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(48) : error C2224: left of '.rgbResult' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(49) : error C2224: left of '.lpCustColors' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(51) : warning C4013: 'ChooseColor' undefined; assuming extern returning int C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(53) : error C2224: left of '.rgbResult' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(75) : warning C4133: 'function' : incompatible types - from 'char [46]' to 'const unsigned short *' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(77) : warning C4133: 'function' : incompatible types - from 'char [100]' to 'unsigned short *' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(77) : warning C4133: 'function' : incompatible types - from 'char [17]' to 'const unsigned short *' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(78) : warning C4133: 'function' : incompatible types - from 'char [100]' to 'const unsigned short *' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(88) : error C2065: 'DEFAULT_GUI_FONT' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(119) : warning C4013: 'MulDiv' undefined; assuming extern returning int C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(122) : warning C4013: 'CreateFont' undefined; assuming extern returning int C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(122) : warning C4047: '=' : 'struct HFONT__ *' differs in levels of indirection from 'int ' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(131) : warning C4133: 'function' : incompatible types - from 'char [22]' to 'const unsigned short *' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(131) : warning C4133: 'function' : incompatible types - from 'char [6]' to 'const unsigned short *' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(180) : warning C4028: formal parameter 3 different from declaration C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(181) : error C2065: 'WNDCLASSEX' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(181) : error C2146: syntax error : missing ';' before identifier 'wc' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(181) : error C2065: 'wc' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(182) : error C2275: 'HWND' : illegal use of this type as an expression C:\Windows CE Tools\wce300\Pocket PC 2002\include\windef.h(201) : see declaration of 'HWND' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(182) : error C2146: syntax error : missing ';' before identifier 'hwnd' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(182) : error C2065: 'hwnd' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(183) : error C2275: 'MSG' : illegal use of this type as an expression C:\Windows CE Tools\wce300\Pocket PC 2002\include\winuser.h(28) : see declaration of 'MSG' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(183) : error C2146: syntax error : missing ';' before identifier 'Msg' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(183) : error C2065: 'Msg' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(185) : error C2224: left of '.cbSize' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(186) : error C2224: left of '.style' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(187) : error C2224: left of '.lpfnWndProc' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(188) : error C2224: left of '.cbClsExtra' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(189) : error C2224: left of '.cbWndExtra' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(190) : error C2224: left of '.hInstance' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(191) : error C2224: left of '.hIcon' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(191) : error C2065: 'IDI_APPLICATION' : undeclared identifier C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(191) : warning C4047: 'function' : 'const unsigned short *' differs in levels of indirection from 'int ' C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(191) : warning C4024: 'LoadIconW' : different types for formal and actual parameter 2 C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(192) : error C2224: left of '.hCursor' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(193) : error C2224: left of '.hbrBackground' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(194) : error C2224: left of '.lpszMenuName' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(195) : error C2224: left of '.lpszClassName' must have struct/union type C:\Documents and Settings\francis\Desktop\misc\sourcecode\source\font_one\font_one.c(196) : error C2224: left of '.hIconSm' must have struct/union type

Share this post


Link to post
Share on other sites
Advertisement
This article in MSDN should help you get started

To answer your question, no, the CE API is not like the regular WinAPI. Certain things, such as CHOOSEFONT, do not exist under CE. Before blindy pasting other peoples code, it usually is a good idea to check the documentation that comes with Embedded Visual C++ to make sure you have a capability. If not, you have to look for alternatives.

Also, once again, you need Unicode. That's explaining why your functions which take strings, the compiler is barfing, stating that it wants const unsigned short*.

Also, you never want to use a wide character operation on a single character array, and vice versa. TCHAR, not char, and not wchar_t.

_T("My Text Goes Here")

And for future reference, please put your code in [source][/source] blocks to make it more readable.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Very very helpful document, I can finally sleep, you are the greatest!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!