Click here to Skip to main content
15,914,327 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CursorClip Drawing Region Pin
Branislav22-Sep-04 1:51
Branislav22-Sep-04 1:51 
GeneralStatic control for text width Pin
mike :D20-Sep-04 21:51
mike :D20-Sep-04 21:51 
GeneralA question about hint on the button Pin
Rassul Yunussov20-Sep-04 21:43
Rassul Yunussov20-Sep-04 21:43 
GeneralRe: A question about hint on the button Pin
Sujan Christo20-Sep-04 22:32
Sujan Christo20-Sep-04 22:32 
GeneralRe: A question about hint on the button Pin
Rassul Yunussov22-Sep-04 19:11
Rassul Yunussov22-Sep-04 19:11 
Generalweird stream << "behavior" Pin
froyd20-Sep-04 20:47
froyd20-Sep-04 20:47 
GeneralActiveX control in VC.Net Pin
Amol Chavan20-Sep-04 20:30
Amol Chavan20-Sep-04 20:30 
Generallocal window hook Pin
Sung-Won20-Sep-04 20:06
Sung-Won20-Sep-04 20:06 
I wanna hook a certain window and coded as below but it didn't work!
please check my code.

In control dialog project..

    BOOL (*install_hook)(HWND, HWND, DWORD);<br />
    m_inst_hooker_dll = LoadLibrary("Hooker_dll.dll");<br />
    if(m_inst_hooker_dll == NULL)<br />
    {<br />
        AfxMessageBox("Hooker_dll.dll was not found!");<br />
        PostQuitMessage(0);<br />
        return;<br />
    }<br />
<br />
    install_hook = (BOOL (*)(HWND, HWND, DWORD))GetProcAddress(m_inst_hooker_dll, "install_hook");<br />
<br />
    DWORD process_di = 0;<br />
    DWORD id = GetWindowThreadProcessId(edit, &process_di);<br />
<br />
    if(!install_hook || !(*install_hook)(this->GetSafeHwnd(), edit, id))<br />
    {<br />
        AfxMessageBox("Fail to intall the Hooker,");<br />
        PostQuitMessage(0);<br />
        return;<br />
    }<br />

'edit',found by FindWindow, the window handle of the external process which will be hooked, has a valide value. I verificated the value by sending a certail message.(It worked!)


In hook_dll project..

<br />
#include "stdafx.h"<br />
#pragma data_seg(".HKT")<br />
HINSTANCE g_module = NULL;<br />
HHOOK g_hook = NULL;<br />
HWND g_msg_destination = NULL;<br />
HWND g_hooked_window = NULL;<br />
#pragma data_seg()<br />
#pragma comment(linker, "/SECTION:.shared, RWS")<br />
<br />
BOOL APIENTRY DllMain( HANDLE hModule, <br />
                       DWORD  ul_reason_for_call, <br />
                       LPVOID lpReserved<br />
                     )<br />
{<br />
    switch (ul_reason_for_call)<br />
    {<br />
        case DLL_PROCESS_ATTACH:<br />
            g_module = (HINSTANCE)hModule;<br />
            break;<br />
<br />
        case DLL_PROCESS_DETACH:<br />
            UnhookWindowsHookEx(g_hook);<br />
            break;<br />
    }<br />
    return TRUE;<br />
}<br />
<br />
LRESULT CALLBACK proc(int nCode, WPARAM w_param, LPARAM l_param)<br />
{<br />
    if(nCode >= 0)<br />
    {<br />
        static char buf[256];<br />
        int n;<br />
<br />
        n = ::SendMessage(g_hooked_window, WM_GETTEXT, 256, (LPARAM)buf);<br />
        buf[n] = 0;<br />
        ::SendMessage(g_msg_destination, WM_SETTEXT, 0, (LPARAM)buf);<br />
    }<br />
<br />
    return ::CallNextHookEx(g_hook, nCode, w_param, l_param);<br />
}<br />
<br />
extern "C" __declspec(dllexport)BOOL install_hook(HWND dest_window, HWND hooked_window, DWORD thread_id)<br />
{<br />
    if(!hooked_window) return FALSE;<br />
    g_msg_destination = dest_window;<br />
    g_hooked_window = hooked_window;<br />
    g_hook = ::SetWindowsHookEx(WH_GETMESSAGE, proc, (HINSTANCE)g_module, thread_id);<br />
    return TRUE;<br />
}

It seems that my hook-procedure was not inserted to the hook chain. and If I set the thread_id = 0, as global hook, It works well.

Please answer me.
GeneralDoes this Code look robust Pin
Monty220-Sep-04 19:20
Monty220-Sep-04 19:20 
GeneralRe: Does this Code look robust Pin
User 58385220-Sep-04 20:43
User 58385220-Sep-04 20:43 
GeneralRe: Does this Code look robust Pin
Monty220-Sep-04 21:12
Monty220-Sep-04 21:12 
GeneralRe: Does this Code look robust Pin
User 58385221-Sep-04 11:48
User 58385221-Sep-04 11:48 
GeneralMFC: Mouse Right-Click Event to remove and set the black spots in an image from 255 to 0 Pin
pohcb_sonic20-Sep-04 18:07
pohcb_sonic20-Sep-04 18:07 
GeneralRe: MFC: Mouse Right-Click Event to remove and set the black spots in an image from 255 to 0 Pin
Christian Graus20-Sep-04 18:24
protectorChristian Graus20-Sep-04 18:24 
GeneralCListBox formatting Pin
stevieo8420-Sep-04 18:07
stevieo8420-Sep-04 18:07 
GeneralRe: CListBox formatting Pin
Branislav21-Sep-04 1:07
Branislav21-Sep-04 1:07 
Questioncan accelerator keys be intercepted by ActiveX ? Pin
somesoft20-Sep-04 17:11
somesoft20-Sep-04 17:11 
QuestionPassing variables to function called by a thread?!?!?? Pin
Zero_G20-Sep-04 14:37
Zero_G20-Sep-04 14:37 
AnswerRe: Passing variables to function called by a thread?!?!?? Pin
David Crow20-Sep-04 16:56
David Crow20-Sep-04 16:56 
AnswerRe: Passing variables to function called by a thread?!?!?? Pin
stevieo8420-Sep-04 18:20
stevieo8420-Sep-04 18:20 
AnswerRe: Passing variables to function called by a thread?!?!?? Pin
V.20-Sep-04 23:29
professionalV.20-Sep-04 23:29 
QuestionWhy public destructors? Pin
Anonymous20-Sep-04 11:16
Anonymous20-Sep-04 11:16 
AnswerRe: Why public destructors? Pin
Christian Graus20-Sep-04 11:30
protectorChristian Graus20-Sep-04 11:30 
GeneralRe: Why public destructors? Pin
Anonymous20-Sep-04 11:53
Anonymous20-Sep-04 11:53 
GeneralRe: Why public destructors? Pin
Jörgen Sigvardsson20-Sep-04 13:22
Jörgen Sigvardsson20-Sep-04 13:22 

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.