Thoughts from Dan Miser RSS 2.0
# Friday, October 15, 2004
If you've ever developed an ActiveForm, then you probably have run into the scenario where you go to a standard control in your form (e.g. an Edit control), select the text, and then press Ctrl+C to copy the text. However, I'm willing to bet that your next reaction was stunned amazement when you realized that the text was not actually copied to the clipboard. To make matters even more maddening, if you use Ctrl+X or Ctrl+V in that very same edit control, things work as you would expect.

I had to fix this problem recently, and it is awfully strange. Pressing Ctrl+X and Ctrl+V makes the TActiveFormControl.TranslateAccelerator method return S_FALSE. Pressing Ctrl+C, the return is S_OK. So in order to fix this, I want to return S_FALSE when Ctrl+C is pressed. I do this by creating a new TActiveXControlClass that overrides the TranslateAccelerator method and returns S_FALSE when needed. The only other thing that needs to be done is to use the new class in your TActiveFormFactory.Create call so that we can get calls to our TranslateAccelerator method and do our own custom stuff.

One caveat: Things are working quite well in IE6. I'm not sure what will happen in other ActiveX containers. Use at your own risk, or at least test in whatever container you're deploying to first!

Here's the code. Please let me know what you think. If you see any improvements that can be made, I'd love to hear about those, too. But at least, for now, my customers are happy again.


type
 TTranslateAcceleratorFormControl = class(TActiveFormControl, IOleInPlaceActiveObject)
  function TranslateAccelerator(var msg: TMsg): HResult; stdcall;
 end;

{ TTranslateAcceleratorFormControl }
{ 
When pressing Ctrl+C, the inherited method returns S_OK meaning that the container thinks
it did what it needed to, and therefore, the message is consumed. When pressing Ctrl+X or
Ctrl+V, the return from the inherited method is S_FALSE.

Therefore, we will always call the inherited method to allow for default processing. If the
return is S_OK, and the message is WM_KEYDOWN, and we have pressed Ctrl+C, we override
the result and return S_FALSE instead.
}
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;

initialization
  TActiveFormFactory.Create(
    ComServer,
    //TActiveFormControl,             // standard Delphi-generated class
    TTranslateAcceleratorFormControl, // our replacement class
    TAFActionTest,
    Class_AFActionTest,
    1,
    '',
    OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
    tmApartment);
