Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#24

AW: Classe/Interface aus WinProc aufrufen

  Alt 14. Sep 2017, 17:42
Die Anwendung fordert das Interface an.

  PopUpMenu := CTRL_PopUpMenuCreate(PopUpCallback);
Delphi-Quellcode:
procedure TMainApp.CreatePopUpMenu(WinHandle: HWND);
var
  PrivateFont: PWideChar;
begin
  PopUpMenu := CTRL_PopUpMenuCreate(PopUpCallback);
  PopUpMenu.Width := CLIENT_WIDTH;
  PopUpMenu.Height := CLIENT_HEIGHT;
  PopUpMenu.SkinConfigFile := PWideChar(FolderResource + 'PopUpWindow\OTTB.ske');
  PopUpMenu.UseVistaCrystal := true;
  PopUpMenu.UseVistaBlur := false;
  PopUpMenu.UseSideBar := True;
  PopUpMenu.SideBarImgPath := '';
  PopUpMenu.SelectedImgPath := FolderResource + 'PopUpWindow\MEN_Select.png';
  PopUpMenu.IconArrowPath := '';
  PopUpMenu.SeperatorImgPath := '';
  PopUpMenu.SideBarCaption := 'Over the TaskBar';
  PopUpMenu.SideBarCaptionLeft := 12;
  PopUpMenu.SideBarCaptionTop := 198;
  PopUpMenu.ImageStateMax := 0;
  PopUpMenu.ItemHeight := 20;
  PopUpMenu.ItemWidth := 190;
  PopUpMenu.ItemLeft := 29;
  PopUpMenu.ItemShadow := 1;
  PopUpMenu.ItemTextLeft := 20;

  hPopUpHandle := PopUpMenu.CreatePopUpMenu(WinHandle);
  if hPopUpHandle <> 0 then
  begin
    AppendMenu(hPopUpHandle);

    PrivateFont := PWideChar(FolderResource + 'PopUpWindow\OTTB.ttf');
    PopUpMenu.FontName := 'Nasalization Free';
    PopUpMenu.FontSize := 14;
    PopUpMenu.CreatePrivateFont(PrivateFont);

    gP.hPopUpMenu := hPopUpHandle;
  end;
end;
Anschließend werden die Variablen an das Interface der DLL übergeben.
Delphi-Quellcode:
procedure TMainApp.AppendMenu(hMain: HWND);
var
  Text: PWideChar;

procedure Append(Handle: HWND; ItemShadow: integer; ItemIconPath: WideString;
  ItemToolTip: PWideChar; ItemHiliteColor: COLORREF; ItemTextAlligment: TTextAlligment;
  Top: integer; Flags, DlgItemID: UINT; Text: PWideChar; Enabled: BOOL = True);
begin
  PopUpMenu.ItemShadow := ItemShadow;
  PopUpMenu.ItemIconPath := ItemIconPath;
  PopUpMenu.ItemToolTip := ItemToolTip;
  PopUpMenu.ItemHiliteColor := ItemHiliteColor;
  PopUpMenu.ItemTextAlligment := ItemTextAlligment;
  PopUpMenu.ItemTop := Top;
  PopUpMenu.ItemEnabled := Enabled;
  PopUpMenu.AppendMenu(Handle, Flags, DlgItemID, Text);
end;

begin

  panBackgoundFrame := CTRL_FrameButtonCreate();
  panBackgoundFrame.ImagePath := SKAERO_FOLDER + 'Frame.png';
  panBackgoundFrame.Left := 9;
  panBackgoundFrame.Top := 9;
  panBackgoundFrame.Width := 210;
  panBackgoundFrame.Height := 340;
  panBackgoundFrame.DlgItemID := ID_BACKGROUNDFRAME;
  panBackgoundFrame.ImageStateMax := 0;
  panBackgoundFrame.Enabled := false;
  panBackgoundFrame.Visible := True;
  panBackgoundFrame.CreateWindow(hMain);
  SKAERO_SetAnchorMode(panBackgoundFrame.Handle, ANCHOR_HEIGHT_WIDTH);
  SKAERO_SetZorder(panBackgoundFrame.Handle, HWND_TOP);

  // About
  Append(PopUpMenu.Handle, 1, '', 'Oops...' + CHR(13) + 'Are they in the wrong place?',
    SKAERO_BTNTEXTCOLOR, Left, 9, MF_OWNERDRAW, IDM_About, 'About');

  // Icon frame
  Append(PopUpMenu.Handle, 1, '', '', SKAERO_BTNTEXTCOLOR, Left, 49, MF_OWNERDRAW, IDM_IconFrame,
    'Icon frame');

  // Background layer
  Append(PopUpMenu.Handle, 1, '', '', SKAERO_BTNTEXTCOLOR, Left, 69, MF_OWNERDRAW, IDM_IconBack,
    'Background layer');

  // Change Wallpaper
  Append(PopUpMenu.Handle, 1, '', '', SKAERO_BTNTEXTCOLOR, Left, 89, MF_OWNERDRAW, IDM_Wallpaper,
    'Change Wallpaper');

  // Shortcut
  if gP.ShortCutVisible then
    Text := 'Hide shor cut'
  else
  Text := 'Show short cut';
  Append(PopUpMenu.Handle, 1, '', '', SKAERO_BTNTEXTCOLOR, Left, 129, MF_OWNERDRAW, IDM_ShortCut,
    Text);

  // Sound
  if gP.SoundActive then
    Text := 'Disable sound'
  else
  Text := 'Enable sound';
  Append(PopUpMenu.Handle, 1, '', '', SKAERO_BTNTEXTCOLOR, Left, 169, MF_OWNERDRAW, IDM_Sound,
    Text);

  // Build Config file
  Append(PopUpMenu.Handle, 1, '', '', SKAERO_BTNTEXTCOLOR, Left, 209, MF_OWNERDRAW, IDM_BuildCONFIG,
    'Build Config file');

  // Edit Config file
  Append(PopUpMenu.Handle, 1, '', '', SKAERO_BTNTEXTCOLOR, Left, 229, MF_OWNERDRAW, IDM_Edit,
    'Edit Config file');

  // Cleanup Config file
  Append(PopUpMenu.Handle, 1, '', '', SKAERO_BTNTEXTCOLOR, Left, 249, MF_OWNERDRAW, IDM_Cleanup,
    'Cleanup Config file');

  // Restart OverTheTaskBar
  Append(PopUpMenu.Handle, 1, '', '', SKAERO_BTNTEXTCOLOR, Left, 269, MF_OWNERDRAW, IDM_Restart,
    'Restart OverTheTaskBar');

  // Portable App
  if gP.Portable then
    Text := 'Disable Portable App'
  else
  Text := 'Enable Portable App';
  Append(PopUpMenu.Handle, 1, '', '', SKAERO_BTNTEXTCOLOR, Left, 309, MF_OWNERDRAW, IDM_PORTABLE,
    Text);

  // Close OverTheTaskBar
  Append(PopUpMenu.Handle, 1, '', '', SKAERO_BTNTEXTCOLOR, Left, 329, MF_OWNERDRAW, IDM_Close,
  'Close OverTheTaskBar');

end;
diese übernimmt nun das Zeichen und alle anderen dinge die mit dem Menu zu tun haben.
Das war's.

Aber entladen wird das Interface nicht.
Warum habe ich schon gesagt.

wird die Callback abgefeuert
Delphi-Quellcode:
procedure PopUpCallback(PopUpState: TPopUpState); stdcall;
begin
  case PopUpState of
    OnPopupDestroyed:
      PopUpMenu := nil;
  end;
end;
wird nur das PopUpMenu der Anwendung auf Nil gesetzt.
Das Interface in der DLL sollte dann schon NIL sein.

EDIT:
Das Menu wird dann in der WinProc gestartet.
Delphi-Quellcode:
    WM_RBUTTONDOWN:
      begin
        if PopUpMenu <> nil then
          PopUpMenu.DestroyWindow;

        nObjectID := MainApp.GetMouseMoveSpriteID(WinHandle, lpX, lpY);
        if nObjectID = 0 then
        begin

          SKAERO_CONFIG_ShadowColor(SKAERO_ColorARGB(255, RGB(0, 0, 0)), SKAERO_WRITE);
          KillTimer(MainHandle, 1);
          MainApp.CreatePopupMenu(WinHandle);

          GetCursorPos(P);
          GetWindowRect(gP.hPopUpMenu, Rect);
          ClientToScreen(gP.hPopUpMenu, P);

          MenuWahl := PopUpMenu.TrackPopupMenu(gP.hPopUpMenu, P.X - 7, (P.Y - Rect.Bottom) + 9,
            Rect.Right, Rect.Bottom);

          if MenuWahl then
            SendMessage(WinHandle, WM_COMMAND, Makelong(word(MenuWahl), 0), 0);
Wenn man zweimal hintereinander den rechten Button klickt wird das Menu über PopUpMenu.DestroyWindow; zerstört.
Andernfalls wird es in der DLL beendet.

gruss

Geändert von EWeiss (14. Sep 2017 um 17:54 Uhr)
  Mit Zitat antworten Zitat