Ver Mensaje Individual
  #6  
Antiguo 20-01-2004
murci murci is offline
Miembro
 
Registrado: jul 2003
Ubicación: Murcia
Posts: 43
Reputación: 0
murci Va por buen camino
Lo primero que quiero es darte las gracias por el interes que te estas tomando con mi problema. Te estoy muy agradecido.

Lo segundo es comentarte que he probado todo lo que has dicho y no hay manera. no salta el evento.

El codigo es el siguiente:

unit uFormPadre;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DBGrids;

const
CM_BASE = $B000;
CM_FocusMiChange = CM_BASE + 7;

type

TCMFocusMiChange = record
Msg: Cardinal;
Unused: Integer;
Sender: TWinControl;
Result: Longint;
end;

TFormPadre = class(TForm)
private
FCActivo : TColor;
FAntColor : TColor;
FAntControl : TComponent;
public
procedure FormCreate(Sender: TObject);
procedure CMFocusMiChange(var Message: TCMFocusMiChange); message CM_FocusMiChange;
Procedure AppMessage(var Msg: TMSg; Var Handled:Boolean);
end;

var
FormPadre: TFormPadre;

implementation

{$R *.nfm}

procedure TFormPadre.CMFocusMiChange(var Message: TCMFocusMiChange);
begin
showmessage('cambio');
end;

procedure TFormPadre.FormCreate(Sender: TObject);
begin
Application.OnMessage := AppMessage;
end;

Procedure TFormPadre.AppMessage(var Msg: TMSg; Var Handled:Boolean);
var
actual : TWincontrol;
begin
if Msg.message = WM_KeyDown then begin
// esto es para controlar que con la flecha abajo se desplegen las
// listas
if Msg.wParam = VK_DOWN then begin
Actual := Screen.ActiveControl;

if Actual is TComboBox then
SendMessage(TComboBox(Screen.ActiveForm.ActiveControl).Handle,CB_SHOWDROPDOWN,-1,0);

// se pueden añadir mas controles....

end;

// y aqui es el control del intro.
if Msg.wParam = VK_RETURN THEN begin
Actual := Screen.ActiveControl;

// para los edit.
if (Actual is TCustomEdit) and not (Actual is TCustomMemo) then
Msg.wParam := VK_TAB;

// para los memo. Con ctrl + enter se salta de linea dentro del
// memo, si solo es intro salta al siguiente control
if (Actual is TCustomMemo) and (HiWord(GetKeyState(VK_CONTROL)) = 0) then
Msg.wParam := VK_TAB;

// Los combobox
if Actual is TCustomComboBox then
if not TCustomComboBox(Actual).DroppedDown then
Msg.wParam := VK_TAB;

// el radiobutton
if Actual is TRadioButton then
Msg.wParam := VK_TAB;

// o esto otro Con Ctrl + intro siguiente celda con
// ctrl + shift + intro celda anterior
// es complicado pero es por no liar con el intro solo
// que siempre pasa de un control a otro.
if Actual is TDBGrid then begin
if (TDBGrid(Actual).ReadOnly) or (HiWord(GetKeyState(VK_CONTROL)) = 0) then
Msg.wParam := VK_TAB
else
if not(HiWord(GetKeyState(VK_SHIFT)) = 0) then begin
if TDBGrid(Actual).selectedindex > 0 then // increment the field
TDBGrid(Actual).selectedindex := TDBGrid(Actual).selectedindex -1
else
TDBGrid(Actual).selectedindex := TDBGrid(Actual).fieldcount -1;
end
else begin
if TDBGrid(Actual).selectedindex < (TDBGrid(Actual).fieldcount -1) then // increment the field
TDBGrid(Actual).selectedindex := TDBGrid(Actual).selectedindex +1
else
TDBGrid(Actual).selectedindex := 0;
end;
end;


// ListBox
if Actual is TCustomListBox then
Msg.wParam := VK_TAB;

// Aqui se pondrían todos los controles que usamos en la
// aplicación y necesitamos cambiar el tab por intro.
// de esta forma te despreocupas de cuantos añades y es más
// limpio el código

end;
end
else if msg.message = CM_FocusMiChange then
showmessage('abierto');
end;


end.


En el evento AppMessage lo uso para que el intro tenga el mismo efecto que el tabulador en algunos controles.
Parece como si el .Net framework no tuviera el mensaje de cambio de foco.
La verdad es que estoy muy perdido.

De nuevo gracias por tu ayuda.
__________________
J. Adolfo Núñez
Responder Con Cita