Jump to content

Delphi65

Members
  • Content Count

    10
  • Joined

  • Last visited

Posts posted by Delphi65


  1. 24 minutes ago, Lars Fosdal said:

    My own scheduler loads a config, and has events added dynamically based on the config settings. Config-wise, events can be oneshot or repeating.  My settings allows for fixed intervals, or specific timeslots during a day.

    The settings are parsed and a scheduler, which basically is a list of times and what is supposed to happened at that time, is rebuilt on startup and at midnight for today's events.  Events that are in past time are removed. It also add specific built in events such as weekly events or overnight events.


    Basically, your timer would then look up "Now" and compare it to the sorted list of events in the scheduler.  If "Now" > "Event.Time", trigger the event and remove the entry from the scheduler.

    In my case, it creates threads specific to the event. How frequently you need to check "Now" and scan the events, depends on how urgent it is that the event happens on time.

    Thanks Lars!

    Yes, correct, my timer will look up for "Now" and compare.

    The events will happen only once a day that could be for example today Wednesday at 20:15. I could however make my timer to check once every 10 minutes. My event time slots are also specific, they will be different for each day.


  2. 8 minutes ago, Lars Fosdal said:

    Which version of Delphi?

    I am being very terse, since doing is learning.
     

    Thank you!

    I am using Delphi Berlin.

    Yes, my memo gives me the day, and my checkbox tell me if the event is set or not. I have my time edit also which gives me the current time.

    I am planning to use a timer to do the checks. If the event is enabled, it will check the day and time and if the enabled day and time matches with the current day and time, it will run the event. I have all the required data, i just need to figure out how to run the event because i need to make sure the current day and time matches with the day and time behind that checkbox which is enabled.

     

    Or if you have any suggestions of how to do this schedule daily at selected time, please shoot me.


  3. Dear all,

    I am trying to run a schedule as following where i have:

    Checkbox (if the schedule is enabled for the day or not, every day has it's own checkbox such as: checkboxMonday, checkboxTuesday etc.)

    Time field (edit showing now)

    Day field (memo showing the today)

    Time field (showing at what time to run the schedule)

     

    Now,

    any ideas of how to combine all this inside one procedure?

    What i am chasing is something like this:

    Procedure Tform1.CollectData;
    begin
    if checkboxMonday is checked and memofield is showing "Monday" and TimeNow is equal to TimeMonday then
    begin
    CollectData;
    end
    else
    ShowMessage('Event is not scheduled');
    end;

    Is this possible?

    If not, what do i need?

     

    Thanks for all the answers.

     

     

     


  4. Thank you to all!

    I have done the following and both Turn On/TurnOff works.

    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
    type
      TfrmPowerControl = class(TForm)
        btnOFF: TButton;
        btnExit: TButton;
        Label1: TLabel;
        btnON: TButton;
        timerTurnOffDisplay: TTimer;
        procedure btnOFFClick(Sender: TObject);
        procedure btnONClick(Sender: TObject);
        procedure btnExitClick(Sender: TObject);
        procedure timerTurnOffDisplayTimer(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      frmPowerControl: TfrmPowerControl;
    
    implementation
    
    {$R *.dfm}
    
      const
      MONITOR_ON      = -1;
      MONITOR_OFF     =  2;
      MONITOR_STANDBY =  1;
    
    procedure TfrmPowerControl.btnOFFClick(Sender: TObject);
    begin
      PostMessage(HWND_BROADCAST , WM_SYSCOMMAND, SC_MONITORPOWER, 2);
    end;
    
    procedure TfrmPowerControl.btnExitClick(Sender: TObject);
    begin
      Close;
      Application.Terminate;
    end;
    
    procedure TfrmPowerControl.btnONClick(Sender: TObject);
    begin
      PostMessage(HWND_BROADCAST , WM_SYSCOMMAND, SC_MONITORPOWER, -1);
    end;
    
    procedure TfrmPowerControl.timerTurnOffDisplayTimer(Sender: TObject);
    begin
      //PostMessage(HWND_BROADCAST , WM_SYSCOMMAND, SC_MONITORPOWER, 2);
    end;
    
    end.

     


  5. 1 hour ago, DelphiUdIT said:

    To turn monitor on simply simulate a keypressed:

     

    
      //Simulate the pression of SHIFT key ...
      keybd_event(VK_SHIFT, 0, 0, 0);
      keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);

    Bye

    My problem is that i cannot turn the display off.

    Yes, you are correct, it can be turned on by using a key press.


  6. 1 hour ago, PeterBelow said:

    Have you tried running the code under an admin account? This may be a rights issue, since you are changing a setting that effects all users.

    I have tested with two different PC where both were pretty same and both with administrator account.


  7. 1 hour ago, programmerdelphi2k said:

    SendMessage(handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

    It doesn't work for me. Not with timer nor a button. I also have Windows 10  22H2 64bit


  8. Hi guys,

    I have been using the following for earlier version of windows.

    Quote
    
    const
      MONITOR_ON      = -1;
      MONITOR_OFF     =  2;
      MONITOR_STANDBY =  1;

    To turn off the monitor:

    
      SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);

    To turn on the monitor:

    
      SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON);

    But this unfortunately no longer works for Windows 10, any idea of how to achieve the same goal on Windows PC?

    Many thanks in advance!

×