end.
Friday, October 15, 2004 7:56:00 PM (GMT Daylight Time, UTC+01:00)  #    Comments [1] -
Delphi
Tracked by:
http://www.google.com/search?q=wmybsced [Pingback]
http://9nc-information.info/46890745/drive-in-movie-theater-in-maine.html [Pingback]
http://9nm-information.info/15698520/index.html [Pingback]
http://9ne-information.info/11620345/index.html [Pingback]
http://9nc-information.info/69059362/book-clubs-world-ebooks.html [Pingback]
http://9nd-information.info/83254442/index.html [Pingback]
http://9nq-information.info/00600854/index.html [Pingback]
http://9nx-information.info/47259726/index.html [Pingback]
http://9nh-information.info/48543719/index.html [Pingback]
http://9oo-information.info/40035303/index.html [Pingback]
http://9qj-information.info/90678519/index.html [Pingback]
http://9oq-information.info/21255871/index.html [Pingback]
http://9ov-information.info/08764184/index.html [Pingback]
http://9ol-information.info/50016884/index.html [Pingback]
http://9qg-information.info/84337502/index.html [Pingback]
http://9oh-information.info/44311196/index.html [Pingback]
http://9qf-information.info/35406179/index.html [Pingback]
http://9rm-information.info/73181128/automatic-racing-transmission.html [Pingback]
http://9sd-information.info/89826118/crossfade-lyric-so-far-away.html [Pingback]
http://9sa-information.info/87249014/index.html [Pingback]
http://9rm-information.info/58474409/index.html [Pingback]
http://9ru-information.info/06775268/juneau-douglas-high-school.html [Pingback]
http://9rf-information.info/02354510/index.html [Pingback]
http://9rv-information.info/47333722/toshiba-satellite-4090cds-laptop-specs.html [Pingback]
http://9sp-information.info/35721644/test-friend.html [Pingback]
http://9rb-information.info/87274082/wedding-invitation-symbols.html [Pingback]
http://9rx-information.info/91467637/index.html [Pingback]
http://9rc-information.info/56598114/mp3-workshop.html [Pingback]
http://9rm-information.info/46756880/index.html [Pingback]
http://9rp-information.info/60757554/index.html [Pingback]
http://9rh-information.info/75409758/pictures-of-house-spider-bites.html [Pingback]
http://9sb-information.info/88949104/index.html [Pingback]
http://9si-information.info/60065103/index.html [Pingback]
http://9uafk-le-informazioni.info/85727472/index.html [Pingback]
http://9uaed-le-informazioni.info/90178892/index.html [Pingback]
http://9uafq-le-informazioni.info/96212427/index.html [Pingback]
http://9uafq-le-informazioni.info/13874092/air-mattress-sofa-bed.html [Pingback]
http://9uaeb-le-informazioni.info/22439671/index.html [Pingback]
http://9uaek-le-informazioni.info/58884043/index.html [Pingback]
http://9uaeq-le-informazioni.info/66780668/index.html [Pingback]
http://9uaee-le-informazioni.info/41546154/deduzione-mutuo.html [Pingback]
http://9uaet-le-informazioni.info/66827612/sito-driver.html [Pingback]
http://9uaej-le-informazioni.info/12890928/index.html [Pingback]
http://9uaea-le-informazioni.info/94856903/index.html [Pingback]
http://9uaem-le-informazioni.info/22333520/palm-village.html [Pingback]
http://9uaes-le-informazioni.info/14220836/concezione-guerra-tesina.html [Pingback]
http://9uaec-le-informazioni.info/25479534/index.html [Pingback]
http://9uaeo-le-informazioni.info/08051965/televisore-al-plasma-50-pollici.html [Pingback]
http://9uaep-le-informazioni.info/82905129/oakdale.html [Pingback]
http://9uafh-le-informazioni.info/91061538/index.html [Pingback]
http://9uaeb-le-informazioni.info/29783133/secondamedicina-com-terapia-diabete-h... [Pingback]
http://9uaeg-le-informazioni.info/23282926/index.html [Pingback]
http://9uahd-le-informazioni.info/77588785/index.html [Pingback]
http://9uahk-le-informazioni.info/92946925/index.html [Pingback]
http://9uahb-le-informazioni.info/10975938/borsa-pelle-nannini.html [Pingback]
http://9uagb-le-informazioni.info/56913863/index.html [Pingback]
http://9uagg-le-informazioni.info/49654575/prison-break-mediaset.html [Pingback]
http://9uaga-le-informazioni.info/48991884/index.html [Pingback]
http://9uagq-le-informazioni.info/48848509/aliquota-dazio-importazione-norvegia.... [Pingback]
http://9uahd-le-informazioni.info/93659274/index.html [Pingback]
http://9uagn-le-informazioni.info/73708906/umano-troppo-umano.html [Pingback]
http://9uagj-le-informazioni.info/53569692/index.html [Pingback]
http://9uahb-le-informazioni.info/86254491/index.html [Pingback]
http://9uahr-le-informazioni.info/33747387/the-waitress-game.html [Pingback]
http://9uaht-le-informazioni.info/41035988/index.html [Pingback]
http://9uage-le-informazioni.info/47241336/cinema-calabresi-san-benedetto.html [Pingback]
http://9uagh-le-informazioni.info/05037316/erap-an-it.html [Pingback]
http://9uagp-le-informazioni.info/98507708/index.html [Pingback]
Navigation
Archive
<November 2014>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
Blogroll
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 2014
Dan Miser
Sign In
Statistics
Total Posts: 388
This Year: 0
This Month: 0
This Week: 0
Comments: 630
Themes
Pick a theme:
All Content © 2014, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)