Thoughts from Dan Miser RSS 2.0
 Thursday, March 03, 2005
For those of you who use ActiveForms, you may have applied my technique to solve the problem when the ActiveX ActiveForm is not activated. Unfortunately, this one line of code gives us a new problem losing focus. For example, say you have focus on a button, and that button calls ShowMessage. If you did a PostMessage(WM_ACTIVATE), then you'll notice that the focus is lost after returning from the ShowMessage call. More precisely, the currently focused control at this point is the Shell DocObject View window used within IE. From this point on, pressing TAB will not take you from control to control within your ActiveForm. You can use the mouse to set focus, but that's sub-optimal.

To solve this, the easiest thing I found was to use the OnFrameWindowActivate and OnDocWindowActivate methods of the IOleInPlaceActiveObject interface. I posted another article about how to use a custom TActiveXControlClass, and that code already uses a method from IOleInPlaceActiveObject. This means that all we need to do is add these 2 methods to that existing class and implement them. The code looks like this:


type
  TTranslateAcceleratorFormControl = class(TActiveFormControl, IOleInPlaceActiveObject)
  private
    FActiveHWND: HWND;
    procedure HandleActiveHWND(Activate: boolean);
  protected
    function TranslateAccelerator(var msg: TMsg): HResult; stdcall;
    function OnFrameWindowActivate(fActivate: BOOL): HResult; stdcall;
    function OnDocWindowActivate(fActivate: BOOL): HResult; stdcall;
  end;


procedure TTranslateAcceleratorFormControl.HandleActiveHWND(Activate: boolean);
begin
  if Activate then
  begin
    if FActiveHWND <> 0 then
      SetFocus(FActiveHWND);
  end
  else
    FActiveHWND := GetFocus;
end;

function TTranslateAcceleratorFormControl.OnDocWindowActivate(fActivate: BOOL): HResult;
begin
  Result := inherited OnDocWindowActivate(fActivate);
  HandleActiveHWND(fActivate);
end;

function TTranslateAcceleratorFormControl.OnFrameWindowActivate(fActivate: BOOL): HResult;
begin
  Result := inherited OnFrameWindowActivate(fActivate);
  HandleActiveHWND(fActivate);
end;

function TTranslateAcceleratorFormControl.TranslateAccelerator(var msg: TMsg): HResult;
begin
  Result := inherited TranslateAccelerator(msg);

  if Result = S_OK then
  begin
    if (msg.message = WM_KEYDOWN) and (GetKeyState(VK_CONTROL) < 0) and (msg.wParam = 67) then
      Result := S_FALSE;
  end;
end;

If you test the ActiveForm at this point, you'll find that things work pretty well. The one remaining problem is that these methods don't fire when getting activated, so I handled that by adding another PostMessage after the PostMessage(WM_ACTIVATE) call. By doing this, we're letting the DAX framework set things up properly, and during that time, InPlaceActivate is called which finishes proper initialization. The code in the ActiveForm class looks similar to this:


type
  TMyActiveForm = class(TActiveForm, IMyActiveForm)
    procedure UMACtivate(var Message: TMessage); message UM_ACTIVATE; // const UM_ACTIVATE = WM_USER + 123;
// Other methods declared here

procedure TMyActiveForm.UMActivate(var Message: TMessage); 
begin
  (ComObject as IOleInPlaceActiveObject).OnFrameWindowActivate(true);
end;

Be sure to call

PostMessage(Handle, UM_ACTIVATE, 0, 0);
after your existing PostMessage call to WM_ACTIVATE.

Let me know if you run into any problems with this approach.

Thursday, March 03, 2005 1:19:00 PM (Central Standard Time, UTC-06:00)  #    Comments [1] -

