Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to avoid repeated SendMessage
    text
    copied!<p>I have a problem: I use SendMessage from a procedure in a DLL to communicate with the main window; procedure is a hook procedure that allows main window to know when mouse right button is clicked in a editbox; it sends also handle of the editbox. It works well, except for this bug: when program is running without breakpoints main window receives twice the same message (in this case WM_APP), while if I put a breakpoint in the hook procedure or in the block that handles WM_APP messages the message is considered once. For further descriptions ask me. Following the code of the hook procedure and of the block that handles WM_APP messages. Thanks</p> <p><strong>Hook procedure</strong></p> <pre><code>MYDLL_API LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam) { // processes the message if(nCode &gt;= 0) { // if user clicked with mouse right button if(wParam != NULL &amp;&amp; (wParam == WM_RBUTTONDOWN || wParam == WM_RBUTTONUP)) { wchar_t *s = (wchar_t*) malloc(CLASSNAMELEN*sizeof(wchar_t)); //MessageBox(mainHwnd, (LPCWSTR)L"Captured mouse right button", (LPCWSTR)L"Test", MB_OK); MOUSEHOOKSTRUCT *m = (MOUSEHOOKSTRUCT*) lParam; GetClassName(m-&gt;hwnd, (LPWSTR) s, CLASSNAMELEN); //MessageBox(mainHwnd, (LPCWSTR) s, (LPCWSTR)L"Test", MB_OK); // only if user clicked on a edit box if(wcsncmp(s, L"Edit", 4) == 0) SendMessage(mainHwnd, WM_APP, 0, (LPARAM) lParam); free(s); s = NULL; } } // calls next hook in chain return CallNextHookEx(NULL, nCode, wParam, lParam); } </code></pre> <p><strong>block in main program that handles WM_APP messages</strong></p> <pre><code>case WM_APP: { //MessageBox(hWnd, (LPCWSTR)L"Received WM_APP", (LPCWSTR)L"Test", MB_OK); // copies text from the edit box MOUSEHOOKSTRUCT *m = (MOUSEHOOKSTRUCT*) lParam; int n = GetWindowTextLength(m-&gt;hwnd); // if text has been inserted if(n &gt; 0 &amp;&amp; n &lt; 1024) { wchar_t *s = (wchar_t*) malloc((n+1)*sizeof(wchar_t)); // gets text GetWindowText(m-&gt;hwnd, (LPWSTR) s, n+1); s[n] = (wchar_t) 0; //MessageBox(hWnd, (LPCWSTR)s, (LPCWSTR)L"Test", MB_OK); // saves text in database stateClassPointer-&gt;insertInList(s); } } break; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload