I am trying to send input to VMWare Player when I switch to it. This is so that do not have press Ctrl-g and make the VMWare grab my input. The following is the script I came up with, but it does not do anything. What is it that missed?
#IfWinActive ahk_class VMPlayerFrame
{
SendInput, {Ctrl down}g{Ctrl up}
} return
You can use #IfWinActive to change hotkeys or hotstrings, but not to create scripts.
You need to detect the window change, and act on that.
#SingleInstance
#installKeybdHook
#Persistent
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,Hwnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return
ShellMessage( wParam )
{
If (wParam = 4 or wParam = 32772) ; Without VMware Player running: wParam = 4, with VMware Player running: wParam = 32772
{
IfWinActive ahk_class VMPlayerFrame
{
SendInput, {Ctrl down}g{Ctrl up}
}
}
}
Return
; Hotkey {Win}+g launches Chrome
#g::Run "C:\Users\%A_Username%\AppData\Local\Google\Chrome\Application\chrome.exe"
; Hotkeys {Ctrl}+Nr gives you fractures
^2::
Send, ½
TrayTip, For 2 Squared,press Ctrl + Shift 2,1,1
Return
^3::
Send, ¾
TrayTip, For 3 Cubed,press Ctrl + Shift 3,1,1
Return
^4::Send, ¼
; HotKeys {Shift}+{Ctrl}+Nr gives you the power
+^0::Send, °
+^1::Send, ¹
+^2::Send, ² ; Shift Control 2#
+^3::Send, ³ ; Shift Control 3#
; Hotstrings mvge, mvgd or mvgf will give you my salutations in various languages.
:*:mvge::Regards,{Enter}{Enter}Robert Ilbrink
:*:mvgd::Mit freundlichen Grüßen,{Enter}{Enter}Robert Ilbrink
:*:mvgf::Salutions,{Enter}{Enter}Robert Ilbrink
Related
I've been trying to create a script that displays message boxes conditioned on the output from another customized message box with more than 3 options.
The custom functions are taken form this thread http://www.autohotkey.com/board/topic/29570-function-custom-msgbox-custom-buttons/page-2
I've tried both the CMsgbox and the MsgBoxV2 functions, running into the same problem. The Message "IT WORKED!" testing with if(condition) will always appear regardless of whether pressing any of the Sym|&Go|&C options, and the message "worked" will never appear regardless of actually pressing C, In other words no specificity or sensitivity regarding variable testing.
!o::
var := MsgBoxV2("Question11","Hi, what's up??","Sym|Go|C","24")
Msgbox 4,, You Pressed %var%
if (%var% = C)
{
Msgbox 4,, IT WORKED!
}
IfEqual, %var%,C
{
Msgbox 4,, worked
}
return
!e::
var := CMsgbox( "s", "d", "*&Sym|&Go|&C","",1 )
Msgbox 4,, You Pressed %var%
if (%var% = C)
{
Msgbox 4,, IT WORKED!
}
IfEqual, %var%,C
{
Msgbox 4,, worked
}
return
I don't know if this is because I've misunderstood the if/Else testing in ahk, or if the output from these custom functions cannot be tested, or both.
One solution would be to figure out what type of variable %var% is, but I've not been able to find a way to figure that out either.
Thanks for reading and hope you guys can help.
here are the custom message functions for testing.
MsgBoxV2(Title="",Text="",Buttons="",IconPath="",Timeout="",Font="",Schriftart="Arial",Colors="||",WindowStyles="",GuiNr = "")
{
Static Stat2,Stat1
Col1:="0xFFFFFF" ,Col2:="0x000000",Col3:="0x000000", Color1:="", Color2:="", Color3:=""
Loop, Parse, Colors,`|
Color%A_Index% := (A_Loopfield = "") ? Col%A_Index% : A_Loopfield
Loop 3
Color%A_Index% := (Color%A_Index% = "") ? Col%A_Index% : Color%A_Index%
if instr(WindowStyles,"+altsubmit")
{
AltSub := "1"
Stringreplace,WindowStyles,WindowStyles,`+altsubmit
}
Gui, Color, %Color1%,%Color1%
Gui, Font, s9
Gui, Font, %Font%, %Schriftart%
X := 20 ,Y := 20
ifexist, %IconPath%
{
Gui, Add, Picture, x20 y20 w32 h32, %IconPath%
X := 70 ,Y := 30
} else
if IconPath is integer
{
Gui, Add, Picture, x20 y20 icon%IconPath% w32 h32, %A_WinDir%\system32\shell32.dll
X := 70 ,Y := 30
}
Gui, Add, Text, x%X% y%Y% c%Color2% vStat2, %Text%
GuicontrolGet, Stat2, Pos
X2 = 10
Y2 := (Stat2Y + Stat2H < 52) ? 82 : Stat2Y + Stat2H + 30
HMax = 0
Gui, Add, Text, vStat1 +border -background
Loop, Parse, Buttons,|,`|
{
Gui, Add, Button, x%X2% w100 Y%Y2% gExButton , %A_Loopfield%
ButT%A_Index% := A_Loopfield
Guicontrolget, Button%A_Index%,Pos
if (HMax < Button%A_Index%H)
HMax := Button%A_Index%H
ABut := A_Index
X2 += 110
}
Loop %ABut%
Guicontrol, Move, Button%A_Index%,h%HMax%
Gui, %WindowStyles%
Gui, Show, Autosize Center,%Title%
Guicontrol, Move, Stat1, % "X-1 Y" Y2 - 10 " W" 1400 " h" 41 + HMax
Guicontrol, -Background +hidden, Stat1
Guicontrol, show, Stat1
Gui, +LastFound
WinGet, G_id
if Timeout !=
if Timeout is integer
settimer, Timeout, %Timeout%
Winwait, ahk_id %G_id%
retval = 0
while winexist("ahk_id " G_id)
sleep 100
if !AltSub
return ButT%retval%
else
return retval
Timeout:
if Timeout =
return
GuiClose:
Gui, destroy
return
ExButton:
MouseGetPos,,,, Control
Stringreplace,retval,Control,Button
Gui, destroy
return
}
;-------------------------------------------------------------------------------
; Custom Msgbox
; Filename: cmsgbox.ahk
; Author : Danny Ben Shitrit (aka Icarus)
;-------------------------------------------------------------------------------
; Copy this script or include it in your script (without the tester on top).
;
; Usage:
; Answer := CMsgBox( title, text, buttons, icon="", owner=0 )
; Where:
; title = The title of the message box.
; text = The text to display.
; buttons = Pipe-separated list of buttons. Putting an asterisk in front of
; a button will make it the default.
; icon = If blank, we will use an info icon.
; If a number, we will take this icon from Shell32.dll
; If a letter ("I", "E" or "Q") we will use some predefined icons
; from Shell32.dll (Info, Error or Question).
; owner = If 0, this will be a standalone dialog. If you want this dialog
; to be owned by another GUI, place its number here.
;
;-------------------------------------------------------------------------------
CMsgBox( title, text, buttons, icon="", owner=0 ) {
Global _CMsg_Result
GuiID := 9 ; If you change, also change the subroutines below
StringSplit Button, buttons, |
If( owner <> 0 ) {
Gui %owner%:+Disabled
Gui %GuiID%:+Owner%owner%
}
Gui %GuiID%:+Toolwindow +AlwaysOnTop
MyIcon := ( icon = "I" ) or ( icon = "" ) ? 222 : icon = "Q" ? 24 : icon = "E" ? 110 : icon
Gui %GuiID%:Add, Picture, Icon%MyIcon% , Shell32.dll
Gui %GuiID%:Add, Text, x+12 yp w180 r8 section , %text%
Loop %Button0%
Gui %GuiID%:Add, Button, % ( A_Index=1 ? "x+12 ys " : "xp y+3 " ) . ( InStr( Button%A_Index%, "*" ) ? "Default " : " " ) . "w100 gCMsgButton", % RegExReplace( Button%A_Index%, "\*" )
Gui %GuiID%:Show,,%title%
Loop
If( _CMsg_Result )
Break
If( owner <> 0 )
Gui %owner%:-Disabled
Gui %GuiID%:Destroy
Result := _CMsg_Result
_CMsg_Result := ""
Return Result
}
9GuiEscape:
9GuiClose:
_CMsg_Result := "Close"
Return
CMsgButton:
StringReplace _CMsg_Result, A_GuiControl, &,, All
Return
The answer lies in syntax of your code. I highly suggest that you read the Tutorial in the Docs fully! It's really well written.
What immediately popped out to me is that your Variables in your If Expressions are surrounded by percents, which is wrong.
Here is a link to the section in the Tutorial that you need to read in order to fix your code.
Try this:
!o::
var := MsgBoxV2("Question11","Hi, what's up??","Sym|Go|C","24")
Msgbox 4,, You Pressed %var%
if (var = "C")
{
Msgbox 4,, IT WORKED!
}
!e::
var := CMsgbox( "s", "d", "*&Sym|&Go|&C","",1 )
Msgbox 4,, You Pressed %var%
If (var = "C")
{
Msgbox 4,, worked
}
return
The IfEqual command is pretty much deprecated and while it's still included in the latest releases, it's basically bad form to use since the If expression much easier to read. Also plain text excluding numbers in an expression should be surrounded by quotes. Hope this helps.
I'm making a Rebol 3 extension that has GUI events.
For now, I manage this using synchronous callbacks so each time an event happens like a mouse move, the C extension calls the Rebol callback function.
But I'd like to manage this using REBEVT and RL->event.
Here is a code sample:
case SDL_MOUSEMOTION:
Add_Event_XY(
RootGob, 2, (event.motion.x + (event.motion.y << 16)), EVT_MOVE
);
/*
cbi.obj = CBI_SDL_MOUSEMOTION.obj;
cbi.word = CBI_SDL_MOUSEMOTION.word;
RXI_COUNT(args) = 1;
RXI_TYPE(args, 1) = RXT_PAIR;
args[1].pair.x = event.motion.x;
args[1].pair.y = event.motion.y;
n = RL_CALLBACK(&cbi);
if(n == 0) {RL_PRINT("%s\n", "callback error");}
*/
break;
But then when I do a wait in Rebol, I get:
>> wait 1
** Script error: wake-up does not allow none! for its port argument
** Where: loop -apply- wait
** Near: loop 8 [
unless event: take sport/state [break]
port...
How to make the port not null?
After some searches in R3 code, I found that I had to initialize as below:
system/view/event-port: open event://
Now it works! (with R3 mainline)
I am trying to get the display name of the running service using c++. I was trying to use the GetServiceDisplayName function but it does not seem to be working, not sure why.
TTServiceBegin( const char *svcName, PFNSERVICE pfnService, bool *svc, PFNTERMINATE pfnTerm,
int flags, int argc, char *argv[], DWORD dynamiteThreadWaitTime )
{
SC_HANDLE serviceStatusHandle;
DWORD dwSizeNeeded = 0 ;
TCHAR* szKeyName = NULL ;
serviceStatusHandle=OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE ,SC_MANAGER_ALL_ACCESS);
GetServiceDisplayName(serviceStatusHandle,svcName, NULL, &dwSizeNeeded);
if(dwSizeNeeded)
{
szKeyName = new char[dwSizeNeeded+1];
ZeroMemory(szKeyName,dwSizeNeeded+1);
if(GetServiceDisplayName(serviceStatusHandle ,svcName,szKeyName,&dwSizeNeeded)!=0)
{
MessageBox(0,szKeyName,"Got the key name",0);
}
}
When i run this code, i can never see the value of szKeyName in my debugger and it goes into the if block for the message box but never displays the message box. Not sure why?
Anyway to get this to work to get the display name of the service or any other/easier way to accomplish that task?
You need to use the WTSSendMessage instead of the MessageBox to interact with the active session.
WTS_SESSION_INFO* pSessionInfo = NULL;
DWORD dwSessionsCount = 0;
if(WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &dwSessionsCount))
{
for(int i=0; i<(int)dwSessionsCount; i++)
{
WTS_SESSION_INFO &si = pSessionInfo[i];
if(si.State == WTSActive)
{
DWORD dwIdCurrentSession = si.SessionId;
std::string strTitle = "Hello";
std::string strMessage = "This is a message from the service";
DWORD dwMsgBoxRetValue = 0;
if(WTSSendMessage(
WTS_CURRENT_SERVER_HANDLE,
dwIdCurrentSession,
(char*)strTitle.c_str(),
strTitle.size(),
(char*)strMessage.c_str(),
strMessage.size(),
MB_RETRYCANCEL | MB_ICONINFORMATION | MB_TOPMOST,
60000,
&dwMsgBoxRetValue,
TRUE))
{
switch(dwMsgBoxRetValue)
{
case IDTIMEOUT:
// Deal with TimeOut...
break;
case IDCANCEL:
// Deal With Cancel....
break;
}
}
else
{
// Deal With Error
}
break;
}
}
WTSFreeMemory(pSessionInfo);
}
The message box will not be visible on Windows Vista and later due to a change that has services running in a separate session (Session 0 Isolation) that does not have access to a desktop so the message box would not be visible to you, the logged on user.
On Window XP and earlier, you need to tick the Allow service to interact with desktop checkbox under the Log On tab in the service's properties dialog for your service to make message box appear.
Instead, you could write the service name out to a file or run a user application that accepts the name of the service to query and have it query and display the service name (I just tried with the posted code and it works correctly, displaying the message box).
I have a little console application that among other things checks the status of another operation. Once a second it checks for keypresses using Term::ReadKey. If the 'r' key has been pressed, it refreshes the display:
{ # generate display ...
print "Press 'r' to refresh, any other key to exit: ";
my $resp = readkey();
print $resp;
redo if $resp =~ /r/i;
}
exit;
sub readkey {
my $key;
ReadMode('cbreak');
while (not defined $key) {
if (defined ($key = ReadKey(-1)) ) {
exit if $key =~ /\cC/i; # allow Ctrl-C to behave normally
return $key;
} else {
sleep 1;
}
}
ReadMode('normal');
}
This all works exactly as intended. However, I also use Caffeine to keep my Win 7 display from going to sleep. This utility works by simulating a press of F15 every 59 seconds, thereby never allowing the screensaver to kick in. Although Caffeine's approach is pretty kludgy it has worked very well for me for years. However, like Windows my console app also reads the simulated press of F15 as a real keypress, causing the console app to exit. If I could match against F15, I could filter it out. So, my question:
How can I determine if F15 has been pressed, using Term::ReadKey?
This is on Windows 7 Pro, Strawberry 5.12.3, Term::ReadKey v. 2.30.02.
(I am aware that there may be a significant x-y problem component to my question, and I welcome other solutions. However, I am curious about how one would do this. I can see why I might want to see when a function key has been pressed in other situations.)
[It's good that you recognize that this is very xy :)]
You're using a unix-centric module. Use a more appropriate module: Win32::Console, for example.
[My earlier answer got converted to a comment. Apparently, the Stack Overflow mods wants my answer to be 99% repeated content?!?]
my $con_in = Win32::Console->new(STD_INPUT_HANDLE);
for (;;) {
my #event = $con_in->Input();
my $event_type = shift(#event);
next if !defined($event_type) || $event_type != 1; # 1: Keyboard
my ($key_down, $repeat_count, $vkcode, $vscode, $char, $ctrl_key_state) = #event;
if ($vkcode == VK_F15 && ($ctrl_key_state & SHIFTED_MASK) == 0) {
if ($key_down) {
say "<Up> pressed/held down" for 1..$repeat_count;
} else {
say "<Up> released";
}
}
}
See KEY_EVENT_RECORD for more information about keyboard events.
See Virtual-Key Codes to identify keys.
Headers and definitions for above code:
use strict;
use warnings;
use feature qw( say );
use Win32::Console qw( STD_INPUT_HANDLE );
use constant {
RIGHT_ALT_PRESSED => 0x0001,
LEFT_ALT_PRESSED => 0x0002,
RIGHT_CTRL_PRESSED => 0x0004,
LEFT_CTRL_PRESSED => 0x0008,
SHIFT_PRESSED => 0x0010,
VK_F15 => 0x7E,
};
use constant SHIFTED_MASK =>
RIGHT_ALT_PRESSED |
LEFT_ALT_PRESSED |
RIGHT_CTRL_PRESSED |
LEFT_CTRL_PRESSED |
SHIFT_PRESSED;
Right now i have a function that runs a query, using ADO, and returns a recordset:
Recordset Execute(Connection connection, String commandText)
{
//[pseudo-code]
Recordset rs = new Recordset();
rs.CursorLocation = adUseClient;
rs.CursorType = adOpenForwardOnly;
rs.Open(commandText, connection,
adOpenForwardOnly, //CursorType; the default
adLockReadOnly, //LockType
adCmdText);
return rs;
}
And this is fine. It runs synchronously, and returns the recordset of a query.
Now i want a similar version, that shows a ProgressDialog, providing the user with the ability to cancel a long-running query:
Recordset Execute(HWND parenthWnd, String caption, Connection connection, String commandText)
{
//[pseudo-code]
//Construct a progressDialog and show it
IProgressDialog pd = new ProgressDialog();
pd.SetTitle(caption); //e.g. "Annual Funding Report"
pd.SetCancelMsg("Please wait while the operation is cancelled");
pd.StartProgressDialog(parenthWnd, null, PROGDLG_MODAL | PROGDLG_NOTIME | PROGDLG_NOMINIMIZE, null);
pd.SetLine(1, "Querying server", False, null);
try
{
//Query the server
Recordset rs = new Recordset();
rs.Open(commandText, connection,
adOpenForwardOnly, //CursorType
adLockReadOnly, //LockType
adCmdText | adAsyncExecute);
while (rs.State and (adStateConnecting+adStateExecuting+adStateFetching) <> 0)
{
if pd.HasUserCancelled()
throw new EUserCancelledOperationException();
Sleep(100);
};
finally
{
//Hide and destroy the progress dialog
pd.StopProgressDialog();
pd = null;
}
//Now we have our results for the client
return rs;
}
The way to check if the user has cancelled the operation is to periodically ask the progress dialog if the user as pressed the cancel button:
pd.HasUserCancelled(); //returns true if user has clicked Cancel
Now i'm faced with how to periodically check if the user has cancelled (and to know if the query has completed, or an error has happened), and to be a good programmer and do it without polling.
The only way to know that an error has happened is to have a handler on the Recordset's FetchCompleteEvent:
pError
An Error object. It describes the error that occurred if the value of adStatus is adStatusErrorsOccurred; otherwise it is not set.
adStatus
An EventStatusEnum status value. When this event is called, this parameter is set to adStatusOK if the operation that caused the event was successfull, or to adStatusErrorsOccurred if the operation failed.
Before this event returns, set this parameter to adStatusUnwantedEvent to prevent subsequent notifications.
pRecordset
A Recordset object. The object for which the records were retrieved.
So this would imply that i'm going to have to have my function construct a helper object, so i can have a FetchComplete handler. But then i have to prevent my synchronous function from returning right away. And then we get into MsgWaitForSingleObject, which is notoriously difficult to use correctly.
So i'm asking for assistance, or canned code.
i should be more explicit: i'm looking for an implementation of function with this method signature:
Recordset ExecuteWithCancelOption(Connection connection, String commandText)
that shows a dialog with a cancel button on it.
The challenge is that the function must now create whatever is required to achieve that. If that involves a hidden form, that has a timer on it, etc - okay.
But i'm looking for a synchronous function that displays a Cancel button.
And the function is going to be a near (or exact) drop-in replacement for
Recordset Execute(Connection connection, String commandText)
Given practical considerations on Windows, i would need to supply the function with a parent window handle that it will parent its dialog to:
Recordset ExecuteWithCancelOption(HWND parentHwnd, Connection connection, String commandText)
And given that this is going to be a reusable function, i'll let the caller provide the text that will be displayed:
Recordset ExecuteWithCancelOption(HWND parenthWnd, String caption, Connection connection, String commandText)
And given that these are both class functions in my TADOHelper class, i can give them the same name, and have them be overloads of one another:
Recordset Execute(HWND parenthWnd, String caption, Connection connection, String commandText)
i would think in languages other than Delphi, anonymous delegates are helpful. But i'm still terrified of having to deal with MsgWaitForMultipleObjects.
Progress informations and gracefully cancelling a query may not be available in every database engine. They need database support, both on the server and the client side. For example Oracle allows cancelling a query, yet has no "on progress" information but reading the V$SESSION_LONGOPS view. Sure, you can kill the session, but it will rollback the whole of it, not just cancel a give query execution.
Usually if the database supports this kind of features, the query is run in a separate thread that will wait for the result. That way the main thread can still get user input or read and display progress information (unless returned in some kind of callback). If the user cancels the query then the appropriate call is issued to stop the operation, allowing the query thread to return, usually the thread will receive a status code that will tell what's happened.
Be aware of how ADO implements async operations: http://msdn.microsoft.com/en-us/library/ms681467(VS.85).aspx
There's also a FetchProgress() event that could help you if you don't want to go the thread way (and even then to cancel a the query, if possible)
In order to make GUI to respond to button clicks you should return control to the message loop of the window. While loop while (rs.State and (adStateConnecting+adStateExecuting+adStateFetching) <> 0) does not return control back to the message loop thus blocking GUI.
Below is an excerpt from a working Delphi code that uses asyncronous ADO queries. This code does not allow for non-modal fetching of data, but ensures that the main form is repainted during data fetch and also allows cancelling the query.
Asynchronous execution and fetching is achieved by setting:
FOpeningDataSet.ExecuteOptions := [eoAsyncExecute, eoAsyncFetchNonBlocking];
execution of query is cancelled by calling
DataSet.Recordset.Cancel;
in FetchProgress event.
Any TADODataSet shall be opened via the method:
OpenDataSetInBackground(DataSourceData.DataSet as TADODataSet);
Supporting code in the main form:
procedure TOperatorForm.OpenDataSetInBackground(DataSet: TADODataSet);
begin
if DataSet.Active then Exit;
FOpeningDataSet := DataSet;
if not FAsyncDataFetch then
begin
FOpeningDataSet.Open;
Exit;
end;
FFetchCancel := False;
FExecuteOptions := FOpeningDataSet.ExecuteOptions;
FFetchProgress := FOpeningDataSet.OnFetchProgress;
FFetchComplete := FOpeningDataSet.OnFetchComplete;
FRecordsetCreate := FOpeningDataSet.OnRecordsetCreate;
FAfterScroll := FOpeningDataSet.AfterScroll;
FOpeningDataSet.ExecuteOptions := [eoAsyncExecute, eoAsyncFetchNonBlocking];
FOpeningDataSet.OnFetchProgress := DataSetFetchProgress;
FOpeningDataSet.OnFetchComplete := DataSetFetchComplete;
FOpeningDataSet.OnRecordsetCreate := DataSetRecordsetCreate;
FOpeningDataSet.AfterScroll := DataSetAfterScroll;
FOpeningDataSet.CursorLocation := clUseClient;
FOpeningDataSet.DisableControls;
try
DataSetProgressForm.Left := Left + (Width - DataSetProgressForm.Width) div 2;
DataSetProgressForm.Top := Top + (Height - DataSetProgressForm.Height) div 2;
DataSetProgressForm.cxButton1.OnClick := DataSetProgressClick;
DataSetProgressForm.cxButton1.Visible := FShowProgressCancelButton;
FOpeningDataSet.Open;
DataSetProgressForm.ShowModal;
finally
FOpeningDataSet.EnableControls;
FOpeningDataSet.ExecuteOptions := FExecuteOptions;
FOpeningDataSet.OnFetchProgress := FFetchProgress;
FOpeningDataSet.OnFetchComplete := FFetchComplete;
FOpeningDataSet.OnRecordsetCreate := FRecordsetCreate;
FOpeningDataSet.AfterScroll := FAfterScroll;
end;
end;
procedure TOperatorForm.DataSetProgressClick(Sender: TObject);
begin
FFetchCancel := True;
end;
procedure TOperatorForm.DataSetFetchProgress(DataSet: TCustomADODataSet; Progress, MaxProgress: Integer; var EventStatus: TEventStatus);
begin
if FFetchCancel then
DataSet.Recordset.Cancel;
end;
procedure TOperatorForm.DataSetFetchComplete(DataSet: TCustomADODataSet; const Error: Error; var EventStatus: TEventStatus);
begin
PostMessage(DataSetProgressForm.Handle, WM_CLOSE, 0, 0);
MessageBeep(MB_ICONEXCLAMATION);
end;
procedure TOperatorForm.DataSetFetchComplete(DataSet: TCustomADODataSet; const Error: Error; var EventStatus: TEventStatus);
begin
PostMessage(DataSetProgressForm.Handle, WM_CLOSE, 0, 0);
MessageBeep(MB_ICONEXCLAMATION);
end;
procedure TOperatorForm.DataSetRecordsetCreate(DataSet: TCustomADODataSet; const Recordset: _Recordset);
begin
if Assigned(FRecordsetCreate) then FRecordsetCreate(DataSet, Recordset);
end;
procedure TOperatorForm.DataSetAfterScroll(DataSet: TDataSet);
begin
// From TBetterADODataSet 4.04
// Ole Willy Tuv's fix 03-10-00 for missing first record
with TADODataSet(DataSet) do
begin
if (eoAsyncFetchNonBlocking in ExecuteOptions) and
(Bof or Eof) and
(CursorLocation = clUseClient) and
(stFetching in RecordSetState) then
begin
if Recordset.RecordCount > 0 then
if Bof then
Recordset.MoveFirst
else if Eof then
Recordset.MoveLast;
CursorPosChanged;
Resync([]);
end;
end;
if Assigned(FAfterScroll) then
FAfterScroll(DataSet);
end;
Progress form:
unit uDataSetProgressForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls, StdCtrls;
type
TDataSetProgressForm = class(TForm)
AnimateProgress: TAnimate;
Label1: TLabel;
Bevel1: TBevel;
Bevel2: TBevel;
Button1: TButton;
Shape1: TShape;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormHide(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DataSetProgressForm: TDataSetProgressForm;
implementation
{$R *.dfm}
{$R servertimeout.res} // contains IDR_SERVAVI animation resource
procedure TDataSetProgressForm.FormCreate(Sender: TObject);
begin
AnimateProgress.ResName := 'IDR_SERVAVI';
end;
procedure TDataSetProgressForm.FormShow(Sender: TObject);
begin
AnimateProgress.Active := True;
end;
procedure TDataSetProgressForm.FormHide(Sender: TObject);
begin
AnimateProgress.Active := False;
end;
end.
and dfm
object DataSetProgressForm: TDataSetProgressForm
Left = 590
Top = 497
BorderStyle = bsNone
ClientHeight = 104
ClientWidth = 205
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
FormStyle = fsStayOnTop
OldCreateOrder = False
Position = poDefaultSizeOnly
OnCreate = FormCreate
OnHide = FormHide
OnShow = FormShow
DesignSize = (
205
104)
PixelsPerInch = 96
TextHeight = 13
object Bevel1: TBevel
Left = 0
Top = 0
Width = 205
Height = 104
Align = alClient
Style = bsRaised
end
object Bevel2: TBevel
Left = 12
Top = 12
Width = 181
Height = 80
Anchors = [akLeft, akTop, akRight, akBottom]
end
object Shape1: TShape
Left = 1
Top = 1
Width = 203
Height = 102
Anchors = [akLeft, akTop, akRight, akBottom]
Brush.Style = bsClear
Pen.Color = clWindowFrame
end
object AnimateProgress: TAnimate
Left = 25
Top = 23
Width = 32
Height = 32
end
object Label1: TLabel
Left = 70
Top = 31
Width = 106
Height = 17
Hint = 'Selecting data...'
Caption = 'Selecting data...'
TabOrder = 1
end
object Button1: TButton
Left = 63
Top = 64
Width = 80
Height = 23
Caption = 'Cancel'
Default = True
TabOrder = 2
end
end
If it is Delphi you can drop a TTimer component in and use that to check if HasUserCancelled value is True. I don't have Delphi in front of me so I'd have to post an example later.
Edit:
Here's an example of a TTimer OnTimer event that checks the current time and the lastactivity time to decide what to do with the forms if the program has been left "Up":
procedure TForm_Main.Timer1Timer(Sender: TObject);
begin
// return to opening screen if no activity for a while:
if Now - LastActivity > TimeOut
then
begin
Form_Select.SBtn_Defendant.Down:= False;
Form_Select.SBtn_Officer.Down:= False;
Form_Select.SBtn_Attorney.Down:= False;
Form_Main.ModalResult:= mrCancel;
Exit;
end;
Form_Main.Caption:= FormatDateTime('dddd mmmm d, yyyy h:nn:ss AM/PM', Now);
end;