AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Convert sample from platform SDK to Delphi
Thema durchsuchen
Ansicht
Themen-Optionen

Convert sample from platform SDK to Delphi

Offene Frage von "Remko"
Ein Thema von Remko · begonnen am 21. Dez 2006 · letzter Beitrag vom 27. Dez 2006
Antwort Antwort
Robert Marquardt
(Gast)

n/a Beiträge
 
#1

Re: Convert sample from platform SDK to Delphi

  Alt 22. Dez 2006, 13:17
Code:
   CPropSheetHost *pThis = (CPropSheetHost*)((LONG_PTR)GetWindowLongPtr(hWnd, VIEW_POINTER_OFFSET));
This is a local variable which is immediately initialized. GetWindowLongPtr supersedes GetWindowLong. You can use GetWindowLong instead.
The value pulled is the this or Self value handed in as parameter to CreateWindowEx.
Code:
    switch (uMessage)
    {
    case WM_NCCREATE:
        {
            LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
            pThis = (CPropSheetHost*)(lpcs->lpCreateParams);
            ::SetWindowLongPtr(hWnd, VIEW_POINTER_OFFSET, (LONG)(LONG_PTR)pThis);
Now here the value is extracted from the CREATESTRUCT structure and stuffed into the extra data area of the window.
This works because WM_NCCREATE is about the first message received so the above variable initialization almost always pulls the value.
It just fails for WM_NCCREATE itself where it gets an uninitialized value, but in this case the variable is initialized from the CREATESTRUCT.
It is a bit overcoded and it contains a bug. The code is not 64 bit safe. (LONG)(LONG_PTR) is a double typecast which first casts the pointer to the type LONG_PTR. LONG_PTR can hold a 64 bit value. Unfortunately it is then casted to LONG which can hold only 32 bits. So the second typecast is actually a bug.

So this is just a trick to be always able to return to object land each time _HiddenWindowProc is called with a message.
Delphi-Quellcode:
var
  Form: TForm1; // or whatever type you have handed in to CreateWindowEx
begin
  Form := GetWindowLong(hWnd, VIEW_POINTER_OFFSET));
  case Msg of
    WM_NCCREATE:
      SetWindowLong(hWnd, VIEW_POINTER_OFFSET, LONG(LPCREATESTRUCT(lParam).lpCreateParams));
This is the trick in Delphi. You can of course drop all this and just access the global variable Form1 Delphi has created for you already.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:49 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz