home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / Chip_2004-11_cd1.bin / tema / fax / download / ventafax5 / vfvh5519i.exe / RCDATA / CABINET / informer.dpr < prev    next >
Text File  |  2003-09-02  |  15KB  |  441 lines

  1. library informer;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   CommDlg,
  7.   Sysutils;
  8.  
  9. type
  10.     TColor = -$7FFFFFFF-1..$7FFFFFFF;
  11.  
  12. const
  13.      BoolValues: array[Boolean] of string = ('0', '1');
  14.      MaskIsRecFile = $20;
  15.  
  16.      WS_EX_LAYERED = $00080000;
  17.      LWA_COLORKEY  = $00000001;
  18.  
  19.      WindowHeight  = 110;
  20.      WindowWidth   = 420;
  21.  
  22.      clBlack       = TColor($000000);
  23.      clMaroon      = TColor($000080);
  24.      clGreen       = TColor($008000);
  25.      clOlive       = TColor($008080);
  26.      clNavy        = TColor($800000);
  27.      clPurple      = TColor($800080);
  28.      clTeal        = TColor($808000);
  29.      clGray        = TColor($808080);
  30.      clSilver      = TColor($C0C0C0);
  31.      clRed         = TColor($0000FF);
  32.      clLime        = TColor($00FF00);
  33.      clYellow      = TColor($00FFFF);
  34.      clBlue        = TColor($FF0000);
  35.      clFuchsia     = TColor($FF00FF);
  36.      clAqua        = TColor($FFFF00);
  37.      clLtGray      = TColor($C0C0C0);
  38.      clDkGray      = TColor($808080);
  39.      clWhite       = TColor($FFFFFF);
  40.      clNone        = TColor($1FFFFFFF);
  41.      clDefault     = TColor($20000000);
  42.  
  43.      cNameLength   = 16;
  44.      cDescriptionLength = 1024;
  45. type
  46.  
  47.   pTPluginName = ^TPluginName;
  48.   TPluginName  = array[0..cNameLength-1] of Char;
  49.  
  50.   pTPluginDescription = ^TPluginDescription;
  51.   TPluginDescription  = array[0..cDescriptionLength-1] of Char;
  52.  
  53.   TSetLayeredWindowAttributes = function(Handle: THandle;
  54.                                          crKey: DWord;
  55.                                          bAlpha: Byte;
  56.                                          dwFlags: DWord): HRESULT; stdcall;
  57.  
  58.   PInfStatus = ^TInfStatus;
  59.   TInfStatus  = packed record
  60.                    bAlreadyRun      : Boolean;
  61.                    iNumFaxMessage   : DWord;
  62.                    iNumVoiceMessage : DWord;
  63.                 end;
  64.  
  65.   TDaTi = packed record
  66.     Year   : Word;
  67.     Month  : Word;
  68.     Day    : Word;
  69.     Hour   : Word;
  70.     Min    : Word;
  71.     Sec    : Word;
  72.   end;
  73.  
  74.   PTRec32C = ^TRec32C;
  75.   TRec32C = packed Record
  76.     phone       : array[0..63] of Char;
  77.     firm        : array[0..63] of Char;
  78.     ToAbonent   : array[0..73] of Char;
  79.     filename    : array[0..255] of Char;
  80.     DocName     : array[0..63] of Char;
  81.     result      : Word;
  82.     speed       : Word;
  83.     quality     : Word;
  84.     Date        : TDaTi;
  85.     Min, Sec    : Word;
  86.     Pages       : Word;
  87.     LastPage    : Word;
  88.     NBlock      : LongInt;
  89.     NBadBlock   : LongInt;
  90.     Attr        : Word;
  91.     ExtData     : array[0..63] of Char;
  92.     CSI         : array[0..21] of Char;
  93.     NCF         : array[0..63] of Char;
  94.     RecId       : LongInt;
  95.     AbId        : LongInt;
  96.     CompName    : array[0..31] of Char;
  97.     PhoneCardID : DWORD;
  98.     LocationID  : DWORD;
  99.     ExtOption   : DWORD;
  100.     VLine       : WORD;
  101.     Reserve     : array[0..49] of char;
  102.   end;
  103.  
  104. var
  105.   ShowCount        : Integer;
  106.   Inst             : Integer;
  107.   hLib             : Integer;
  108.   Handle           : Integer;
  109.   hMessageFont     : Integer;
  110.   hCountFont       : Integer;
  111.   hOkFont          : Integer;
  112.   hMapObj          : Integer;
  113.   hlMessage        : Integer;
  114.   hlCount          : Integer;
  115.   hlOk             : Integer;
  116.   TextColor        : TColor;
  117. //  BackgroundColor  : TColor;
  118.   bMMFWasCreated   : Boolean;
  119.   bExit            : Boolean;
  120.   bSoundOn         : Boolean;
  121.   wFlag            : Cardinal;
  122.   WinClass         : TWndClassA;
  123.   Msg              : TMsg;
  124.   pInfSt           : PInfStatus;
  125.   IniFileName      : array[0..255] of Char;
  126.  
  127.   SetLayeredWindowAttributes : TSetLayeredWindowAttributes;
  128.  
  129. function ColorToRGB(Color: TColor): Longint;
  130. begin
  131.   if Color < 0
  132.      then Result := GetSysColor(Color and $000000FF)
  133.      else Result := Color;
  134. end;
  135.  
  136. function WindowProc(hWnd, uMsg,    wParam,    lParam: Integer): Integer; stdcall;
  137. begin
  138.      Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
  139.  
  140.      if uMsg = WM_CTLCOLORSTATIC then
  141.      begin
  142.           if (lParam =hlMessage) or (lParam =hlCount) then
  143.           begin
  144.                SetTextColor(WParam, ColorToRGB(TextColor));
  145.                SetBkColor(WParam, ColorToRGB(clNone));
  146.           end
  147.           else if lParam =hlOk then
  148.           begin
  149.                SetTextColor(WParam, ColorToRGB(clNone));
  150.                SetBkColor(WParam, ColorToRGB(TextColor));
  151.           end;
  152.      end;
  153.  
  154.      if uMsg = WM_TIMER then
  155.      begin
  156.           if pInfSt<> nil then SetWindowText(hlCount, PChar('Fax: '
  157.                                       +IntToStr(pInfSt.iNumFaxMessage)
  158.                                       +'  Voice: '
  159.                                       +IntToStr(pInfSt.iNumVoiceMessage)));
  160.           if ShowCount = 2
  161.           then begin
  162.                     SetWindowText(hlMessage, '                                        ');
  163.                     ShowCount := 0;
  164.           end
  165.           else begin
  166.                     SetWindowText(hlMessage, '       Message received');
  167.                     if bSoundOn and (ShowCount=0) then MessageBeep(MB_ICONASTERISK);
  168.                     Inc(ShowCount);
  169.           end;
  170.      end;
  171.  
  172.      if (uMsg = WM_LBUTTONDOWN) or (uMsg = WM_DESTROY) then bExit := true;
  173. end;
  174.  
  175. function AfterSession(R : TRec32C): LongInt; stdcall; export;
  176. var
  177.    Buffer            : array[0..2047] of Char;
  178. begin
  179.      Result    := 0;
  180.  
  181.      if (StrPas(R.filename)='') or ((R.Attr and MaskIsRecFile)<>0) then Exit;
  182.  
  183.      hMapObj := OpenFileMapping(FILE_MAP_ALL_ACCESS,true,'VFInformer');
  184.      bMMFWasCreated := hMapObj=0;
  185.      if bMMFWasCreated then hMapObj := CreateFileMapping($ffffffff,nil,PAGE_READWRITE,0,SizeOf(TInfStatus),'VFInformer');
  186.      pInfSt := MapViewOfFile(hMapObj,FILE_MAP_ALL_ACCESS,0,0,0);
  187.  
  188.      if pInfSt.bAlreadyRun then
  189.      begin
  190.           if pInfSt <> nil then
  191.           begin
  192.                if Pos('wav',LowerCase(ExtractFileExt(StrPas(R.filename))))<>0
  193.                   then Inc(pInfSt.iNumVoiceMessage)
  194.                   else Inc(pInfSt.iNumFaxMessage);
  195.           end;
  196.           CloseHandle(hMapObj);
  197.           Exit;
  198.      end;
  199.  
  200.      GetPrivateProfileString('setting','color',PChar(IntToStr(clRed)),Buffer, SizeOf(Buffer),IniFileName);
  201.      TextColor := StrToIntDef(StrPas(Buffer),clRed);
  202.      WritePrivateProfileString('setting','color',PChar(IntToStr(TextColor)),IniFileName);
  203.      GetPrivateProfileString('setting','sound','0',Buffer, SizeOf(Buffer),IniFileName);
  204.      bSoundOn := StrToInt(StrPas(Buffer)) = 1;
  205.      WritePrivateProfileString('setting','sound',PChar(BoolValues[bSoundOn]),IniFileName);
  206.  
  207.      FillChar(pInfSt^,SizeOf(TInfStatus),#0);
  208.      if pInfSt <> nil then
  209.      begin
  210.           if Pos('wav',LowerCase(ExtractFileExt(StrPas(R.filename))))<>0
  211.              then Inc(pInfSt.iNumVoiceMessage)
  212.              else Inc(pInfSt.iNumFaxMessage);
  213.      end;
  214.  
  215.      pInfSt.bAlreadyRun := true;
  216.      bExit              := false;
  217.      Inst               := hInstance;
  218.      ShowCount          := 0;
  219.      hLib               := LoadLibrary('user32.dll');
  220.  
  221.      if hLib>=32 then @SetLayeredWindowAttributes := GetProcAddress(HLib,'SetLayeredWindowAttributes');
  222.      if Assigned(SetLayeredWindowAttributes)
  223.            then wFlag := WS_POPUP
  224.            else wFlag := WS_POPUP or WS_VISIBLE;
  225.  
  226.      with WinClass do
  227.      begin
  228.           style          := 2;
  229.           lpfnWndProc    := @WindowProc;
  230.           hInstance      := Inst;
  231.           hbrBackground  := CreateSolidBrush(clNone);
  232.           lpszClassname  := 'INFORMER_WINDOW';
  233.           hCursor        := LoadCursor(0, IDC_HAND);
  234.      end;
  235.      RegisterClass(WinClass);
  236.  
  237.      Handle := CreateWindowEx(WS_EX_TOOLWINDOW, 'INFORMER_WINDOW', '',
  238.                               wFlag,
  239.                               (GetSystemMetrics(SM_CXSCREEN)-WindowWidth) div 2,
  240.                               (GetSystemMetrics(SM_CYSCREEN)-WindowHeight) div 2,
  241.                               WindowWidth,
  242.                               WindowHeight-15,
  243.                               0,
  244.                               0,
  245.                               Inst,
  246.                               nil);
  247.  
  248.      SetWindowPos(Handle,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE or SWP_NOSIZE);
  249.  
  250.      if Assigned(SetLayeredWindowAttributes) then
  251.      begin
  252.           SetWindowLong(Handle,GWL_EXSTYLE,GetWindowLong(Handle,GWL_EXSTYLE) or WS_EX_LAYERED);
  253.           SetLayeredWindowAttributes(Handle,clNone,0,LWA_COLORKEY);
  254.      end;
  255.  
  256.      SetWindowLong(Handle,GWL_STYLE,GetWindowLong(Handle,GWL_STYLE) or WS_VISIBLE);
  257.  
  258.      hlMessage := CreateWindow('Static',
  259.                                '',
  260.                                WS_VISIBLE or WS_CHILD or SS_CENTER or SS_SIMPLE,
  261.                                0,
  262.                                0,
  263.                                WindowWidth,
  264.                                WindowHeight div 2,
  265.                                Handle,
  266.                                0,
  267.                                Inst,
  268.                                nil);
  269.  
  270.      hlOk := CreateWindow('Static',
  271.                           '',
  272.                           WS_VISIBLE or WS_CHILD or SS_CENTER or SS_SIMPLE,
  273.                           WindowWidth-94,
  274.                           WindowHeight div 2,
  275.                           WindowWidth,
  276.                           WindowHeight div 2,
  277.                           Handle,
  278.                           0,
  279.                           Inst,
  280.                           nil);
  281.  
  282.      hlCount := CreateWindow('Static',
  283.                              '',
  284.                              WS_VISIBLE or WS_CHILD or SS_CENTER or SS_SIMPLE,
  285.                              WindowWidth div 2 - 140,
  286.                              (WindowHeight div 2) + 10,
  287.                              WindowWidth,
  288.                              WindowHeight div 2,
  289.                              Handle,
  290.                              0,
  291.                              Inst,
  292.                              nil);
  293.  
  294.      hMessageFont := CreateFont(60,
  295.                                 17,
  296.                                 0,
  297.                                 0,
  298.                                 800,
  299.                                 0,
  300.                                 0,
  301.                                 0,
  302.                                 DEFAULT_CHARSET,
  303.                                 OUT_DEFAULT_PRECIS,
  304.                                 CLIP_DEFAULT_PRECIS,
  305.                                 DEFAULT_QUALITY,
  306.                                 DEFAULT_PITCH or FF_DONTCARE,
  307.                                 'Arial Black');
  308.  
  309.      hCountFont := CreateFont(28,
  310.                               12,
  311.                               0,
  312.                               0,
  313.                               800,
  314.                               0,
  315.                               0,
  316.                               0,
  317.                               DEFAULT_CHARSET,
  318.                               OUT_DEFAULT_PRECIS,
  319.                               CLIP_DEFAULT_PRECIS,
  320.                               DEFAULT_QUALITY,
  321.                               DEFAULT_PITCH or FF_DONTCARE,
  322.                               'Arial Black');
  323.  
  324.      hOkFont := CreateFont(40,
  325.                            17,
  326.                            0,
  327.                            0,
  328.                            800,
  329.                            0,
  330.                            0,
  331.                            0,
  332.                            DEFAULT_CHARSET,
  333.                            OUT_DEFAULT_PRECIS,
  334.                            CLIP_DEFAULT_PRECIS,
  335.                            DEFAULT_QUALITY,
  336.                            DEFAULT_PITCH or FF_DONTCARE,
  337.                            'Arial Black');
  338.  
  339.      if hMessageFont <> 0 then SendMessage(hlMessage, WM_SETFONT, hMessageFont, 0);
  340.      if hCountFont <> 0 then SendMessage(hlCount, WM_SETFONT, hCountFont, 0);
  341.      if hOkFont <> 0 then SendMessage(hlOk, WM_SETFONT, hOkFont, 0);
  342.  
  343.      SetWindowText(hlMessage, '       Message received');
  344.      SetWindowText(hlOk, '  OK  ');
  345.      if pInfSt<> nil then SetWindowText(hlCount, PChar('Fax: '
  346.                                  +IntToStr(pInfSt.iNumFaxMessage)
  347.                                  +'  Voice: '
  348.                                  +IntToStr(pInfSt.iNumVoiceMessage)));
  349.  
  350.      UpdateWindow(Handle);
  351.  
  352.      SetTimer(Handle,0,400,nil);
  353.  
  354.      while GetMessage(Msg, Handle, 0, 0) and (not bExit) do
  355.      begin
  356.           TranslateMessage(msg);
  357.           DispatchMessage(msg);
  358.      end;
  359.  
  360.      Killtimer(Handle,0);
  361.  
  362.      DestroyWindow(hlCount);
  363.      DestroyWindow(hlOk);
  364.      DestroyWindow(hlMessage);
  365.      DestroyWindow(Handle);
  366.      DeleteObject(hMessageFont);
  367.      DeleteObject(hCountFont);
  368.      DeleteObject(hOkFont);
  369.      pInfSt.bAlreadyRun := false;
  370.      UnmapViewOfFile(pInfSt);
  371.      CloseHandle(hMapObj);
  372.      FreeLibrary(HLib);
  373. end;
  374.  
  375. procedure PluginName(const pPluginName: pTPluginName; const Size: DWord); stdcall; export;
  376. const
  377.      csPluginName = 'Informer v1.2';
  378. begin
  379.      StrPLCopy(Pointer(pPluginName),csPluginName,Size);
  380. end;
  381.  
  382. procedure PluginDescription(const pPluginDescription: pTPluginDescription; const Size: DWord); stdcall; export;
  383. const
  384.      csPluginDescription = 'VentaFax Informer Plugin v1.2'#13#10+
  385.                            '(c) 2003 Venta Association'#13#10+
  386.                            'This sample plug-in displays number of received voice and fax messages.'#13#10+
  387.                            'http://www.ventafax.com'#13#10+
  388.                            'Build date:  September 1, 2003';
  389. begin
  390.      StrPLCopy(Pointer(pPluginDescription),csPluginDescription,Size);
  391. end;
  392.  
  393. procedure Configure(hWnd: THandle); stdcall; export;
  394. const
  395.      MaxCustomColors = 16;
  396.  
  397. type
  398.   TCustomColors = array[0..MaxCustomColors - 1] of Longint;
  399.  
  400. var
  401.    tagChooseColor    : TChooseColor;
  402.    aCustomColors     : TCustomColors;
  403.    i                 : LongInt;
  404.    Buffer            : array[0..2047] of Char;
  405. begin
  406.      GetPrivateProfileString('setting','color',PChar(IntToStr(clRed)),Buffer, SizeOf(Buffer),IniFileName);
  407.      TextColor := StrToIntDef(StrPas(Buffer),clRed);
  408.      WritePrivateProfileString('setting','color',PChar(IntToStr(TextColor)),IniFileName);
  409.  
  410.      FillChar(tagChooseColor,SizeOf(TChooseColor),#0);
  411.      for i := 0 to MaxCustomColors - 1 do aCustomColors[i] := -1;
  412.      tagChooseColor.lStructSize := SizeOf(TChooseColor);
  413.      tagChooseColor.hWndOwner := hWnd;
  414.      tagChooseColor.Flags := CC_RGBINIT;
  415.      tagChooseColor.rgbResult := ColorToRGB(TextColor);
  416.      tagChooseColor.lpCustColors := @aCustomColors;
  417.  
  418.      if ChooseColor(tagChooseColor) then
  419.      begin
  420.           TextColor := TColor(tagChooseColor.rgbResult);
  421.           WritePrivateProfileString('setting','color',PChar(IntToStr(TextColor)),IniFileName);
  422.      end;
  423.  
  424.      if Handle<>0 then InvalidateRect(Handle,nil,true);
  425.  
  426.      bSoundOn := MessageBox(hWnd,'Sound On?','Sound setup',MB_YESNO or MB_ICONQUESTION) = IDYES;
  427.      WritePrivateProfileString('setting','sound',PChar(BoolValues[bSoundOn]),IniFileName);
  428. end;
  429.  
  430. exports
  431.        Configure,
  432.        PluginName,
  433.        PluginDescription,
  434.        AfterSession;
  435.  
  436. begin
  437.      Handle := 0;
  438.      GetModuleFileName(hInstance,@IniFileName,SizeOf(IniFileName)-1);
  439.      StrPCopy(IniFileName,ChangeFileExt(StrPas(IniFileName),'.ini'));
  440. end.
  441.