| 1 |
unit activexcontainer; |
| 2 |
|
| 3 |
{$mode delphi}{$H+} |
| 4 |
|
| 5 |
{ Visual ActiveX container. |
| 6 |
|
| 7 |
Copyright (C) 2011 Ludo Brands |
| 8 |
|
| 9 |
This library is free software; you can redistribute it and/or modify it |
| 10 |
under the terms of the GNU Library General Public License as published by |
| 11 |
the Free Software Foundation; either version 2 of the License, or (at your |
| 12 |
option) any later version with the following modification: |
| 13 |
|
| 14 |
As a special exception, the copyright holders of this library give you |
| 15 |
permission to link this library with independent modules to produce an |
| 16 |
executable, regardless of the license terms of these independent modules,and |
| 17 |
to copy and distribute the resulting executable under terms of your choice, |
| 18 |
provided that you also meet, for each linked independent module, the terms |
| 19 |
and conditions of the license of that module. An independent module is a |
| 20 |
module which is not derived from or based on this library. If you modify |
| 21 |
this library, you may extend this exception to your version of the library, |
| 22 |
but you are not obligated to do so. If you do not wish to do so, delete this |
| 23 |
exception statement from your version. |
| 24 |
|
| 25 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 26 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 27 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License |
| 28 |
for more details. |
| 29 |
|
| 30 |
You should have received a copy of the GNU Library General Public License |
| 31 |
along with this library; if not, write to the Free Software Foundation, |
| 32 |
Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1335, USA. |
| 33 |
} |
| 34 |
|
| 35 |
interface |
| 36 |
|
| 37 |
uses |
| 38 |
Classes, SysUtils, Windows, ActiveX, ComObj; |
| 39 |
|
| 40 |
type |
| 41 |
//from OCIDL.h |
| 42 |
PPointF = ^TPointF; |
| 43 |
tagPOINTF = record |
| 44 |
x: Single; |
| 45 |
y: Single; |
| 46 |
end; |
| 47 |
TPointF = tagPOINTF; |
| 48 |
POINTF = TPointF; |
| 49 |
|
| 50 |
|
| 51 |
IOleControlSite = interface |
| 52 |
['{B196B289-BAB4-101A-B69C-00AA00341D07}'] |
| 53 |
function OnControlInfoChanged: HResult; stdcall; |
| 54 |
function LockInPlaceActive(fLock: BOOL): HResult; stdcall; |
| 55 |
function GetExtendedControl(out disp: IDispatch): HResult; stdcall; |
| 56 |
function TransformCoords(var ptlHimetric: TPoint; var ptfContainer: TPointF; |
| 57 |
flags: Longint): HResult; stdcall; |
| 58 |
function TranslateAccelerator(msg: PMsg; grfModifiers: Longint): HResult; |
| 59 |
stdcall; |
| 60 |
function OnFocus(fGotFocus: BOOL): HResult; stdcall; |
| 61 |
function ShowPropertyFrame: HResult; stdcall; |
| 62 |
end; |
| 63 |
|
| 64 |
IPropertyNotifySink = interface |
| 65 |
['{9BFBBC02-EFF1-101A-84ED-00AA00341D07}'] |
| 66 |
function OnChanged(dispid: TDispID): HResult; stdcall; |
| 67 |
function OnRequestEdit(dispid: TDispID): HResult; stdcall; |
| 68 |
end; |
| 69 |
|
| 70 |
ISimpleFrameSite = interface |
| 71 |
['{742B0E01-14E6-101B-914E-00AA00300CAB}'] |
| 72 |
function PreMessageFilter(wnd: HWnd; msg, wp, lp: Integer; |
| 73 |
out res: Integer; out Cookie: Longint): HResult; |
| 74 |
stdcall; |
| 75 |
function PostMessageFilter(wnd: HWnd; msg, wp, lp: Integer; |
| 76 |
out res: Integer; Cookie: Longint): HResult; |
| 77 |
stdcall; |
| 78 |
end; |
| 79 |
|
| 80 |
|
| 81 |
TStatusTextEvent = procedure(Sender: TObject; Status:string) of object; |
| 82 |
|
| 83 |
{ TActiveXContainer } |
| 84 |
|
| 85 |
TActiveXContainer = class(TComponent, IUnknown, IOleClientSite, |
| 86 |
IOleControlSite, IOleInPlaceSite, IOleInPlaceFrame, IDispatch) |
| 87 |
private |
| 88 |
FHandle: HWND; |
| 89 |
FPixelsPerInchX, |
| 90 |
FPixelsPerInchY: Integer; |
| 91 |
FActive: boolean; |
| 92 |
FAttached: boolean; |
| 93 |
FClassName: string; |
| 94 |
FOleObject: IDispatch; |
| 95 |
FOnStatusText: TStatusTextEvent; |
| 96 |
FPrevWndProc:windows.WNDPROC; |
| 97 |
Function GetvObject:variant; |
| 98 |
//IOleClientSite |
| 99 |
Function SaveObject: HResult;StdCall; |
| 100 |
Function GetMoniker(dwAssign: Longint; dwWhichMoniker: Longint;OUT mk: IMoniker):HResult;StdCall; |
| 101 |
Function GetContainer(OUT container: IOleContainer):HResult;StdCall; |
| 102 |
procedure SetActive(AValue: boolean); |
| 103 |
procedure SetClassName(AValue: string); |
| 104 |
procedure SetHandle(AValue: HWND); |
| 105 |
procedure SetOleObject(AValue: IDispatch); |
| 106 |
Function ShowObject:HResult;StdCall; |
| 107 |
Function OnShowWindow(fShow: BOOL):HResult;StdCall; |
| 108 |
Function RequestNewObjectLayout:HResult;StdCall; |
| 109 |
//IOleControlSite |
| 110 |
function OnControlInfoChanged: HResult; stdcall; |
| 111 |
function LockInPlaceActive(fLock: BOOL): HResult; stdcall; |
| 112 |
function GetExtendedControl(out disp: IDispatch): HResult; stdcall; |
| 113 |
function TransformCoords(var ptlHimetric: TPoint; var ptfContainer: TPointF; |
| 114 |
flags: Longint): HResult; stdcall; |
| 115 |
function TranslateAccelerator(msg: PMsg; grfModifiers: Longint): HResult;overload; |
| 116 |
stdcall; |
| 117 |
function OnFocus(fGotFocus: BOOL): HResult; stdcall; |
| 118 |
function ShowPropertyFrame: HResult; stdcall; |
| 119 |
//IOleInPlaceSite |
| 120 |
function CanInPlaceActivate : HResult;stdcall; |
| 121 |
function OnInPlaceActivate : HResult;stdcall; |
| 122 |
function OnUIActivate : HResult;stdcall; |
| 123 |
function GetWindowContext(out ppframe:IOleInPlaceFrame;out ppdoc:IOleInPlaceUIWindow;lprcposrect:LPRECT;lprccliprect:LPRECT;lpframeinfo:LPOLEINPLACEFRAMEINFO):hresult; stdcall; |
| 124 |
function Scroll(scrollExtant:TSIZE):hresult; stdcall; |
| 125 |
function OnUIDeactivate(fUndoable:BOOL):hresult; stdcall; |
| 126 |
function OnInPlaceDeactivate :hresult; stdcall; |
| 127 |
function DiscardUndoState :hresult; stdcall; |
| 128 |
function DeactivateAndUndo :hresult; stdcall; |
| 129 |
function OnPosRectChange(lprcPosRect:LPRect):hresult; stdcall; |
| 130 |
//IOleWindow |
| 131 |
function GetWindow(out wnd: HWnd): HResult; stdcall; |
| 132 |
function ContextSensitiveHelp(fEnterMode: BOOL): HResult; stdcall; |
| 133 |
//IOleInPlaceFrame |
| 134 |
function InsertMenus(hmenuShared: HMenu; var menuWidths: TOleMenuGroupWidths): HResult;StdCall; |
| 135 |
function SetMenu(hmenuShared: HMenu; holemenu: HMenu; hwndActiveObject: HWnd): HResult;StdCall; |
| 136 |
function RemoveMenus(hmenuShared: HMenu): HResult;StdCall; |
| 137 |
function SetStatusText(pszStatusText: POleStr): HResult;StdCall; |
| 138 |
function EnableModeless(fEnable: BOOL): HResult;StdCall; |
| 139 |
function TranslateAccelerator(var msg: TMsg; wID: Word): HResult;StdCall;overload; |
| 140 |
//IOleInPlaceUIWindow |
| 141 |
function GetBorder(out rectBorder: TRect):HResult;StdCall; |
| 142 |
function RequestBorderSpace(const borderwidths: TRect):HResult;StdCall; |
| 143 |
function SetBorderSpace(const borderwidths: TRect):HResult;StdCall; |
| 144 |
function SetActiveObject(const activeObject: IOleInPlaceActiveObject;pszObjName: POleStr):HResult;StdCall; |
| 145 |
//IDispatch |
| 146 |
function GetTypeInfoCount(out count : longint) : HResult;stdcall; |
| 147 |
function GetTypeInfo(Index,LocaleID : longint; |
| 148 |
out TypeInfo): HResult;stdcall; |
| 149 |
function GetIDsOfNames(const iid: TGUID; names: Pointer; |
| 150 |
NameCount, LocaleID: LongInt; DispIDs: Pointer) : HResult;stdcall; |
| 151 |
function Invoke(DispID: LongInt;const iid : TGUID; |
| 152 |
LocaleID : longint; Flags: Word;var params; |
| 153 |
VarResult,ExcepInfo,ArgErr : pointer) : HResult;stdcall; |
| 154 |
//internal |
| 155 |
procedure Attach; |
| 156 |
procedure Detach; |
| 157 |
public |
| 158 |
constructor Create(TheOwner: TComponent); override; |
| 159 |
destructor Destroy; override; |
| 160 |
//VT_DISPATCH variant used for late binding |
| 161 |
property vObject:Variant read GetvObject; |
| 162 |
published |
| 163 |
//ActiveX object is automatically created from classname and destroyed when set |
| 164 |
property OleClassName:string read FClassName write SetClassName; |
| 165 |
{IDispatch interface for ActiveX object. Overrides classname. Set ComServer |
| 166 |
when you create and destroy the object yourself, fe. using CoClass. |
| 167 |
When Active, returns the IDispatch for the object. |
| 168 |
} |
| 169 |
property ComServer:IDispatch read FOleObject write SetOleObject; |
| 170 |
{When set, binds ActiveX component to control. |
| 171 |
When cleared, detaches the component from the control |
| 172 |
If Classname is provided the ActiveX component will also be created and destroyed |
| 173 |
automatically.} |
| 174 |
property Active:boolean read FActive write SetActive; |
| 175 |
property Handle: HWND read FHandle write SetHandle; |
| 176 |
end; |
| 177 |
|
| 178 |
implementation |
| 179 |
|
| 180 |
{$ifdef wince} |
| 181 |
const |
| 182 |
GWLP_USERDATA=GWL_USERDATA; |
| 183 |
|
| 184 |
function GetWindowLongPtrW(hWnd:HWND; nIndex:longint):LONG; |
| 185 |
begin |
| 186 |
result:=GetWindowLongW(hWnd, nIndex); |
| 187 |
end; |
| 188 |
|
| 189 |
function SetWindowLongPtrW(hWnd:HWND; nIndex:longint; dwNewLong:LONG):LONG; |
| 190 |
begin |
| 191 |
result:=SetWindowLongW(hWnd, nIndex, dwNewLong); |
| 192 |
end; |
| 193 |
|
| 194 |
function SetWindowLongPtr(hWnd:HWND; nIndex:longint; dwNewLong:LONG):LONG; |
| 195 |
begin |
| 196 |
result:=SetWindowLongW(hWnd, nIndex, dwNewLong); |
| 197 |
end; |
| 198 |
{$endif wince} |
| 199 |
|
| 200 |
function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; |
| 201 |
lParam: LParam): LRESULT; stdcall; |
| 202 |
var |
| 203 |
bounds:TRect; |
| 204 |
DC: HDC; |
| 205 |
size:TPOINT; |
| 206 |
AXC:TActiveXContainer; |
| 207 |
begin |
| 208 |
AXC:=TActiveXContainer(GetWindowLongPtrW( Ahwnd, GWLP_USERDATA)); |
| 209 |
case uMsg of |
| 210 |
WM_DESTROY:AXC.Detach; |
| 211 |
WM_SIZE: |
| 212 |
begin |
| 213 |
size.x:=(LOWORD(lparam)*2540) div AXC.FPixelsPerInchX; |
| 214 |
size.y:=(HIWORD(lparam)*2540) div AXC.FPixelsPerInchY; |
| 215 |
MoveWindow(AXC.FHandle, 0, 0, LOWORD(lparam), HIWORD(lparam), True); |
| 216 |
olecheck((AXC.ComServer as IOleObject).SetExtent(DVASPECT_CONTENT,size)); |
| 217 |
GetClientRect(AXC.FHandle, @bounds); |
| 218 |
olecheck((AXC.ComServer as IOleInPlaceObject).SetObjectRects(@bounds,@bounds)); |
| 219 |
end; |
| 220 |
WM_PAINT: |
| 221 |
begin |
| 222 |
DC:=GetDC(AXC.handle); |
| 223 |
GetClientRect(AXC.FHandle, @bounds); |
| 224 |
olecheck((AXC.ComServer as IViewObject).Draw(DVASPECT_CONTENT,0,nil,nil,0,DC,@bounds,@bounds,nil,0)); |
| 225 |
ReleaseDC(AXC.handle,DC); |
| 226 |
end; |
| 227 |
end; |
| 228 |
result:=CallWindowProc(AXC.FPrevWndProc,Ahwnd, uMsg, WParam, LParam); |
| 229 |
end; |
| 230 |
|
| 231 |
{ TActiveXContainer } |
| 232 |
|
| 233 |
function TActiveXContainer.GetvObject: variant; |
| 234 |
begin |
| 235 |
result:=FOleObject; |
| 236 |
end; |
| 237 |
|
| 238 |
function TActiveXContainer.SaveObject: HResult; StdCall; |
| 239 |
begin |
| 240 |
Result := S_OK; |
| 241 |
end; |
| 242 |
|
| 243 |
function TActiveXContainer.GetMoniker(dwAssign: Longint; dwWhichMoniker: Longint; out |
| 244 |
mk: IMoniker): HResult; StdCall; |
| 245 |
begin |
| 246 |
mk := nil; |
| 247 |
Result := E_NOTIMPL; |
| 248 |
end; |
| 249 |
|
| 250 |
function TActiveXContainer.GetContainer(out container: IOleContainer): HResult; |
| 251 |
StdCall; |
| 252 |
begin |
| 253 |
container := nil; |
| 254 |
Result := E_NOINTERFACE; |
| 255 |
end; |
| 256 |
|
| 257 |
procedure TActiveXContainer.SetActive(AValue: boolean); |
| 258 |
begin |
| 259 |
if FActive=AValue then Exit; |
| 260 |
if AValue then |
| 261 |
begin |
| 262 |
if (FClassName='') and not assigned(ComServer) then |
| 263 |
raise exception.Create('OleClassName and ComServer not assigned.'); |
| 264 |
if not assigned(FOleObject) then |
| 265 |
FOleObject:=CreateOleObject(FClassName); |
| 266 |
Attach; |
| 267 |
end |
| 268 |
else |
| 269 |
begin |
| 270 |
Detach; |
| 271 |
if FClassName<>'' then //destroy com object |
| 272 |
FOleObject:=nil; |
| 273 |
end; |
| 274 |
FActive:=AValue; |
| 275 |
end; |
| 276 |
|
| 277 |
procedure TActiveXContainer.SetClassName(AValue: string); |
| 278 |
begin |
| 279 |
if (FClassName=AValue) or FActive then Exit; |
| 280 |
FClassName:=AValue; |
| 281 |
end; |
| 282 |
|
| 283 |
procedure TActiveXContainer.SetHandle(AValue: HWND); |
| 284 |
var |
| 285 |
DC: HDC; |
| 286 |
begin |
| 287 |
if FHandle=AValue then Exit; |
| 288 |
FHandle:=AValue; |
| 289 |
|
| 290 |
DC:= GetDC(FHandle); |
| 291 |
FPixelsPerInchX := GetDeviceCaps(DC, LOGPIXELSX); |
| 292 |
FPixelsPerInchY := GetDeviceCaps(DC, LOGPIXELSY); |
| 293 |
ReleaseDC(FHandle, DC); |
| 294 |
end; |
| 295 |
|
| 296 |
procedure TActiveXContainer.SetOleObject(AValue: IDispatch); |
| 297 |
begin |
| 298 |
if (FOleObject=AValue) or FActive then Exit; |
| 299 |
FOleObject:=AValue; |
| 300 |
end; |
| 301 |
|
| 302 |
function TActiveXContainer.ShowObject: HResult; StdCall; |
| 303 |
begin |
| 304 |
Result := S_OK; |
| 305 |
end; |
| 306 |
|
| 307 |
function TActiveXContainer.OnShowWindow(fShow: BOOL): HResult; StdCall; |
| 308 |
begin |
| 309 |
Result := S_OK; |
| 310 |
end; |
| 311 |
|
| 312 |
function TActiveXContainer.RequestNewObjectLayout: HResult; StdCall; |
| 313 |
begin |
| 314 |
Result := S_OK; |
| 315 |
end; |
| 316 |
|
| 317 |
function TActiveXContainer.OnControlInfoChanged: HResult; stdcall; |
| 318 |
begin |
| 319 |
Result := E_NOTIMPL; |
| 320 |
end; |
| 321 |
|
| 322 |
function TActiveXContainer.LockInPlaceActive(fLock: BOOL): HResult; stdcall; |
| 323 |
begin |
| 324 |
Result := E_NOTIMPL; |
| 325 |
end; |
| 326 |
|
| 327 |
function TActiveXContainer.GetExtendedControl(out disp: IDispatch): HResult; stdcall; |
| 328 |
begin |
| 329 |
Result := E_NOTIMPL; |
| 330 |
end; |
| 331 |
|
| 332 |
function TActiveXContainer.TransformCoords(var ptlHimetric: TPoint; |
| 333 |
var ptfContainer: TPointF; flags: Longint): HResult; stdcall; |
| 334 |
begin |
| 335 |
if flags and 4 <> 0 then //XFORMCOORDS_HIMETRICTOCONTAINER=4 |
| 336 |
begin |
| 337 |
ptfContainer.X := (ptlHimetric.X * FPixelsPerInchX) div 2540; |
| 338 |
ptfContainer.Y := (ptlHimetric.Y * FPixelsPerInchY) div 2540; |
| 339 |
end |
| 340 |
else if assigned(@ptlHimetric) and (flags and 8 <> 0) then //XFORMCOORDS_CONTAINERTOHIMETRIC = 8 |
| 341 |
begin |
| 342 |
ptlHimetric.X := Integer(Round(ptfContainer.X * 2540 / FPixelsPerInchX)); |
| 343 |
ptlHimetric.Y := Integer(Round(ptfContainer.Y * 2540 / FPixelsPerInchY)); |
| 344 |
end; |
| 345 |
Result := S_OK; |
| 346 |
end; |
| 347 |
|
| 348 |
function TActiveXContainer.TranslateAccelerator(msg: PMsg; grfModifiers: Longint |
| 349 |
): HResult; stdcall; |
| 350 |
begin |
| 351 |
Result := E_NOTIMPL; |
| 352 |
end; |
| 353 |
|
| 354 |
function TActiveXContainer.OnFocus(fGotFocus: BOOL): HResult; stdcall; |
| 355 |
begin |
| 356 |
Result := S_OK; |
| 357 |
end; |
| 358 |
|
| 359 |
function TActiveXContainer.ShowPropertyFrame: HResult; stdcall; |
| 360 |
begin |
| 361 |
Result := E_NOTIMPL; |
| 362 |
end; |
| 363 |
|
| 364 |
function TActiveXContainer.CanInPlaceActivate: HResult;stdcall; |
| 365 |
begin |
| 366 |
Result := S_OK; |
| 367 |
end; |
| 368 |
|
| 369 |
function TActiveXContainer.OnInPlaceActivate: HResult;stdcall; |
| 370 |
begin |
| 371 |
Result := S_OK; |
| 372 |
end; |
| 373 |
|
| 374 |
function TActiveXContainer.OnUIActivate: HResult; stdcall; |
| 375 |
begin |
| 376 |
Result := S_OK; |
| 377 |
end; |
| 378 |
|
| 379 |
function TActiveXContainer.GetWindowContext(out ppframe: IOleInPlaceFrame; out |
| 380 |
ppdoc: IOleInPlaceUIWindow; lprcposrect: LPRECT; lprccliprect: LPRECT; |
| 381 |
lpframeinfo: LPOLEINPLACEFRAMEINFO): hresult; stdcall; |
| 382 |
begin |
| 383 |
if assigned (ppframe) then |
| 384 |
ppframe := Self as IOleInPlaceFrame; |
| 385 |
if assigned(ppdoc) then |
| 386 |
ppdoc:= nil; |
| 387 |
if assigned(lpframeinfo) then |
| 388 |
begin |
| 389 |
lpframeinfo.fMDIApp := False; |
| 390 |
lpframeinfo.cAccelEntries := 0; |
| 391 |
lpframeinfo.haccel := 0; |
| 392 |
lpframeinfo.hwndFrame := Handle; |
| 393 |
end; |
| 394 |
|
| 395 |
if assigned (lprcPosRect) then |
| 396 |
GetClientRect(FHandle, lprcPosRect); |
| 397 |
if assigned (lprcClipRect) then |
| 398 |
GetClientRect(FHandle, lprcClipRect); |
| 399 |
|
| 400 |
Result := S_OK; |
| 401 |
end; |
| 402 |
|
| 403 |
function TActiveXContainer.Scroll(scrollExtant: TSIZE): hresult; stdcall; |
| 404 |
begin |
| 405 |
Result := E_NOTIMPL; |
| 406 |
end; |
| 407 |
|
| 408 |
function TActiveXContainer.OnUIDeactivate(fUndoable: BOOL): hresult; stdcall; |
| 409 |
begin |
| 410 |
Result := S_OK; |
| 411 |
end; |
| 412 |
|
| 413 |
function TActiveXContainer.OnInPlaceDeactivate: hresult; stdcall; |
| 414 |
begin |
| 415 |
Result := S_OK; |
| 416 |
end; |
| 417 |
|
| 418 |
function TActiveXContainer.DiscardUndoState: hresult; stdcall; |
| 419 |
begin |
| 420 |
Result := E_NOTIMPL; |
| 421 |
end; |
| 422 |
|
| 423 |
function TActiveXContainer.DeactivateAndUndo: hresult; stdcall; |
| 424 |
begin |
| 425 |
Result := E_NOTIMPL; |
| 426 |
end; |
| 427 |
|
| 428 |
function TActiveXContainer.OnPosRectChange(lprcPosRect: LPRect): hresult; stdcall; |
| 429 |
begin |
| 430 |
Result := S_OK; |
| 431 |
end; |
| 432 |
|
| 433 |
function TActiveXContainer.GetWindow(out wnd: HWnd): HResult; stdcall; |
| 434 |
begin |
| 435 |
wnd:=Handle; |
| 436 |
Result := S_OK; |
| 437 |
end; |
| 438 |
|
| 439 |
function TActiveXContainer.ContextSensitiveHelp(fEnterMode: BOOL): HResult; stdcall; |
| 440 |
begin |
| 441 |
Result := E_NOTIMPL; |
| 442 |
end; |
| 443 |
|
| 444 |
function TActiveXContainer.InsertMenus(hmenuShared: HMenu; |
| 445 |
var menuWidths: TOleMenuGroupWidths): HResult; StdCall; |
| 446 |
begin |
| 447 |
Result := E_NOTIMPL; |
| 448 |
end; |
| 449 |
|
| 450 |
function TActiveXContainer.SetMenu(hmenuShared: HMenu; holemenu: HMenu; |
| 451 |
hwndActiveObject: HWnd): HResult; StdCall; |
| 452 |
begin |
| 453 |
Result := E_NOTIMPL; |
| 454 |
end; |
| 455 |
|
| 456 |
function TActiveXContainer.RemoveMenus(hmenuShared: HMenu): HResult; StdCall; |
| 457 |
begin |
| 458 |
Result := S_OK; |
| 459 |
end; |
| 460 |
|
| 461 |
function TActiveXContainer.SetStatusText(pszStatusText: POleStr): HResult; StdCall; |
| 462 |
begin |
| 463 |
if assigned(FOnStatusText) then |
| 464 |
FOnStatusText(Self,utf8encode(WideString(pszStatusText))); |
| 465 |
Result := S_OK; |
| 466 |
end; |
| 467 |
|
| 468 |
function TActiveXContainer.EnableModeless(fEnable: BOOL): HResult; StdCall; |
| 469 |
begin |
| 470 |
Result := S_OK; |
| 471 |
end; |
| 472 |
|
| 473 |
function TActiveXContainer.TranslateAccelerator(var msg: TMsg; wID: Word): HResult; |
| 474 |
StdCall; |
| 475 |
begin |
| 476 |
Result := E_NOTIMPL; |
| 477 |
end; |
| 478 |
|
| 479 |
function TActiveXContainer.GetBorder(out rectBorder: TRect): HResult; StdCall; |
| 480 |
begin |
| 481 |
Result := INPLACE_E_NOTOOLSPACE; |
| 482 |
end; |
| 483 |
|
| 484 |
function TActiveXContainer.RequestBorderSpace(const borderwidths: TRect): HResult; |
| 485 |
StdCall; |
| 486 |
begin |
| 487 |
Result := INPLACE_E_NOTOOLSPACE; |
| 488 |
end; |
| 489 |
|
| 490 |
function TActiveXContainer.SetBorderSpace(const borderwidths: TRect): HResult; |
| 491 |
StdCall; |
| 492 |
begin |
| 493 |
Result := E_NOTIMPL; |
| 494 |
end; |
| 495 |
|
| 496 |
function TActiveXContainer.SetActiveObject( |
| 497 |
const activeObject: IOleInPlaceActiveObject; pszObjName: POleStr): HResult; |
| 498 |
StdCall; |
| 499 |
begin |
| 500 |
Result := S_OK; |
| 501 |
end; |
| 502 |
|
| 503 |
function TActiveXContainer.GetTypeInfoCount(out count: longint): HResult; |
| 504 |
stdcall; |
| 505 |
begin |
| 506 |
Count := 0; |
| 507 |
Result := S_OK; |
| 508 |
end; |
| 509 |
|
| 510 |
function TActiveXContainer.GetTypeInfo(Index, LocaleID: longint; out TypeInfo |
| 511 |
): HResult; stdcall; |
| 512 |
begin |
| 513 |
Pointer(TypeInfo) := nil; |
| 514 |
Result := E_NOTIMPL; |
| 515 |
end; |
| 516 |
|
| 517 |
function TActiveXContainer.GetIDsOfNames(const iid: TGUID; names: Pointer; |
| 518 |
NameCount, LocaleID: LongInt; DispIDs: Pointer): HResult; stdcall; |
| 519 |
begin |
| 520 |
Result := E_NOTIMPL; |
| 521 |
end; |
| 522 |
|
| 523 |
function TActiveXContainer.Invoke(DispID: LongInt; const iid: TGUID; |
| 524 |
LocaleID: longint; Flags: Word; var params; VarResult, ExcepInfo, |
| 525 |
ArgErr: pointer): HResult; stdcall; |
| 526 |
const |
| 527 |
DISPID_AMBIENT_BACKCOLOR = -701; |
| 528 |
DISPID_AMBIENT_DISPLAYNAME = -702; |
| 529 |
DISPID_AMBIENT_FONT = -703; |
| 530 |
DISPID_AMBIENT_FORECOLOR = -704; |
| 531 |
DISPID_AMBIENT_LOCALEID = -705; |
| 532 |
DISPID_AMBIENT_MESSAGEREFLECT = -706; |
| 533 |
DISPID_AMBIENT_USERMODE = -709; |
| 534 |
DISPID_AMBIENT_UIDEAD = -710; |
| 535 |
DISPID_AMBIENT_SHOWGRABHANDLES = -711; |
| 536 |
DISPID_AMBIENT_SHOWHATCHING = -712; |
| 537 |
DISPID_AMBIENT_SUPPORTSMNEMONICS = -714; |
| 538 |
DISPID_AMBIENT_AUTOCLIP = -715; |
| 539 |
begin |
| 540 |
if (Flags and DISPATCH_PROPERTYGET <> 0) and (VarResult <> nil) then |
| 541 |
begin |
| 542 |
Result := S_OK; |
| 543 |
case DispID of |
| 544 |
// DISPID_AMBIENT_BACKCOLOR: |
| 545 |
// PVariant(VarResult)^ := Color; |
| 546 |
DISPID_AMBIENT_DISPLAYNAME: |
| 547 |
PVariant(VarResult)^ := OleVariant(Name); |
| 548 |
DISPID_AMBIENT_FONT: |
| 549 |
PVariant(VarResult)^ :=nil; |
| 550 |
// DISPID_AMBIENT_FORECOLOR: |
| 551 |
// PVariant(VarResult)^ := Font.Color; |
| 552 |
DISPID_AMBIENT_LOCALEID: |
| 553 |
PVariant(VarResult)^ := Integer(GetUserDefaultLCID); |
| 554 |
DISPID_AMBIENT_MESSAGEREFLECT: |
| 555 |
PVariant(VarResult)^ := False; |
| 556 |
DISPID_AMBIENT_USERMODE: |
| 557 |
PVariant(VarResult)^ := not (csDesigning in ComponentState); |
| 558 |
DISPID_AMBIENT_UIDEAD: |
| 559 |
PVariant(VarResult)^ := csDesigning in ComponentState; |
| 560 |
DISPID_AMBIENT_SHOWGRABHANDLES: |
| 561 |
PVariant(VarResult)^ := False; |
| 562 |
DISPID_AMBIENT_SHOWHATCHING: |
| 563 |
PVariant(VarResult)^ := False; |
| 564 |
DISPID_AMBIENT_SUPPORTSMNEMONICS: |
| 565 |
PVariant(VarResult)^ := True; |
| 566 |
DISPID_AMBIENT_AUTOCLIP: |
| 567 |
PVariant(VarResult)^ := True; |
| 568 |
else |
| 569 |
Result := DISP_E_MEMBERNOTFOUND; |
| 570 |
end; |
| 571 |
end else |
| 572 |
Result := DISP_E_MEMBERNOTFOUND; |
| 573 |
end; |
| 574 |
|
| 575 |
procedure TActiveXContainer.Attach; |
| 576 |
var |
| 577 |
size:TPOINT; |
| 578 |
ARect: TRect; |
| 579 |
begin |
| 580 |
SetWindowLongPtr(Handle,GWLP_USERDATA, PtrInt(Self)); |
| 581 |
FPrevWndProc:=Windows.WNDPROC(SetWindowLongPtr(Handle,GWL_WNDPROC,PtrInt(@WndCallback))); |
| 582 |
FAttached:=true; |
| 583 |
olecheck((FOleObject as IOleObject).SetClientSite(Self as IOleClientSite)); |
| 584 |
olecheck((FOleObject as IOleObject).SetHostNames(PWideChar(name),PWideChar(name))); |
| 585 |
GetClientRect(FHandle, ARect); |
| 586 |
size.x:=(ARect.Width*2540) div FPixelsPerInchX; |
| 587 |
size.y:=(ARect.Height*2540) div FPixelsPerInchY; |
| 588 |
olecheck((FOleObject as IOleObject).SetExtent(DVASPECT_CONTENT,size)); |
| 589 |
olecheck((FOleObject as IOleObject).DoVerb(OLEIVERB_INPLACEACTIVATE,nil,Self as IOleClientSite,0,Handle,ARect)); |
| 590 |
end; |
| 591 |
|
| 592 |
procedure TActiveXContainer.Detach; |
| 593 |
const |
| 594 |
OLECLOSE_NOSAVE = 1; |
| 595 |
begin |
| 596 |
if FAttached then |
| 597 |
begin |
| 598 |
SetWindowLongPtr(Handle,GWL_WNDPROC,PtrInt(@FPrevWndProc)); |
| 599 |
SetWindowLongPtr(Handle,GWLP_USERDATA, 0); |
| 600 |
end; |
| 601 |
if assigned(FOleObject) then |
| 602 |
begin |
| 603 |
olecheck((FOleObject as IOleObject).SetClientSite(nil)); |
| 604 |
olecheck((FOleObject as IOleObject).Close(OLECLOSE_NOSAVE)); |
| 605 |
end; |
| 606 |
end; |
| 607 |
|
| 608 |
constructor TActiveXContainer.Create(TheOwner: TComponent); |
| 609 |
begin |
| 610 |
inherited Create(TheOwner); |
| 611 |
end; |
| 612 |
|
| 613 |
destructor TActiveXContainer.Destroy; |
| 614 |
begin |
| 615 |
Active:=false; //destroys com object if created by Self |
| 616 |
inherited Destroy; |
| 617 |
end; |
| 618 |
|
| 619 |
end. |
| 620 |
|