Intercept mesages from a control ? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Intercept mesages from a control ?

How do I intercept WM_LBUTTONDOWN of edit control?

Many thanks.


  • pseudocoderpseudocoder Posts: 688Member ✭✭✭
    subclass the control


    HWND hParent;
    WNDPROC wpEdit;

    LRESULT CALLBACK EditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {

    LRESULT lRes;

    if(msg != WM_MOUSEMOVE) {
    lRes = CallWindowProc(wpEdit, hwnd, msg, wParam, lParam);
    } else {
    return DefWindowProc(hwnd, msg, wParam, lParam);

    if(msg == WM_LBUTTONDOWN) {
    // code
    MessageBox(hwnd, TEXT("lbutton click test"), TEXT(""), MB_OK);
    return lRes;

    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {

    // bits of code
    static HWND hEdit1; // handle to edit control

    switch(msg) {

    WM_CREATE : // bits of code
    hParent = hwnd;
    wpEdit = (WNDPROC) SetWindowLong(hEdit1, GWL_WNDPROC, (LONG) EditProc);
    // bits of code

    WM_DESTORY : // bits of code
    SetWindowLong(hEdit1, GWL_WNDPROC, (LONG) wpEdit);
    // bits of code
    // bits of code

    something like that, I think.

Sign In or Register to comment.