All pastes #2061507 Raw Edit

Stuff

public text v1 · immutable
#2061507 ·published 2011-05-16 14:46 UTC
rendered paste body
% first, must create the dialog window by using the dialog editor
% and EXPORTING to the I/E window. From there, copy its contents
% and paste them to this window, as below:

my_gui :- 
   _S1 = [dlg_ownedbyprolog,ws_sysmenu,ws_maximizebox,ws_minimizebox,ws_thickframe,ws_caption],
   _S2 = [ws_child,ws_visible,ws_tabstop,bs_defpushbutton],
   _S3 = [ws_child,ws_visible,ws_tabstop,bs_pushbutton],
   _S12 = [ws_child,ws_border,ws_visible],
   wdcreate(  my_gui,        `my_gui`,                              232,  40, 400, 400, _S1  ),
   wccreate( (my_gui,1000),  button,    `Ok`,                        10,  10,  60,  30, _S2  ),
   wccreate( (my_gui,1001),  button,    `Close`,                     70,  10,  60,  30, _S3  ),
   wccreate( (my_gui,9000),  grafix,    `Grafix1`,                    0,  80,  40,  40, _S12 ),
   wccreate( (my_gui,9001),  grafix,    `Grafix1`,                   40,  80,  40,  40, _S12 ),
   wccreate( (my_gui,9002),  grafix,    `Grafix1`,                   80,  80,  40,  40, _S12 ),
   wccreate( (my_gui,9003),  grafix,    `Grafix1`,                  120,  80,  40,  40, _S12 ),
   wccreate( (my_gui,9004),  grafix,    `Grafix1`,                  160,  80,  40,  40, _S12 ),
   wccreate( (my_gui,9005),  grafix,    `Grafix1`,                    0, 120,  40,  40, _S12 ),
   wccreate( (my_gui,9006),  grafix,    `Grafix1`,                   40, 120,  40,  40, _S12 ),
   wccreate( (my_gui,9007),  grafix,    `Grafix1`,                   80, 120,  40,  40, _S12 ),
   wccreate( (my_gui,9008),  grafix,    `Grafix1`,                  120, 120,  40,  40, _S12 ),
   wccreate( (my_gui,9009),  grafix,    `Grafix1`,                  160, 120,  40,  40, _S12 ),
   wccreate( (my_gui,9010),  grafix,    `Grafix1`,                    0, 160,  40,  40, _S12 ),
   wccreate( (my_gui,9011),  grafix,    `Grafix1`,                   40, 160,  40,  40, _S12 ),
   wccreate( (my_gui,9012),  grafix,    `Grafix1`,                   80, 160,  40,  40, _S12 ),
   wccreate( (my_gui,9013),  grafix,    `Grafix1`,                  120, 160,  40,  40, _S12 ),
   wccreate( (my_gui,9014),  grafix,    `Grafix1`,                  160, 160,  40,  40, _S12 ),
   wccreate( (my_gui,9015),  grafix,    `Grafix1`,                    0, 200,  40,  40, _S12 ),
   wccreate( (my_gui,9016),  grafix,    `Grafix1`,                   40, 200,  40,  40, _S12 ),
   wccreate( (my_gui,9017),  grafix,    `Grafix1`,                   80, 200,  40,  40, _S12 ),
   wccreate( (my_gui,9018),  grafix,    `Grafix1`,                  120, 200,  40,  40, _S12 ),
   wccreate( (my_gui,9019),  grafix,    `Grafix1`,                  160, 200,  40,  40, _S12 ),
   wccreate( (my_gui,9020),  grafix,    `Grafix1`,                    0, 240,  40,  40, _S12 ),
   wccreate( (my_gui,9021),  grafix,    `Grafix1`,                   40, 240,  40,  40, _S12 ),
   wccreate( (my_gui,9022),  grafix,    `Grafix1`,                   80, 240,  40,  40, _S12 ),
   wccreate( (my_gui,9023),  grafix,    `Grafix1`,                  120, 240,  40,  40, _S12 ),
   wccreate( (my_gui,9024),  grafix,    `Grafix1`,                  160, 240,  40,  40, _S12 ).



% now must actually create the dialog and then show it.

doit:-						% use this to declare my_gui
	my_gui,					% my_gui is the dialog window name
	wshow(my_gui,1),			% show it - make it appear
	window_handler(my_gui,my_gui_handler),	% window handler for my_gui=my_gui_handler
	call_dialog(my_gui,X).			% running the dialog

% now must create a handler program to process the messages that the
% controls generate
%
% The first one is a handler that is specific to the msg_button 1000
% ie the Ok button.
% it does a few things, but importantly, it does not instantiate the final (4th)
% argument - if it did, it would terminate the dialog
 
my_gui_handler((my_gui,1000), msg_button,_,_):-	% ID=1000 is the Ok button
	writeq(Text),				% also write it to the console window
	nl,					% and a new line
	ttyflush,				% housekeeping
	beep(440,32).				% make a beep noise (frequency, duration)

% the next one is (sort of) simple, when the close button is pressed (ID 1001),
% a message box appears that returns a value B that is:
% OK = 1
% Cancel= 2
% The clause check_close is used to determine what to do. If it is OK=1, then 
% this will destroy the dialog window, otherwise do nothing - back to before

my_gui_handler((my_gui,1001), msg_button,_,C):-			% C is the var
	msgbox('Warning', 'this will close the dialog',49,B),	% get the value
	check_close(B,C).					% what to do?

check_close(B,C):-				% takes the vars B & C
	B=1, C=1.				% must satisfy B=1 and C=1


%
% this next one does a simple check after the X button has been clicked on
% it refuses to close the user-dialog, but directs the user to close in 
% the 'proper fashion' It is mildly abusive too!
%
my_gui_handler(my_gui,msg_close,_,_):-
	msgbox('Daft person', 'Use the Close button to close',48,C).