Tracked by:
http://fbbbbbbbbbbbb.com [Pingback]
http://bbbbbbbbbbcc.com [Pingback]
http://ebbbbbbbbbbbb.com [Pingback]
http://dbbbbbbbbbbbb.com [Pingback]
http://bbbbbbbbbbbbc.com [Pingback]
http://www.cats.de [Pingback]
http://www.dogs.com [Pingback]
http://9nx-information.info/54489598/bio-gas-plant.html [Pingback]
http://9nm-information.info/23571621/index.html [Pingback]
http://9nq-information.info/97728438/index.html [Pingback]
http://9nj-information.info/34052569/index.html [Pingback]
http://9nm-information.info/97783460/duke-university-music-department.html [Pingback]
http://9nm-information.info/40813181/index.html [Pingback]
http://9nd-information.info/97606199/index.html [Pingback]
http://9nx-information.info/02751155/mousetrap-board-game-instructions.html [Pingback]
http://9ni-information.info/31178082/service-proxy.html [Pingback]
http://9nu-information.info/94567706/new-york-city-borad-of-elections.html [Pingback]
http://9nc-information.info/32790421/index.html [Pingback]
http://9op-information.info/59800011/guy-self-blow-job.html [Pingback]
http://9ol-information.info/29317859/index.html [Pingback]
http://9oh-information.info/40387173/westfiel-shopping-tampa.html [Pingback]
http://9ov-information.info/19572809/no-kill-cat-shelters.html [Pingback]
http://9os-information.info/24726119/index.html [Pingback]
http://9oi-information.info/48488546/index.html [Pingback]
http://9oe-information.info/00667202/index.html [Pingback]
http://9qi-information.info/66419508/index.html [Pingback]
http://9qe-information.info/33534133/index.html [Pingback]
http://9sb-information.info/44010111/edonkey-1-4.html [Pingback]
http://9rv-information.info/06909664/index.html [Pingback]
http://9sp-information.info/71320783/ritmo-75.html [Pingback]
http://9sj-information.info/94718655/index.html [Pingback]
http://9rl-information.info/27780756/genie-duct-work-lift.html [Pingback]
http://9uafl-le-informazioni.info/71907392/index.html [Pingback]
http://9uaes-le-informazioni.info/48204327/index.html [Pingback]
http://9uafd-le-informazioni.info/20340660/ex-ii-cc-sentenza-2004.html [Pingback]
http://9uafh-le-informazioni.info/94108639/simona-rinieri-dennis.html [Pingback]
http://9uafh-le-informazioni.info/94108639/index.html [Pingback]
http://9uaep-le-informazioni.info/49144923/index.html [Pingback]
http://9uaen-le-informazioni.info/38820333/index.html [Pingback]
http://9uafe-le-informazioni.info/03840478/index.html [Pingback]
http://9uaek-le-informazioni.info/88372723/trucchi-spiderman-2.html [Pingback]
http://9uagr-le-informazioni.info/61488660/index.html [Pingback]
http://9uagn-le-informazioni.info/59092624/index.html [Pingback]
http://9uahb-le-informazioni.info/75876468/formal-power-series.html [Pingback]
http://9uago-le-informazioni.info/25857077/canzone-goccia-dopo-goccia.html [Pingback]
http://9uagj-le-informazioni.info/38118892/canon-580-speedlite-ex.html [Pingback]
http://9uagf-le-informazioni.info/09829552/index.html [Pingback]
http://9uahj-le-informazioni.info/74429501/index.html [Pingback]
http://9uagd-le-informazioni.info/34990784/index.html [Pingback]
http://9uahf-le-informazioni.info/37407869/index.html [Pingback]
Friday, May 27, 2005 3:59:00 AM (Central Standard Time, UTC-06:00)
Implemented this internally in our ActiveForm project now - and it works like a charm!



Kudus and thanks!
Comments are closed.
Navigation
Archive
<July 2008>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Dan Miser
Sign In
Statistics
Total Posts: 306
This Year: 21
This Month: 0
This Week: 0
Comments: 604
All Content © 2008, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)