Is it possible to set a font to a msgInfo.
Thanks in advance
Otto
Is it possible to set a font to a msgInfo.
Thanks in advance
Otto
FW msgbox and other msg* functions in turn call Windows MessageBox API function, which in turn uses system fonts set by user.
////////////////////////////////////////////
// MyMessages.Prg
//
// A collection of messages functions
/////////////////////////////////////////////////////
*
#INCLUDE "FiveWin.CH"
#xcommand DEFAULT <v1> TO <x1> [, <vn> TO <xn> ] ;
=> ;
IF <v1> == NIL ; <v1> := <x1> ; END ;
[; IF <vn> == NIL ; <vn> := <xn> ; END ]
*
*
/* Standard icon resource IDs */
#define IDI_APPLICATION 32512
#define IDI_HAND 32513
#define IDI_QUESTION 32514
#define IDI_EXCLAMATION 32515
#define IDI_INFORMATION 32516
#define IDI_WIN 32517
#define COLOR_BTNFACE 15
#ifdef __CLIPPER__
#define EM_SETSEL (WM_USER+1)
#else
#define EM_SETSEL 177
#endif
*
#Define TIPO_MSGINFO "1"
#Define TIPO_MSGRUN "2"
#Define TIPO_ALERT "3"
#Define TIPO_MSGYESNO "4"
#Define TIPO_MSGNOYES "5"
*
#Define LISTA_ICONOS_EN_EJECUTABLE Upper("ProgIco")
*
//-------------------------------------------------------------------------//
CLASS TMsg
DATA cTipo
DATA cTitle
DATA cMsg
DATA oFont
DATA oFontBtn
DATA lFontInterno HIDDEN
DATA xIcon
DATA aOptions
DATA oDlg
DATA lModal HIDDEN
METHOD New()
METHOD Activate()
METHOD DlgInit HIDDEN
DATA nDefault
METHOD Default HIDDEN
DATA oPrompt
DATA lTerminar INIT .F.
DATA nStyle
DATA oIcon
DATA lBtnCancelar INIT .F. HIDDEN
DATA bActionCancelar INIT NIL HIDDEN
ENDCLASS
////////////////////////////////////////////////////////////
METHOD New(cTipo)
IF Empty(cTipo)
MsgInfo("Falta cTipo", cTipo)
ENDIF
::cTipo := cTipo
::Default()
RETURN Self
///////////////////////////////////////
METHOD Default
DO CASE
CASE ::cTipo == TIPO_MSGINFO
DEFAULT ::aOptions:= {"&Aceptar"}
DEFAULT ::xIcon:= IDI_INFORMATION
CASE ::cTipo == TIPO_MSGYESNO
DEFAULT ::aOptions:= {oemtoansi("&Yes"), "&No"}
DEFAULT ::xIcon:= IDI_QUESTION
DEFAULT ::nDefault:= 1
CASE ::cTipo == TIPO_MSGNOYES
DEFAULT ::aOptions:= {oemtoansi("&Yes"), "&No"}
DEFAULT ::xIcon:= IDI_QUESTION
DEFAULT ::nDefault:= 2
CASE ::cTipo == TIPO_MSGRUN
DEFAULT ::xIcon:= IDI_WIN
IF ::lBtnCancelar
IF Empty(::aOptions)
::aOptions:= {oemtoansi("&Cancel")}
ENDIF
ENDIF
ENDCASE
DEFAULT ::aOptions:= {}
DEFAULT ::cTitle:= OemToAnsi("Attention")
DEFAULT ::cMsg := OemToAnsi("Attention message")
DEFAULT ::lFontInterno:= .f.
DEFAULT ::nDefault:= 1
*
RETURN NIL
*
//-------------------------------------------------------------------------//
METHOD Activate()
Local oPorError:= Self
Local oFlash
::Default()
IF ValType(::cTitle) != "C"
MsgInfo("Wrong title", ::cTitle)
ENDIF
IF ::oFont == NIL
DEFINE FONT ::oFont NAME GetSysFont() SIZE NIL, -14
::lFontInterno:= .t.
ENDIF
IF ::oFontBtn == NIL
::oFontBtn:= ::oFont
ENDIF
IF ::xIcon == NIL
IF ::cTipo == TIPO_ALERT
IF Len(::aOptions) > 1
::xIcon:= IDI_QUESTION
ELSE
::xIcon:= IDI_EXCLAMATION
ENDIF
ENDIF
ENDIF
IF Empty(::aOptions)
IF ::cTipo $ TIPO_ALERT+ TIPO_MSGYESNO+ TIPO_MSGNOYES
MsgInfo("Missing aOptions", ::aOptions)
ENDIF
ENDIF
::lModal:= !(::cTipo $ TIPO_MSGRUN)
IF !::lModal
#Define STYLE_CAPTION WS_CAPTION
DEFINE DIALOG ::oDlg TITLE ::cTitle FONT ::oFont ;
STYLE If(::nStyle != NIL, ::nStyle, STYLE_CAPTION)
ELSE
DEFINE DIALOG ::oDlg TITLE ::cTitle FONT ::oFont
ENDIF
::oDlg:Cargo := 0
::oDlg:lHelpIcon := .f.
IF !::lModal
ACTIVATE DIALOG ::oDlg ;
ON INIT (oPorError:DlgInit()) ;
NOWAIT ;
VALID oPorError:lTerminar
SysRefresh() // Important
ELSE
ACTIVATE DIALOG ::oDlg ;
ON INIT (;
oPorError:DlgInit(),;
NIL;
)
IF oFlash != NIL
oFlash:End()
oFlash:= NIL
ENDIF
ENDIF
IF ::lFontInterno
::oFont:End()
ENDIF
RETURN ::oDlg:Cargo
//-----------------------------------------------------------------//
METHOD DlgInit()
Local oGet:= nil, oBtn, oIcon
Local cSay, cLine
Local nMaxWidth, nMaxHeight, nWidth, nHeight, nLines, nFor
Local nBtnWidth, nBtnOffset, nBtnHeight, nBtnLength
Local lHScroll, lVScroll
Local aBotones:= {}
Local hBmp
Local nEspecial
if ValType( ::cMsg ) != "C"
::cMsg = cValToChar( ::cMsg )
endif
cSay := ""
nMaxWidth := 0
nMaxHeight := 0
nLines := MlCount(::cMsg, 254)
lHScroll := .f.
lVScroll := .f.
FOR nFor := 1 TO nLines
cLine := Trim(Memoline(::cMsg, 254, nFor))
cSay += cLine+CRLF
nMaxHeight += ::oDlg:nGetChrHeight()
nMaxWidth := Max(nMaxWidth, ::oDlg:GetWidth(cLine, ::oFont)+10)
NEXT
IF ::xIcon != Nil
IF Valtype(::xIcon) == "C" .AND.;
! (Upper(::xIcon) $ LISTA_ICONOS_EN_EJECUTABLE) // They are in .exe
IF File(::xIcon)
@ 20/14, 18/8 ICON ::oIcon FILE ::xIcon OF ::oDlg
ELSE
@ 20/14, 18/8 ICON ::oIcon RESOURCE ::xIcon OF ::oDlg
ENDIF
ELSE
@ 20/14, 18/8 ICON ::oIcon OF ::oDlg
IF ValType(::xIcon) == "N"
::oIcon:hIcon := LoadIcon(0, ::xIcon)
ELSE
::oIcon:hIcon := LoadIcon(GetInstance(), "ProgIco")
ENDIF
ENDIF
ELSE
@ 20/14, 18/8 ICON ::oIcon OF ::oDlg
::oIcon:hIcon := LoadIcon(0, IDI_EXCLAMATION)
ENDIF
nWidth := nMaxWidth
nHeight := nMaxHeight
if nHeight > 400
nHeight := 400
lVScroll := .t.
endif
#Define NUEVO_WIDTH 800
if nWidth > NUEVO_WIDTH
nWidth := NUEVO_WIDTH
lHScroll := .t.
lVScroll := .t.
endif
if lVScroll
nHeight := Max(100, nHeight)
endif
DO CASE
CASE lHScroll .and. lVScroll
@ 25, 70 GET oGet VAR cSay OF ::oDlg READONLY MEMO;
SIZE nWidth, nHeight PIXEL FONT ::oFont ;
COLOR NIL, GetSysColor( COLOR_BTNFACE ) ;
NOBORDER HSCROLL
CASE lHScroll .and. !lVScroll
@ 25, 70 GET oGet VAR cSay OF ::oDlg READONLY MEMO;
SIZE nWidth, nHeight PIXEL FONT ::oFont ;
COLOR NIL, GetSysColor( COLOR_BTNFACE ) ;
NOBORDER HSCROLL NO VSCROLL
CASE !lHScroll .and. lVScroll
@ 25, 70 GET oGet VAR cSay OF ::oDlg READONLY MEMO;
SIZE nWidth, nHeight PIXEL FONT ::oFont ;
COLOR NIL, GetSysColor( COLOR_BTNFACE ) ;
NOBORDER
OTHERWISE
@ 25, 70 GET oGet VAR cSay OF ::oDlg READONLY MEMO;
SIZE nWidth, nHeight PIXEL FONT ::oFont ;
COLOR NIL, GetSysColor( COLOR_BTNFACE ) ;
NOBORDER NO VSCROLL
END CASE
IF oGet != NIL
oGet:bMMoved := {|| DestroyCaret()}
oGet:bGotFocus := {|| PostMessage(oGet:hWnd, EM_SETSEL, 0, 0)}
ENDIF
nMaxWidth := Max(nWidth + 80, ::oDlg:GetWidth(::cTitle) + 30)
nBtnWidth := 50
FOR nFor := 1 TO len(::aOptions)
nBtnWidth := Max(nBtnWidth, ::oDlg:GetWidth(::aOptions[nFor], ::oFontBtn)+50)
NEXT
nBtnHeight := Max(nHeight, 20) + 50
#Define LARGO_BOTON ((::oFontBtn:nHeight)* 1.7)
nMaxHeight:= LARGO_BOTON+ nBtnHeight
nMaxHeight+= 40
IF Empty(::aOptions)
nMaxHeight:= nBtnHeight+ 30
ENDIF
nBtnLength := (len(::aOptions) * nBtnWidth) + ( (len(::aOptions) + 2 ) * 7)
if nBtnLength > nMaxWidth
nMaxWidth := nBtnLength + 10
endif
nBtnOffset := (nMaxWidth - (len(::aOptions)*nBtnWidth) - (len(::aOptions)+2*7)) / 2
FOR nFor := 1 TO len(::aOptions)
nEspecial:= 0
@ nBtnHeight,;
nEspecial+ nBtnOffset + (nBtnWidth*(nFor-1)) + ((nFor-1)*7) ;
BUTTON oBtn PROMPT ::aOptions[nFor] ;
PIXEL SIZE nBtnWidth, LARGO_BOTON ;
OF ::oDlg FONT ::oFontBtn
oBtn:bAction := GenBlock( ::oDlg, nFor, ::cTitle, ::bActionCancelar)
Aadd(aBotones, oBtn)
NEXT nFor
#Define ULT_ (Len(::aOptions))
IF Len(::aOptions) > 1
aBotones[1]:bLostFocus:=;
{|| If((GetFocus() == oGet:hWnd .OR. GetFocus() == ::oIcon:hWnd) .AND. (GetKeyState(VK_LEFT) .OR. GetKeyState(VK_UP)),;
( ForceFocus(aBotones[ULT_])), nil)}
aBotones[ULT_]:bLostFocus:=;
{|| If((GetFocus() == oGet:hWnd .OR. GetFocus() == ::oIcon:hWnd) .AND. (GetKeyState(VK_RIGHT) .OR. GetKeyState(VK_DOWN)),;
( ForceFocus(aBotones[1])),;
NIL;
)}
ENDIF
IF !Empty(::aOptions)
::oDlg:bStart := {|| ::oDlg:aControls[::nDefault+ 1]:SetFocus()}
ENDIF
*
*
#Define BOTTOM_MARGEN 20
DlgSetSize(::oDlg, 10, BOTTOM_MARGEN)
WndCenter(::oDlg:hWnd)
::oPrompt:= oGet
RETURN NIL
//-----------------------------------------------------------------//
STATIC FUNCTION GenBlock(oDlg, nElem, cTitle, bActionCancelar)
#Define NORMAL_ (oDlg:Cargo := nElem, oDlg:End())
#Define ACTION_CANCELAR If(bActionCancelar == NIL, NIL, Eval(bActionCancelar) )
RETURN { || ACTION_CANCELAR, NORMAL_ }
RETURN NIL
*
*
////////////////////////////////////////
FUNCTION MyMsgInfo(cMsg, cTitle)
Local oMsg
Local oFont, oFontBtn
*
DEFINE FONT oFont NAME GetSysFont() SIZE NIL, -18
DEFINE FONT oFontBtn NAME GetSysFont() SIZE NIL, -15
*
oMsg:= TMsg():New(TIPO_MSGINFO)
oMsg:cMsg := cMsg
oMsg:cTitle:= cTitle
omsg:oFont:= oFont
omsg:oFontBtn:= oFontBtn
*
oMsg:Activate()
oFont:End()
RETURN NIL
*
*
//-------------------------------------------------------------------------//
FUNCTION MyAlert(cMsg, aOptions, cTitle, nDefault, xIcon)
Local oMsg
Local oFont, oFontBtn
Local nOpcion
*
*
DEFAULT aOptions:= {"Ok"}
*
DEFINE FONT oFont NAME GetSysFont() SIZE NIL, -18
DEFINE FONT oFontBtn NAME "Courier" SIZE NIL, -15
oMsg:= TMsg():New(TIPO_ALERT)
oMsg:cMsg := cMsg
oMsg:cTitle:= cTitle
oMsg:aOptions:= aOptions
omsg:oFont:= oFont
omsg:oFontBtn:= oFontBtn
oMsg:nDefault:= nDefault
*
oMsg:Activate()
nOpcion:= oMsg:oDlg:Cargo
oFont:End()
oFontBtn:End()
RETURN nOpcion
*
*
*
//-------------------------------------------------------------------------//
FUNCTION MyMsgYesNoBis(cMsg, cTitle, lDefaultYes)
Local l
*
DEFAULT lDefaultYes:= .t.
*
IF lDefaultYes
l:= MyMsgYesNo(cMsg, cTitle)
ELSE
l:= MyMsgNoYes(cMsg, cTitle)
ENDIF
RETURN l
*
//-------------------------------------------------------------------------//
FUNCTION MyMsgYesNo(cMsg, cTitle)
Local oMsg
Local oFont, oFontBtn
Local nOpcion
*
*
DEFINE FONT oFont NAME GetSysFont() SIZE NIL, -18
DEFINE FONT oFontBtn NAME GetSysFont() SIZE NIL, -15
*
*
oMsg:= TMsg():New(TIPO_MSGYESNO)
oMsg:cMsg := cMsg
oMsg:cTitle:= cTitle
omsg:oFont:= oFont
omsg:oFontBtn:= oFontBtn
*
oMsg:Activate()
nOpcion:= oMsg:oDlg:Cargo
*
oFont:End()
oFontBtn:End()
RETURN nOpcion == 1
*
*
//-------------------------------------------------------------------------//
FUNCTION MyMsgNoYes(cMsg, cTitle)
Local oMsg
Local oFont, oFontBtn
Local nOpcion
*
DEFINE FONT oFont NAME GetSysFont() SIZE NIL, -18
DEFINE FONT oFontBtn NAME GetSysFont() SIZE NIL, -15
*
*
oMsg:= TMsg():New(TIPO_MSGNOYES)
oMsg:cMsg := cMsg
oMsg:cTitle:= cTitle
omsg:oFont:= oFont
omsg:oFontBtn:= oFontBtn
*
oMsg:Activate()
nOpcion:= oMsg:oDlg:Cargo
*
oFont:End()
oFontBtn:End()
RETURN nOpcion == 1
*
*
//-------------------------------------------------------------------------//
STATIC FUNCTION ForceFocus(oJump)
Local oFocus:= oWndFromHwnd(GetFocus())
Local bValid, bWhen
*
IF If(oFocus != NIL, oFocus:hWnd != oJump:hWnd, .t.)
*
IF oFocus != NIL
bWhen:= oFocus:bWhen
bValid:= oFocus:bValid
oFocus:bWhen:= {|| .f. }
oFocus:bValid:= {|| .t.}
ENDIF
*
*
IF __ObjHasMethod(oJump, "FORWHEN")
oJump:ForWhen()
ENDIF
*
*
oJump:SetFocus()
*
IF oFocus != NIL
IF !(oFocus:ClassName() $ "TWINDOW,TDIALOG")
IF bWhen == NIL
oFocus:bWhen:= {|| .t. }
*
ELSE
oFocus:bWhen := bWhen
ENDIF
oFocus:ForWhen()
ENDIF
*
oFocus:bWhen := bWhen
oFocus:bValid:= bValid
ENDIF
*
ENDIF
*
RETURN NIL
*