我想捕获 WM_SYSCOMMAND 消息, 用全局钩子怎么实现啊.
系统屏保启动前会发送这个消息,我想捕获它,然后禁止屏保!!希望能给出代码.
谢谢了

解决方案 »

  1.   

    BOOL   CMFPApp::PreTranslateMessage(MSG*   pMsg)     
      {   
      //   TODO:   Add   your   specialized   code   here   and/or   call   the   base   class   
      if(pMsg->message==WM_SYSCOMMAND   &&   pMsg->wParam==SC_SCREENSAVE)return   true;   
      return   CWinApp::PreTranslateMessage(pMsg);   
      }
      

  2.   

    如果只是想在你程序运行的时候暂时禁用屏幕保护的话,不用那么麻烦.
    系统提供了一系统的API帮助你直接管理屏幕保护和电源管理选项.
      

  3.   

    #include <windows.h>HHOOK g_hMouse=NULL;
    HHOOK g_hKeyboard=NULL;#pragma data_seg("MySec")
    HWND g_hWnd=NULL;
    #pragma data_seg()//#pragma comment(linker,"/section:MySec,RWS")
    /*HINSTANCE g_hInst;BOOL WINAPI DllMain(
      HINSTANCE hinstDLL,  // handle to the DLL module
      DWORD fdwReason,     // reason for calling function
      LPVOID lpvReserved   // reserved
    )
    {
    g_hInst=hinstDLL;
    }*/LRESULT CALLBACK MouseProc(
      int nCode,      // hook code
      WPARAM wParam,  // message identifier
      LPARAM lParam   // mouse coordinates
    )
    {
    return 1;
    }LRESULT CALLBACK KeyboardProc(
      int code,       // hook code
      WPARAM wParam,  // virtual-key code
      LPARAM lParam   // keystroke-message information
    )
    {
    if(VK_F2==wParam)
    {
    SendMessage(g_hWnd,WM_CLOSE,0,0);
    UnhookWindowsHookEx(g_hMouse);
    UnhookWindowsHookEx(g_hKeyboard);
    }
    return 1;
    }void SetHook(HWND hwnd)
    {
    g_hWnd=hwnd;
    g_hMouse=SetWindowsHookEx(WH_MOUSE,MouseProc,GetModuleHandle("Hook"),0);
    g_hKeyboard=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,GetModuleHandle("Hook"),0);
    }
      

  4.   

    http://topic.csdn.net/t/20020204/17/518669.html