Click here to Skip to main content
15,905,683 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralC# dll import into C++ Pin
student66694-May-04 11:05
student66694-May-04 11:05 
GeneralRe: C# dll import into C++ Pin
Mike Dimmick4-May-04 11:11
Mike Dimmick4-May-04 11:11 
GeneralRe: C# dll import into C++ Pin
monrobot134-May-04 11:48
monrobot134-May-04 11:48 
GeneralRight clicking in CButtonST Pin
Albedo4-May-04 10:52
Albedo4-May-04 10:52 
GeneralCommand-line parameter in URL Pin
BlackDice4-May-04 10:05
BlackDice4-May-04 10:05 
GeneralRe: Command-line parameter in URL Pin
Terry O'Nolley4-May-04 10:09
Terry O'Nolley4-May-04 10:09 
GeneralRe: Command-line parameter in URL Pin
BlackDice4-May-04 10:17
BlackDice4-May-04 10:17 
Questionhow to focus in a desired window Pin
shammyrly4-May-04 9:57
shammyrly4-May-04 9:57 
my aim is to create a key board driver, i got a program from the net and it is working but i have to focus the the keyboard events to a desired window (say ms word). what changes should i make in the following codes.
#include "mian.h"

#define MAX_COUNT 50 // Max number of keystrokes to remember

#pragma data_seg(".shared") // ".shared" is defined in exports.def to allow
// all instances of the dll to share these variables
HWND m_hHwndKey = 0;
HHOOK m_hHookKey = 0;
HWND m_hHwndMouse = 0;
HHOOK m_hHookMouse = 0;

CHAR m_szMain[MAX_COUNT] = ""; // A buffer to store decoded keyboard codes
int m_nLastPos = 0; // Last position used in the buffer

HCURSOR m_hCursorLast = 0; // These two values are used to copy the mouse
HCURSOR m_hCursorLastRet = 0; // cursor
#pragma data_seg()

// Set the values for the window and hook for the Keyboard hook
void WINAPI SetValuesKey(HWND hWnd, HHOOK hk) {
Sleep(0);
m_hHwndKey = hWnd;
m_hHookKey = hk;
}

// Set the values for the window and hook for the mouse hook
void WINAPI SetValuesMouse(HWND hWnd, HHOOK hk) {
Sleep(0);
m_hHwndMouse = hWnd;
m_hHookMouse = hk;
}

// This is the mouse hook itself
LRESULT CALLBACK MouseProc( int nCode, WPARAM wParam, LPARAM lParam ) {
Sleep(0);
if (nCode < 0) {
return CallNextHookEx(m_hHookMouse, nCode, wParam, lParam);
}

Sleep(0);
if (nCode == HC_ACTION) {

HCURSOR hCursor = GetCursor();

// Copy the mouse cursor
if (hCursor != m_hCursorLastRet) {
if (m_hCursorLast) {
DestroyCursor(m_hCursorLast);
}

ICONINFO ii;
GetIconInfo(hCursor, &ii);
m_hCursorLast = CreateIconIndirect(&ii);
DeleteObject(ii.hbmMask);
DeleteObject(ii.hbmColor);
Sleep(0);

m_hCursorLastRet = hCursor;
Sleep(0);

}

// If the message is a WM_NC*, convert it to a WM_*
if ((wParam >= 0xA0) & (wParam <= 0xA9)) {
wParam = wParam + 352;
}

// Let the listening window know about the message
Sleep(0);
PostMessage(m_hHwndMouse, wParam, 0, MAKEWPARAM(
( (MOUSEHOOKSTRUCT*) lParam )->pt.x,
( (MOUSEHOOKSTRUCT*) lParam )->pt.y));

}


return 0;
}

// Function to get the last mouse cursor that was copied. The return cursor
// is a copy of the copy, so the callee must delete it.
HCURSOR WINAPI GetLastCursor() {
Sleep(0);
HCURSOR hCursor = m_hCursorLast;
m_hCursorLast = 0;
return (hCursor);
}

