#include "ApplicationInterface.h" #include #include #include #include "resource.h" HINSTANCE g_hInst; // The current instance HWND g_hWnd; // The main window HWND g_hwndCB; // The command bar handle HDC hdc; // Only valid when painting HBRUSH background; HFONT navFont; // For navigation HFONT textFont; // For navigation int font; // Current font id HFONT defaultFont; void initApplicationInterface() { font=FONT_DEFAULT; LOGFONT fontSpecs; memset(&fontSpecs,0,sizeof(fontSpecs)); fontSpecs.lfHeight=-10; fontSpecs.lfWeight=200; fontSpecs.lfPitchAndFamily=FF_ROMAN; fontSpecs.lfQuality=5; navFont=CreateFontIndirect(&fontSpecs); fontSpecs.lfHeight=-12; textFont=CreateFontIndirect(&fontSpecs); background=(HBRUSH) GetStockObject(WHITE_BRUSH); } void loadString(UINT id, LPTSTR buffer) { LoadString(g_hInst, id, buffer, MAX_LOADSTRING); } UString loadString(UINT id) { TCHAR chars[MAX_LOADSTRING]; loadString(id,chars); return UString(chars); } void setTitle(UString title) { SetWindowText(g_hWnd,title.c_str()); } void refreshScreen() { InvalidateRect(g_hWnd, NULL, TRUE); UpdateWindow(NULL); } void drawText(RECT* rt, UString text) { drawText(rt,text.c_str(), text.length()); } void drawRText(RECT* rt, UString text) { drawRText(rt,text.c_str(), text.length()); } int drawVerseText(RECT* rt, UString text) { RECT tmp=*rt; tmp.left+=1; DrawText(hdc, text.c_str(),text.length(),&tmp,DT_LEFT|DT_WORDBREAK); DrawText(hdc, text.c_str(),text.length(),&tmp,DT_LEFT|DT_WORDBREAK|DT_CALCRECT); return (tmp.bottom)-(tmp.top); } void setFont(int id) { HFONT newFont; switch (id) { case FONT_NAVIGATION: newFont=navFont; break; case FONT_TEXT: newFont=textFont; break; default: id=FONT_DEFAULT; newFont=defaultFont; } if ((font==FONT_DEFAULT)&&(id!=FONT_DEFAULT)) //let's remember the default font defaultFont=(HFONT)SelectObject(hdc,newFont); else if (font!=id) SelectObject(hdc,newFont); } void selectMenu(int mode) { setMenuSelected(g_hwndCB,MENU_BOOK,(mode==MENU_BOOK)); setMenuSelected(g_hwndCB,MENU_CHAP,(mode==MENU_CHAP)); setMenuSelected(g_hwndCB,MENU_VERSE,(mode==MENU_VERSE)); setMenuSelected(g_hwndCB,MENU_TEXT,(mode==MENU_TEXT)); setMenuSelected(g_hwndCB,MENU_FIND,(mode==MENU_FIND)); } void addMenu(HMENU menu, int id, UString text) { AppendMenu(menu,0,USERBUTTONS+id,text.c_str()); } void checkMenu(HMENU menu, int id, bool checked) { CheckMenuItem(menu,USERBUTTONS+id,checked?MF_CHECKED:MF_UNCHECKED); }