Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Основная";
Текущий архив: 2002.04.25;
Скачать: [xml.tar.bz2];

Вниз

Неприходит сообщение WM_MouseLeave в форму!   Найти похожие ветки 

 
Vovochka   (2002-04-10 12:15) [0]

Вот! MouseEnter - нормально приходит. Чуствуется что где-то подводный камень. Может надо как-то хитро с формой что-то сделать?


 
MAxiMum   (2002-04-10 12:27) [1]

Приведи текст.


 
Vovochka   (2002-04-10 12:32) [2]

Мне просто нужно автоматом убирать форму после ухода мышки из неё.

сейчас что-то типа:

TForm1= class(TForm)
.....
procedure wmMouseLeave(var message:TMessage);message Wm_MouseLeave;
end;
.........
procedure wmMouseLeave(...);
begin
close;///Хрень!
end;


 
troits   (2002-04-10 12:53) [3]

Эх .....
Надо читать help до конца.
Дело в том, что надо вызвать ф-ю TrackMouseEvent, потом message придет _один_ раз. Чтобы опять его получить, надо опять вызывать TrackMouseEvent.

Но это API. А в твоем случае надо ловить не message, а CM_MOUSELEAVE - "дельфийское" сообщение


 
Vovochka   (2002-04-10 13:25) [4]

Мда.
Насчет CM_MouseLeave, оно меня тоже неспасет - событие приходит если мышь уходит на дочерний контрол.
Реально как-то отследить уход мышки из региона или (потерю фокуса|активности) формы. Идеально было-бы onDeactivate form.


 
troits   (2002-04-10 14:10) [5]

Можно по таймеру вызывать GetCursorPos / WindowFromPoint и отслеживать выход за ClientArea окна


 
MAxiMum   (2002-04-10 18:14) [6]

А ты inherited вызываешь.


 
Vovochka   (2002-04-12 08:11) [7]

2Max
Угу.


 
Fantasist   (2002-04-12 08:31) [8]

Ну, самое примитивное, отслеживать MouseMove.


 
REA   (2002-04-12 10:59) [9]

Не забудь еще проверить что юзер Alt-Tab нажал и т.п.


 
troits   (2002-04-12 11:08) [10]

>Vovochka
Почитай
http://www.rsdn.ru/qna/?ui/mouseout.xml


 
Севостьянов Игорь   (2002-04-12 11:38) [11]

Сталкивался я с такой проблемой, дело в том что WM_MOUSELEAVE не везде проходит (я имею ввиду OS)
Но например я расширил (добавил событие OnSelectedButton для кнопки ) свой TToolBarEx таким образом

TToolBarEx = class(TToolBar)
private
FSelectedButton: Integer;
FMouseInControl: Boolean;
FMouseCoord: TPoint;
FOnSelectedButton: TSelectedEvent;
procedure WMNCPaint(var Msg: TWMNCPaint); message WM_NCPAINT;
procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;
procedure CMMouseLeave(var Msg: TWMMouse); message CM_MOUSELEAVE;

function GetButtonIndex: Integer;
function GetToolBarRect: TRect;
protected
procedure SetSelectedButton(Selected: Boolean);
function ButtonHitTest(X, Y: integer): Boolean; dynamic;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property SelectedButton: Integer read FSelectedButton;
property MouseInControl: Boolean read FMouseInControl;
published
property OnSelectedButton: TSelectedEvent read FOnSelectedButton write FOnSelectedButton;
end;

-----------
{ TToolBarEx }

constructor TToolBarEx.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FSelectedButton := -1;
FMouseInControl := False;
FMouseCoord := Point(-1, -1);
end;

destructor TToolBarEx.Destroy;
begin
inherited Destroy;
end;

function TToolBarEx.GetToolBarRect: TRect;
begin
GetWindowRect(Handle, Result);
if ebTop in EdgeBorders then
Inc(Result.Top, 2);
if ebLeft in EdgeBorders then
Inc(Result.Left, 2);
if ebBottom in EdgeBorders then
Dec(Result.Bottom, 2);
if ebRight in EdgeBorders then
Dec(Result.Right, 2);
end;