// Returns the current state of the keyboard bufffer
void WINAPI GetKeyInfo(CHAR * szIn, int * nLastPos) {
Sleep(0);
memcpy(szIn, &m_szMain, MAX_COUNT);
(* nLastPos) = m_nLastPos;
}

// Keyboard hook
LRESULT CALLBACK KeyProc( int nCode, WPARAM wParam, LPARAM lParam ) {
if (nCode < 0) {
Sleep(0);
return CallNextHookEx(m_hHookKey, nCode, wParam, lParam);
}

Sleep(0);
if (nCode == HC_ACTION) {

if (lParam & 0x80000000) {
Sleep(0);
PostMessage(m_hHwndKey, WM_KEYUP, wParam, lParam);
} else {
BYTE lpKeyState[256];
GetKeyboardState((unsigned char *)&lpKeyState);

// Convert the message to a normal keystroke, and store it
// in the buffer
WORD lpChar;

int nRet = ToAscii(
wParam,
(lParam & 0xFF0000) >> 16,
(unsigned char *)&lpKeyState,
&lpChar,
0);

if (nRet == 1) {
m_szMain[m_nLastPos] = (char) lpChar;
m_nLastPos ++;
if (m_nLastPos >= MAX_COUNT) {
m_nLastPos = 0;
}
}

Sleep(0);
PostMessage(m_hHwndKey, WM_KEYDOWN, wParam, lParam);
}

}

return 0;
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID) {
Sleep(0);
if (fdwReason == DLL_PROCESS_ATTACH) {
DisableThreadLibraryCalls(hinstDLL);
}
Sleep(0);
return TRUE;
}

// This is to prevent the CRT from loading, thus making this a smaller
// and faster dll.
extern "C" BOOL __stdcall _DllMainCRTStartup( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
Sleep(0);
return DllMain( hinstDLL, fdwReason, lpvReserved );
}
Cry | :((
GeneralCalling base class function Pin
BlackDice4-May-04 9:45
BlackDice4-May-04 9:45 
GeneralRe: Calling base class function Pin
Joe Woodbury4-May-04 10:09
professionalJoe Woodbury4-May-04 10:09 
GeneralRe: Calling base class function Pin
BlackDice4-May-04 10:11
BlackDice4-May-04 10:11 
GeneralRe: Calling base class function Pin
toxcct4-May-04 10:33
toxcct4-May-04 10:33 
GeneralWriting HTML to file Pin
monrobot134-May-04 9:30
monrobot134-May-04 9:30 
GeneralRe: Writing HTML to file Pin
Rafael Fernández López4-May-04 9:34
Rafael Fernández López4-May-04 9:34 
GeneralRe: Writing HTML to file Pin
toxcct4-May-04 10:04
toxcct4-May-04 10:04 
GeneralRe: Writing HTML to file Pin
Rafael Fernández López4-May-04 10:12
Rafael Fernández López4-May-04 10:12 
GeneralRe: Writing HTML to file Pin
Joe Woodbury4-May-04 10:12
professionalJoe Woodbury4-May-04 10:12 
GeneralRe: Writing HTML to file Pin
toxcct4-May-04 10:18
toxcct4-May-04 10:18 
GeneralRe: Writing HTML to file Pin
David Crow4-May-04 10:12
David Crow4-May-04 10:12 
GeneralRe: Writing HTML to file Pin
toxcct4-May-04 10:22
toxcct4-May-04 10:22 
GeneralCToolBarCtrl, &#161;&#161; Help, please !! Pin
Rafael Fernández López4-May-04 9:08
Rafael Fernández López4-May-04 9:08 
GeneralRe: CToolBarCtrl, &#161;&#161; Help, please !! Pin
Rafael Fernández López4-May-04 10:08
Rafael Fernández López4-May-04 10:08 
GeneralFilling a child window in a dialog box dynamically Pin
cscafidi4-May-04 8:47
cscafidi4-May-04 8:47 
GeneralRe: Filling a child window in a dialog box dynamically Pin
David Crow4-May-04 9:05
David Crow4-May-04 9:05 
GeneralRe: Filling a child window in a dialog box dynamically Pin
cscafidi4-May-04 9:47
cscafidi4-May-04 9:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.