I have in my application modal dialog. My costumer in his program close a dialogs by click right button in this dialog or out of dialog, but his dialogs are not modal, so he just check if in any place of application come button click (not important in dialog or in main application window).

This what I want is create this same funcjonality, but with modal dialogs. So I need information, that user click out of dialog (in main application window space).

If I use SetCapture for dialog I have this funcionality, but mouse click in control not make result (dialog have a mouse and not propagete this events to controls). This same problem with "NCCLICK" i.e. click in cross for close application.

I try with your's

Code:
SetWindowsHookEx(WH_MOUSE,MouseProc,NULL,GetCurrentThreadId());
where

Code:
LRESULT CALLBACK MouseProc(          int nCode,
    WPARAM wParam,
    LPARAM lParam
)
{
	if (wParam==WM_RBUTTONDOWN)
	{
		Beep(1000,100);
	}
	
	return CallNextHookEx(0,nCode,wParam,lParam);
}
but I havn't this "beep" if I click out of modal dialog (in main application window).