6/24/10

Input an display and center ( MFC)

Buzz It
#include
#include
char str[100];
int textindex;
CFont e;
int fc;
CPoint textxy;
int showcaret;
LOGFONT m;
class myframe:public CFrameWnd
{
public:
myframe()
{
Create(0,"hello mfc",WS_OVERLAPPEDWS_CAPTIONWS_SYSMENUWS_MINIMIZEBOX,CRect(100,100,500,500));

showcaret= 0;
}
int selectfont()
{
CFontDialog f(&m);
if(f.DoModal()==IDCANCEL)
{
MessageBox("you have not selected any font","Atttention");
return 0;
}
e.CreateFontIndirect(&m);
fc=f.GetColor();
return 1;
}
void OnLButtonDown(UINT flags,CPoint p)
{
CClientDC d(this);
CreateSolidCaret(2,m.lfHeight );
showcaret=1;
textxy=p;
textindex=0;
SetCaretPos(CPoint(textxy.x,textxy.y-m.lfHeight));
ShowCaret();
}
void OnChar(UINT ch,UINT cnt,UINT flags)
{
if(showcaret==0)
{
return ;
}
if(ch==13textindex==99)
{
textindex=0;
HideCaret();
showcaret=0;
}
else
{
CClientDC d(this);
str[textindex]=ch;
CSize size=d.GetTextExtent(str,textindex);
HideCaret();
d.TextOut(textxy.x+size.cx,textxy.y,&str[textindex],1);
textindex++;
size=d.GetTextExtent(str,textindex);
SetCaretPos (CPoint(textxy.x+size.cx,textxy.y-m.lfHeight ));
ShowCaret();
}
}
void OnKillFocus(CWnd *w)
{
::DestroyCaret ();
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_CHAR()
ON_WM_LBUTTONDOWN()
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
int InitInstance()
{
myframe *p;
p=new myframe;
m_pMainWnd=p;
m_pMainWnd->ShowWindow(1);
return 1;
}
};
myapp a;





Output

0 comments:

Post a Comment