~ubuntu-branches/ubuntu/oneiric/psi/oneiric

« back to all changes in this revision

Viewing changes to src/win32/idleui.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2005-01-10 17:41:43 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050110174143-ltocv5zapl6blf5d
Tags: 0.9.3-1
* New upstream release
* Cleaned up debian/rules (some things are done by upstream Makefiles now)
* Fixed some lintian warnings:
  - removed executable bit from some .png files
  - moved psi.desktop to /usr/share/applications
* Updated menu files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
////////////////////////////////////////////////////////////////
2
 
// 2000 Microsoft Systems Journal. 
3
 
// If this program works, it was written by Paul DiLascia.
4
 
// If not, I don't know who wrote it.
5
 
// This program compiles with Visual C++ 6.0 on Windows 98
6
 
//
7
 
// See IdleUI.h
8
 
// 
9
 
 
10
 
#include<windows.h>
11
 
#include<assert.h>
12
 
 
13
 
#define DLLEXPORT __declspec(dllexport)
14
 
 
15
 
#ifdef _DEBUG
16
 
#define new DEBUG_NEW
17
 
#undef THIS_FILE
18
 
static char THIS_FILE[] = __FILE__;
19
 
#endif
20
 
 
21
 
HINSTANCE myInstance;
22
 
 
23
 
int WINAPI DllMain(HINSTANCE hinst, unsigned long reason, void*) 
24
 
25
 
        myInstance = hinst;
26
 
        return 1; 
27
 
}
28
 
 
29
 
////////////////
30
 
// The following global data is SHARED among all instances of the DLL
31
 
// (processes); i.e., these are system-wide globals.
32
 
// 
33
 
#pragma data_seg (".IdleUI")  // you must define as SHARED in .def
34
 
HHOOK g_hHookKbd = NULL;      // one instance for all processes
35
 
HHOOK g_hHookMouse = NULL;    // one instance for all processes
36
 
DWORD g_dwLastInputTick = 0;  // tick time of last input event
37
 
#pragma data_seg ()
38
 
 
39
 
/////////////////
40
 
// Get tick count of last keyboard or mouse event
41
 
//
42
 
DLLEXPORT DWORD IdleUIGetLastInputTime()
43
 
{
44
 
        return g_dwLastInputTick;
45
 
}
46
 
 
47
 
/////////////////
48
 
// Keyboard hook: record tick count
49
 
//
50
 
LRESULT CALLBACK MyKbdHook(int code, WPARAM wParam, LPARAM lParam)
51
 
{
52
 
        if (code==HC_ACTION) {
53
 
                g_dwLastInputTick = GetTickCount();
54
 
        }
55
 
        return ::CallNextHookEx(g_hHookKbd, code, wParam, lParam);
56
 
}
57
 
 
58
 
/////////////////
59
 
// Mouse hook: record tick count
60
 
//
61
 
LRESULT CALLBACK MyMouseHook(int code, WPARAM wParam, LPARAM lParam)
62
 
{
63
 
        if (code==HC_ACTION) {
64
 
                g_dwLastInputTick = GetTickCount();
65
 
        }
66
 
        return ::CallNextHookEx(g_hHookMouse, code, wParam, lParam);
67
 
}
68
 
 
69
 
//////////////////
70
 
// Initialize DLL: install kbd/mouse hooks.
71
 
//
72
 
DLLEXPORT BOOL IdleUIInit()
73
 
{
74
 
        if (g_hHookKbd == NULL) {
75
 
                HINSTANCE hInst = myInstance;
76
 
                g_hHookKbd   = SetWindowsHookEx(WH_KEYBOARD, MyKbdHook,   hInst, 0);
77
 
                g_hHookMouse = SetWindowsHookEx(WH_MOUSE,               MyMouseHook, hInst, 0);
78
 
                g_dwLastInputTick = GetTickCount(); // init count
79
 
        }
80
 
        assert(g_hHookKbd);
81
 
        assert(g_hHookMouse);
82
 
        return TRUE;
83
 
}
84
 
 
85
 
//////////////////
86
 
// Terminate DLL: remove hooks.
87
 
//
88
 
DLLEXPORT void IdleUITerm()
89
 
{
90
 
        BOOL bRet1 = UnhookWindowsHookEx(g_hHookKbd);
91
 
        BOOL bRet2 = UnhookWindowsHookEx(g_hHookMouse);
92
 
        assert(bRet1 && bRet2);
93
 
}