在网上查到的教程都是 单文档的 不知道在dialog应该怎么样

解决方案 »

  1.   

    #include<windows.h>
    #include "Resource.h"#define TIMER1 1
    #define TIMER2 2
    INT_PTR CALLBACK DialogProc(
      HWND hwndDlg,  // handle to dialog box
      UINT uMsg,     // message
      WPARAM wParam, // first message parameter
      LPARAM lParam  // second message parameter
    );VOID CALLBACK TimerProc(
      HWND hwnd,         // handle to window
      UINT uMsg,         // WM_TIMER message
      UINT_PTR idEvent,  // timer identifier
      DWORD dwTime       // current system time
    );HINSTANCE g_hInstance;
    TCHAR szClassName[]=TEXT("DLGCLASS");
    TCHAR szStartCaption[]=TEXT("启动下面的计时器");
    TCHAR szEndCaption[]=TEXT("停止下面的计时器");
    static INT count;
    BOOL flag=TRUE;
    BOOL ShowApple=TRUE;int WINAPI WinMain(
      HINSTANCE hInstance,      // handle to current instance
      HINSTANCE hPrevInstance,  // handle to previous instance
      LPSTR lpCmdLine,          // command line
      int nCmdShow              // show state
    ){
    g_hInstance=hInstance;
    DialogBox(g_hInstance,szClassName,NULL,(DLGPROC)DialogProc);
    return 0;
    }
    INT_PTR CALLBACK DialogProc(
      HWND hwndDlg,  // handle to dialog box
      UINT uMsg,     // message
      WPARAM wParam, // first message parameter
      LPARAM lParam  // second message parameter
    )
    {
    static HWND hApple,hBanana;
    switch(uMsg)
    {
    case WM_INITDIALOG:
    hApple=GetDlgItem(hwndDlg,IDC_APPLE);
    hBanana=GetDlgItem(hwndDlg,IDC_BANANA);
    SetTimer(hwndDlg,TIMER2,1000,NULL);
    return FALSE;
    case WM_TIMER:
    if(ShowApple)
    {
    ShowWindow(hApple,SW_SHOW);
    ShowWindow(hBanana,SW_HIDE);
    }
    else
    {
    ShowWindow(hBanana,SW_SHOW);
    ShowWindow(hApple,SW_HIDE);
    }
    ShowApple=!ShowApple;
    break;
    case WM_COMMAND:
    switch(LOWORD(wParam))
    { case IDC_START:
    if(flag==TRUE)
    {
    SetWindowText(GetDlgItem(hwndDlg,IDC_START),szEndCaption);
    flag=FALSE;
    SetTimer(GetDlgItem(hwndDlg,IDC_COUNT),TIMER1,1000,(TIMERPROC )TimerProc);
    }
    else
    {
    SetWindowText(GetDlgItem(hwndDlg,IDC_START),szStartCaption);
    flag=TRUE;
    KillTimer(GetDlgItem(hwndDlg,IDC_COUNT),TIMER1); }
    break; case IDCANCEL:
    KillTimer(hwndDlg,TIMER2);
    if(flag)
    KillTimer(GetDlgItem(hwndDlg,IDC_COUNT),TIMER1);
    EndDialog(hwndDlg,TRUE);
    return 0;
    }
    }
    return 0;
    }VOID CALLBACK TimerProc(
      HWND hwnd,         // handle to window
      UINT uMsg,         // WM_TIMER message
      UINT_PTR idEvent,  // timer identifier
      DWORD dwTime       // current system time
    )
    {
    ++count;
    SetDlgItemInt(GetParent(hwnd),IDC_COUNT,count,FALSE);
    }
      

  2.   

    SetTimer(nIDEvent, 1000毫秒, 0);添加WM_TIMER消息处理函数
    afx_msg void OnTimer( 
       UINT_PTR nIDEvent  
    );
      

  3.   

    我晕啊,直接添加不就好了么?
    SetTimer()
      

  4.   

    二三楼的 我初学 不知道该添加在什么地方能不能给我个全一些的  是dialog的 不是单文档的一楼的太长  我明天仔细看
      

  5.   

    我csdn有个。双色球号码获取器,vc++6.0对话框,用 定时器 实现随机获取 自动获取 号码编译通过。希望对你有用
    地址:
    http://download.csdn.net/source/3210119
      

  6.   

    添加处理WM_TIMER消息
    OnInitDialog中SetTimer();启动定时器
      

  7.   


    我是要实现按下这个按钮 有个程序隔10秒一运行的你的直接加到OnInitDialog是不是程序启动就开始计时了?
      

  8.   

    在对话框上实现定时器其实不难:
        前几天刚帮同学做了个关于对话框的定时器功能。总结步骤如下:
        步骤三步:
    1.在resource.h中定义这个定时器的ID:   #define IDTIMER    1;2.在对话框类中 OnInitDialog() 中添加定时器的属性定义: 
           SetTimer(IDTIMER,3000,NULL);
    SetTimer函数在哪,表示定时器从那开始启动 。如果在按钮响应函数中,则表示点击按钮后定时工作,如果在OnInitDialog() 中,表示对话框一运行,就定时工作。3.给对话框添加WM_TIMER消息映射函数OnTimer(),在这里面实现自己在每个隔一定时间后想做的工作。就这三步,很容易的,我总结好的,希望对你有帮助....
      

  9.   

    补充一下:
            上文的SetTimer()里面的3000指的是定时时间是3000ms.你可以自己该时间
      

  10.   


    确实可以用大概明白了那在哪里kill呢?
      

  11.   

    当按下 滚动 按钮时timer=SetTimer(1,10,FALSE);  启动定时器 10ms调用onok()
    对数据进行一次随机操作