function TToolBarEx.GetButtonIndex: Integer;
var
TBR: TRect;
i: Integer;
begin
TBR := GetToolBarRect;
with TBR do
begin
Result := -1;
Right := Left;
for i := 0 to ButtonCount-1 do
begin
Right := Right + Buttons[i].Width;
if PtInRect(TBR, Point(FMouseCoord.X, FMouseCoord.Y)) then Result := Buttons[i].Index;
Left := Right;
end;
end;
end;

procedure TToolBarEx.SetSelectedButton(Selected: Boolean);
var
KeyState: TKeyboardState;
begin
FSelectedButton := -1;
if Selected then FSelectedButton := GetButtonIndex;
GetKeyBoardState(KeyState);
if Assigned(FOnSelectedButton) then FOnSelectedButton(Self, FSelectedButton, KeyboardStateToShiftState(KeyState));
FMouseInControl := Selected;
end;

function TToolBarEx.ButtonHitTest(X, Y: integer): Boolean;
begin
FMouseCoord := Point(X, Y);
Result := PtInRect(GetToolBarRect, FMouseCoord);
end;

procedure TToolBarEx.WMNCPaint(var Msg: TWMNCPaint);
var
Pt: TPoint;
begin
inherited;
GetCursorPos(Pt);
SetSelectedButton(ButtonHitTest(Pt.x, Pt.y));
end;

procedure TToolBarEx.WMNCHitTest(var Msg: TWMNCHitTest);
var
KeyState: TKeyboardState;
begin
inherited;
if ButtonHitTest(Msg.XPos, Msg.YPos) then
begin
if not FMouseInControl then SetSelectedButton(True);
end
else
if FMouseInControl then SetSelectedButton(True);

GetKeyBoardState(KeyState);
if Assigned(FOnSelectedButton) then FOnSelectedButton(Self, FSelectedButton, KeyboardStateToShiftState(KeyState));

end;

procedure TToolBarEx.CMMouseLeave(var Msg: TWMMouse);
begin
inherited;
if FMouseInControl then SetSelectedButton(False);
end;
----------- ВЫЗОВ------------------

procedure TfrmMain.tbToolBarSelectedButton(Sender: TObject; Index: Integer;
Shift: TShiftState);
begin
tbtnClearDB.Enabled := (tbtnClearDB.Index = Index) and (Shift = [ssShift, ssCtrl]);
end;



А в MSDN все просто:

WM_MOUSELEAVE
The WM_MOUSELEAVE message is posted to a window when the cursor leaves the client area of the window specified in a prior call to TrackMouseEvent.

A window receives this message through its WindowProc function.

LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_MOUSELEAVE
WPARAM wParam, // not used
LPARAM lParam // not used
);
Parameters
This message has no parameters.

Return Values
If an application processes this message, it should return zero.

Remarks
All tracking requested by TrackMouseEvent is canceled when this message is generated. The application must call TrackMouseEvent when the mouse reenters its window if it requires further tracking of mouse hover behavior.

Requirements
Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98: Requires Windows 98.
Header: Declared in Winuser.h; include Windows.h.

See Also
Mouse Input Overview, Mouse Input Messages, GetCapture, SetCapture, TrackMouseEvent, TRACKMOUSEEVENT, WM_NCMOUSELEAVE




Страницы: 1 вся ветка

Форум: "Основная";
Текущий архив: 2002.04.25;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.48 MB
Время: 0.007 c
1-80993
Vova33
2002-04-12 16:53
2002.04.25
Пакеты


3-80822
Mikeee
2002-04-05 09:16
2002.04.25
Вот вопросик...


14-81072
Suntechnic
2002-03-20 22:37
2002.04.25
Вот, наткнулся в Инете....


1-80969
Vovochka
2002-04-10 12:15
2002.04.25
Неприходит сообщение WM_MouseLeave в форму!


1-80973
Explorer
2002-04-12 12:20
2002.04.25
Как в QuickRep создать несколько страниц





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский