我现在需要在win2k上做一个小程序,要求是实时的作一些处理。所以我希望我的程序能尽可能的独占cpu而不被系统服务或者其他程序打断。各位高人能给我一些指点吗?谢谢!!

解决方案 »

  1.   

    怎么设置啊,我现在就是手工在任务管理器中设置,但是我想把它做进我的程序里,程序运行后自动将自己的优先器设置为实时?不知道该怎么设置。另外设置为实时后,win2k的系统服务,或者鼠标、键盘等中断就不会对我的程序产生干扰了吗??谢谢
      

  2.   

    To:DentistryDoctor
    提高优先级到实时,
    怎么做的?
    兄台有具件的API函数吗?
      

  3.   

    BOOL SetThreadPriority(
      HANDLE hThread,
      int nPriority
    );Priority Meaning 
    THREAD_PRIORITY_ABOVE_NORMAL Priority 1 point above the priority class. 
    THREAD_PRIORITY_BELOW_NORMAL Priority 1 point below the priority class. 
    THREAD_PRIORITY_HIGHEST Priority 2 points above the priority class. 
    THREAD_PRIORITY_IDLE Base priority of 1 for IDLE_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, or HIGH_PRIORITY_CLASS processes, and a base priority of 16 for REALTIME_PRIORITY_CLASS processes. 
    THREAD_PRIORITY_LOWEST Priority 2 points below the priority class. 
    THREAD_PRIORITY_NORMAL Normal priority for the priority class. 
    THREAD_PRIORITY_TIME_CRITICAL Base priority of 15 for IDLE_PRIORITY_CLASS, BELOW_NORMAL_PRIORITY_CLASS, NORMAL_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, or HIGH_PRIORITY_CLASS processes, and a base priority of 31 for REALTIME_PRIORITY_CLASS processes
      

  4.   

    用这个函数
    BOOL SetPriorityClass(
      HANDLE hProcess,        // handle to process
      DWORD dwPriorityClass   // priority class
    );
    把进程的Priority Class设成REALTIME_PRIORITY_CLASS
      

  5.   

    我的程序中没有用到多线程,setPriorityClass能用吗?setPriorityClass中的进程句柄我写什么呢?我的小程序是一个gialog,setPriorityClass应该加在那里呢?
      

  6.   

    加在InitInstance的AfxEnableControlContainer()后面
    BOOL CPriorityTestApp::InitInstance()
    {
    AfxEnableControlContainer();
    SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS);
    ......}
    再看进程管理器里面的优先级显示实时的了