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

Вниз

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

 
Севостьянов Игорь   (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.46 MB
Время: 0.011 c
1-80857
DimNK
2002-04-13 12:24
2002.04.25
Форма авторизации


6-81022
Johnny
2002-01-28 18:35
2002.04.25
Проблемы с RPC сервером при использовании TDCOMConnection


3-80753
nic406
2002-04-04 06:35
2002.04.25
Выборка с VIEW и JOIN(SQL2000) - Помогите новичку!!!


3-80812
fozy
2002-04-05 11:59
2002.04.25
КАРАУЛ MSSQL в Paradox langdriver не могу подобрать плизз


1-80878
Демон
2002-04-14 10:47
2002.04.25
HELP!!! JPEG в BMP





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский