![]() |
Tray Programm ohne VCL
Hallo,
ich möchte eine kleine Tray App schreiben: ![]() Aber da diese ohne Forms auskommen soll, ist es Blödsinn die forms.pas mitzucompilen und das Fenster nur mit Application.ShowMainForm := False zu verstecken. Wenn ich eine Console App schreibe und das {$APPTYPE CONSOLE} weglasse, habe ich aber kein OnCreate und OnClose Event mehr. Das Programm beendet sich wenn es bei end ankommt. Wie mache ich das nun? Mfg Novo |
AW: Tray Programm ohne VCL
Du musst, ein Fenster per WinAPI erzeugen.
Ein Programm, das auf VCL-basiert, hat dies schon gemacht und hat eine sogenannte Message-Schleife. Diese musst du selbst erzeugen. Hab grad nicht den Link, aber Luckie hier im Forum, hat ein paar gute Demos, sowie eine Docu geschrieben, wie man sowas macht. So oder so musst du ein Fenster erzeugen, du kannst aber die Höhe, Breite und Pos auf 0 setzten, dann ist es "unsichtbar". Und danach kannst du das TrayIcon in etwa genauso erzeugen. Ich glaub sogar bei den Demos ist eine TrayIcon Demo dabei, wie du sie haben willst. |
AW: Tray Programm ohne VCL
0?
Warum nicht ausblenden? (Visible) Wenn du eine Konsolenanwendung hast (egal ob mit oder ohne Konsolenfenster), dann gibt es keine Nachrichtenschkleife, welche bei der VCL im
Delphi-Quellcode:
abgearbeitet wird.
Application.Run;
Ohne Fenster beendet sich eine VCL-Anwendung natürlich. (genauer, wenn das Hauptfenster geschlossen wird oder es nie existierte) Schau dich bei Luckie auf der Webseite mal um. > NonVCL |
AW: Tray Programm ohne VCL
Hallo,
hier ist ein bißchen älterer Code, den ich vor längerer Zeit mal aus einer Newsgroup kopiert habe, funktioniert aber immer noch (bei mir Windoes 7 32bit). Eine Resourcendatei Icons.res für das Programm-Icon wird vorausgesetzt. Vielleicht kannst Du das Programm ja für deine Zwecke modifizieren.
Delphi-Quellcode:
program DeskPop;
uses Windows, Messages, ShellAPI, SysUtils; {$R *.RES} {$R ICONS.RES} const AppName = 'DeskTop Hide'; var x: Integer; NID: TNotifyIconData; WndClass: array [0 .. 50] of Char; procedure Panic(szMessage: PChar); begin if szMessage <> nil then MessageBox(0, szMessage, AppName, MB_OK); Halt(0); end; procedure HandleCommand(Wnd: HWND; Cmd: Word); begin case Cmd of Ord('A'): MessageBox(0, 'Freeware brian.slack@strath.ac.uk 1997', AppName, MB_OK); Ord('E'): PostMessage(Wnd, WM_CLOSE, 0, 0); end; end; function DummyWindowProc(Wnd: HWND; Msg, wParam: Word; lParam: LongInt): LongInt; stdcall; var TrayHandle: THandle; DC: HDC; PM: HMENU; Pt: TPoint; begin DummyWindowProc := 0; StrPCopy(@WndClass[0], 'Progman'); TrayHandle := FindWindow(@WndClass[0], nil); case Msg of WM_CREATE: // Program initialisation - just set up a tray icon begin NID.cbSize := SizeOf(NID); NID.Wnd := Wnd; NID.uID := 1; NID.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP; NID.uCallBackMessage := WM_USER; NID.hIcon := LoadIcon(hInstance, 'MAINICON'); lstrcpy(NID.szTip, 'Desktop is on'); Shell_NotifyIcon(NIM_ADD, @NID); end; WM_DESTROY: begin Shell_NotifyIcon(nim_Delete, @NID); PostQuitMessage(0); ShowWindow(TrayHandle, SW_RESTORE); end; WM_COMMAND: // Command notification begin HandleCommand(Wnd, LoWord(wParam)); Exit; end; WM_USER: // Had a tray notification - see what to do if (lParam = wm_LButtonDown) then begin if x = 0 then begin ShowWindow(TrayHandle, SW_HIDE); NID.hIcon := LoadIcon(hInstance, 'offICON'); lstrcpy(NID.szTip, 'Desktop is off'); Shell_NotifyIcon(NIM_MODIFY, @NID); x := 1 end else begin ShowWindow(TrayHandle, SW_RESTORE); NID.hIcon := LoadIcon(hInstance, 'ONICON'); lstrcpy(NID.szTip, 'Desktop is on'); Shell_NotifyIcon(NIM_MODIFY, @NID); x := 0; end; end else if (lParam = wm_RButtonDown) then begin GetCursorPos(Pt); PM := CreatePopupMenu; AppendMenu(PM, 0, Ord('A'), 'About DeskTop Hide...'); AppendMenu(PM, mf_Separator, 0, nil); AppendMenu(PM, 0, Ord('E'), 'Exit DeskTop Hide'); SetForegroundWindow(Wnd); DC := GetDC(0); if TrackPopupMenu(PM, tpm_BottomAlign or tpm_RightAlign, Pt.x, GetDeviceCaps(DC, HORZRES) { pt.y } , 0, Wnd, nil) then SetForegroundWindow(Wnd); DestroyMenu(PM) end; end; DummyWindowProc := DefWindowProc(Wnd, Msg, wParam, lParam); end; procedure WinMain; var Wnd: HWND; Msg: TMsg; Cls: TWndClass; begin { Previous instance running ? If so, exit } if FindWindow(AppName, nil) <> 0 then Panic(AppName + ' is already running.'); { Register the window class } FillChar(Cls, SizeOf(Cls), 0); Cls.lpfnWndProc := @DummyWindowProc; Cls.hInstance := hInstance; Cls.lpszClassName := AppName; RegisterClass(Cls); { Now create the dummy window } Wnd := CreateWindow(AppName, AppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, HInstance, nil); x := 0; if Wnd <> 0 then begin ShowWindow(Wnd, SW_HIDE); while GetMessage(Msg, 0, 0, 0) do begin TranslateMessage(Msg); DispatchMessage(Msg); end; end; end; begin WinMain; end. |
AW: Tray Programm ohne VCL
Zitat:
Zitat:
Wollte es halt mal so probieren. Habe mir jetzt mal ne "Form ohne VCL" Demo besorgt und studiere sie mal :) |
AW: Tray Programm ohne VCL
Zitat:
|
AW: Tray Programm ohne VCL
Zitat:
naja wenn ich per WinAPI ein kleines Fenster erzeuge und den dann "visible := false" mache dann sollte das ja gehen. Sorry aber das ist mein erster NonVCL Versuch. |
AW: Tray Programm ohne VCL
Zitat:
|
AW: Tray Programm ohne VCL
Zitat:
|
AW: Tray Programm ohne VCL
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:05 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 by Thomas Breitkreuz