Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

請問VC++的程式(關於計時的0

0 views
Skip to first unread message

風清揚

unread,
Aug 2, 2000, 3:00:00 AM8/2/00
to
問題在於Invalidate()事通知係同將畫面設為無效所以會重繪
but妳自己呼叫的話並沒有設為無效區阿
如你一定要如此的話改用CWindowDC dc(NULL);
dc.TextOut(10,10,"123");
你可在螢幕上任意位址繪圖只需注意是否為你想要或稍加修改邏輯位址(只改妳的view)

※ 引述《Poseid...@bbs.nkfu.edu.tw (Oceanus)》之銘言:
: //請問如下MFC程式: (問題在註解處...您不需要看完整篇程式,只是問個觀念...)
: #include <afxwin.h>
: #include "clockrc.h"
: #define TIMEID 1
: class MyFrameWindow : public CFrameWnd
: {
: public:
: MyFrameWindow ( )
: {
: if ( !Create ( NULL, "MFC Clock", WS_VISIBLE | WS_OVERLAPPEDWINDOW ) )
: return;
: if ( ! SetTimer ( TIMEID, 1000, NULL ) )
: {
: MessageBox ( "No more timer resource", "MFC Clock" );
: DestroyWindow();
: }
: }
: void GetTime ( char* tstr )
: {
: SYSTEMTIME t;
: GetLocalTime(&t);
: wsprintf ( tstr, "%02d:%02d:%02d", t.wHour, t.wMinute, t.wSecond );
: }
: afx_msg void OnTimer( UINT id )
: {
: char tstr[30];
: if ( id == TIMEID )
: {
: if ( IsIconic() )
: {
: GetTime ( tstr );
: SetWindowText ( tstr );
: }
: else
: Invalidate();//在下的問題在此,本行程式主要在強迫將工作區重繪,
: //也就是會叫用到OnPaint()函式,可是在下將本行程式 //改為OnPaint();卻會造成畫面時間無法更新,請問是
: //什麼原因呢?煩請不吝賜教,感激不盡!! 新手留...
: }
: }
: afx_msg void OnPaint( )
: {
: char tstr[30];
: CPaintDC paintDC( this );
: GetTime(tstr);
: paintDC.TextOut ( 0, 0, tstr );
: }
: afx_msg void OnSize( UINT nType, int cx, int cy )
: {
: CFrameWnd::OnSize ( nType, cx, cy );
: if ( ( nType != SIZE_MINIMIZED ) && ( nType != SIZE_MAXHIDE ) )
: SetWindowText ( "MFC Clock" );
: }
: DECLARE_MESSAGE_MAP()
: };
: BEGIN_MESSAGE_MAP(MyFrameWindow, CFrameWnd)
: ON_WM_TIMER()
: ON_WM_PAINT()
: ON_WM_SIZE()
: END_MESSAGE_MAP()
: class HelloApp : public CWinApp
: {
: public:
: HelloApp ( )
: : CWinApp ( "MFC Clock" )
: {}
: BOOL InitInstance( )
: {
: CFrameWnd *MyFrame = new MyFrameWindow;
: m_pMainWnd = MyFrame;
: MyFrame->SetIcon ( LoadIcon ( IDI_MYICON ), TRUE );
: return TRUE;
: }
: } MFCClock;

--
[1;36m※Post by [37mhorserider [36mfrom [33mnas6po183.ht.ficnet.net. [m
[1;34m▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ [m
[1;36m東吳溪城bbs站 [31m˙ [33m電子佈告欄系統 [31m˙ [32mbbs.scu.edu.tw [31m˙ [37m163.14.2.15 [m
[1;34m▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ [m

Jimmy Lee

unread,
Aug 3, 2000, 3:00:00 AM8/3/00
to
On 02 Aug 2000 13:59:05 GMT, horseri...@bbs.scu.edu.tw (風清揚)
wrote:

>問題在於Invalidate()事通知係同將畫面設為無效所以會重繪
>but妳自己呼叫的話並沒有設為無效區阿
>如你一定要如此的話改用CWindowDC dc(NULL);
>dc.TextOut(10,10,"123");
>你可在螢幕上任意位址繪圖只需注意是否為你想要或稍加修改邏輯位址(只改妳的view)

建議用 UpdateWindow, 請看看 Online help

- Jimmy

0 new messages