View previous topic :: View next topic |
Author |
Message |
ShinobiSoft Professional Member
Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Mon Dec 16, 2002 4:19 am Post subject: Simple useage of Windows API |
|
|
The purpose of this script is to demonstrate the usage of some of the Windows API calls through the @sendmsg() function.
See the rem statements within the script code for a further explanation.
Code: |
rem This script was designed to demonstrate a few of the Windows API calls that might
rem be used within a text editor or Notepad type application.
rem The main purpose of this script, however, is to demonstrate how to use the Windows
rem API to obtain the Line and Column numbers from a multi-line edit (MLE) control.
rem Some additional functionality includes enabling and disabling toolbar buttons,
rem automatically reopening the last opened file and setting the EDIT control to the
rem line and column positions from the previous session.
%%new = 1
%F = @regread(default,,lastFile)
if @null(%F)
%F = @path(%0)Untitled%%new.txt
else
%1 = %F
end
rem To further customize this application, simply create a dialog,
rem within this script, for changing/setting of the variables below.
rem Then put in a gosub call to the :SetTabsAndMargins function to apply these
rem new settings to the EDIT control. You could also save these values
rem to the registry or an ini file and retrieve them upon the programs entry.
%%tabStops = 2
%%marginLeft = 20
%%marginRight = 80
TITLE Editor
option scale,96
dialog create,Editor,-1,0,640,480,CLASS EditWin
dialog add,Style,St1,Courier New,9,,#FFFFFF,#8F4040
dialog add,MENU,&File,&New|Ctrl+N,&Open|Ctrl+O,&Save|Ctrl+S,Save &As...,-,&Print|Alt+P,-,E&xit|Alt+X
dialog add,MENU,&Edit,&Undo|Ctrl+Z,-,Cu&t|Ctrl+X,&Copy|Ctrl+C,&Paste|Ctrl+V,Select &All|Ctrl+A,-,&Options|Alt+O
dialog add,MENU,&Help,&About
dialog add,Group,TBar1,5,5,630,30
dialog add,BITBTN,New,10,10,20,20,Newfile.bmp,,New
dialog add,BITBTN,Open,10,30,20,20,Openfile.bmp,,Open
dialog add,BITBTN,Save,10,50,20,20,Savefile.bmp,,Save
dialog add,GROUP,Sep1,5,75,2,30
dialog add,BITBTN,Print,10,80,20,20,Printfile.bmp,,Print
dialog add,GROUP,Sep2,5,105,2,30
dialog add,BITBTN,Cut,10,110,20,20,Cut.bmp,,Cut
dialog add,BITBTN,Copy,10,130,20,20,Copy.bmp,,Copy
dialog add,BITBTN,Paste,10,150,20,20,Paste.bmp,,Paste
dialog add,GROUP,Sep3,5,175,2,30
dialog add,BITBTN,Undo,10,180,20,20,Undo.bmp
dialog add,EDIT,Ed1,40,0,640,420,,,MULTI,SCROLL,TABS,St1
dialog add,Status,Stat
dialog show
gosub SetTabsAndMargins
if %1
goto OpenMENU
end
:Evloop
wait "0.1",event
parse "%E;%D",@event(D)
goto %E
:Timer
%%name = @name(%F).@ext(%F)
if @null(@dlgtext(Ed1))
dialog disable,Print
else
dialog enable,Print
end
REM *** EM_GETMODIFY ***
%%getModify = @sendmsg(~Ed1,$00B8,0,0)
if @equal(%%getModify,0)
%%status =
dialog disable,Save
dialog title,Editor - [%%name]
else
%%status = Modified
dialog enable,Save
dialog title,Editor - [%%name*]
end
REM *** EM_CANUNDO ***
%%canUndo = @sendmsg(~Ed1,$00C6,0,0)
if @equal(%%canUndo,1)
dialog enable,Undo
else
dialog disable,Undo
end
REM *** EM_LINEINDEX ***
%%lineIndex = @sendmsg(~Ed1,$00BB,-1,0)
REM *** EM_LINEFROMCHAR ***
%%line = @sendmsg(~Ed1,$00C9,-1,0)
REM *** EM_GETSEL ***
%%getSel = @sendmsg(~Ed1,$00B0,NULL,NULL)
%%charIndex = @fdiv(%%getSel,65537)
%%col = @format(@fsub(%%charIndex,%%lineIndex),4.0)
%%dec = @pos(.,%%charIndex)
if @greater(%%dec,0)
dialog enable,Cut
dialog enable,Copy
else
dialog disable,Cut
dialog disable,Copy
end
list create,3
list paste,3
if @text(3)
dialog enable,Paste
else
dialog disable,Paste
end
list close,3
dialog set,Stat,Line: @succ(%%line) Col: @succ(%%col)@tab()%%status@tab()@datetime(tt)" "
goto Evloop
:NewMENU
:NewBUTTON
%%new = @succ(%%new)
%F = @path(%0)Untitled%%new.txt
dialog set,Ed1,
rem Sets the Modified flag to FALSE.
%%setModify = @sendmsg(~Ed1,$00B9,0,0)
goto Evloop
:OpenMENU
:OpenBUTTON
if @null(%1)
%%F = @filedlg("Text files (*.txt)|*.txt",Open file,%F,OPEN)
else
%%F = %1
%1 =
end
if @not(@null(%%F))
%F = %%F
list create,1
list loadfile,1,%F
dialog set,Ed1,@text(1)
list close,1
%%F =
rem Sets the Modified flag to FALSE.
%%setModify = @sendmsg(~Ed1,$00B9,0,0)
if @equal(%F,@regread(default,,lastFile))
%%oldIndex = @regread(default,,lineCol)
dialog focus,Ed1
%%setSel = @sendmsg(~Ed1,$00B1,%%oldIndex,%%oldIndex)
%%scrollCaret = @sendmsg(~Ed1,$00B7,0,0)
end
end
goto Evloop
:SaveMENU
:SaveBUTTON
%%msg = @msgbox(Function not implemented!,Editor,$040)
rem +++ ADD CODE HERE +++
rem then...
rem Sets the Modified flag to FALSE.
%%setModify = @sendmsg(~Ed1,$00B9,0,0)
goto Evloop
:Save As...MENU
%%msg = @msgbox(Function not implemented!,Editor,$040)
goto Evloop
:PrintMENU
:PrintBUTTON
if @dlgtext(Ed1)
list create,1
list assign,1,@dlgtext(Ed1)
list print,1,Courier New,9
list close,1
end
goto Evloop
:UndoMENU
:UndoBUTTON
%%undo = @sendmsg(~Ed1,$0304,0,0)
goto Evloop
:CutMENU
:CutBUTTON
%%cut = @sendmsg(~Ed1,$0300,0,0)
goto Evloop
:CopyMENU
:CopyBUTTON
%%copy = @sendmsg(~Ed1,$0301,0,0)
goto Evloop
:PasteMENU
:PasteBUTTON
%%paste = @sendmsg(~Ed1,$0302,0,0)
goto Evloop
:Select AllMENU
%%setSel = @sendmsg(~Ed1,$00B1,0,-1)
goto Evloop
:AboutMENU
%%msgText = Editor 1.0@cr()@cr()Written by Bill Weckel of ShinobiSoft@cr()@cr()To demonstrate some of the uses@cr()of the "@"sendmsg() function.
%%msg = @msgbox(%%msgText,"About Editor",$040)
goto Evloop
:ExitMENU
:CLOSE
registry write,default,,lastfile,%F
registry write,default,,linecol,%%charIndex
exit
:SetTabsAndMargins
%%setTabStops = @sendmsg(~Ed1,$00CB,1,@chr(@prod(%%tabstops,4)))
%%setLeftMargin = @sendmsg(~Ed1,$00D3,1,20)
%%setRightMargin = @sendmsg(~Ed1,$00D3,2,80)
exit
|
Happy coding!!
Bill
ShinobiSoft _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
Back to top |
|
|
GeoTrail Valued Contributor
Joined: 18 Feb 2003 Posts: 572 Location: Bergen, Norway
|
Posted: Fri Feb 21, 2003 3:43 am Post subject: |
|
|
I tried to run the script but got this error:
Invalid parameter to command to line 57 which is
Any ideas why? _________________
|
|
Back to top |
|
|
SnarlingSheep Professional Member
Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Fri Feb 21, 2003 5:51 am Post subject: |
|
|
Try adding OPTION DECIMALSEP,"." at the very top of the script. _________________ -Sheep
My pockets hurt... |
|
Back to top |
|
|
ShinobiSoft Professional Member
Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Fri Feb 21, 2003 5:52 am Post subject: |
|
|
Try inserting the following code into the script beneith the other option
command at the top of the script:
Code: |
option decimalsep,"."
|
I think that will solve the problem. _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
Back to top |
|
|
ShinobiSoft Professional Member
Joined: 06 Nov 2002 Posts: 790 Location: Knoxville, Tn
|
Posted: Fri Feb 21, 2003 5:52 am Post subject: |
|
|
Oops:) Was too slow I guess! _________________ Bill Weckel
ShinobiSoft Software
"The way is known to all, but not all know it." |
|
Back to top |
|
|
SnarlingSheep Professional Member
Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Fri Feb 21, 2003 5:54 am Post subject: |
|
|
I win a new car right? Doesn't have to be fancy..just make sure it starts on a cold morning. _________________ -Sheep
My pockets hurt... |
|
Back to top |
|
|
GeoTrail Valued Contributor
Joined: 18 Feb 2003 Posts: 572 Location: Bergen, Norway
|
Posted: Fri Feb 21, 2003 5:59 am Post subject: |
|
|
Yeah that worked great.
Actually I found the solution in the help file.
It's got something to do with that here in Europe we use a comma as a decimal seperator, and in the US it's a period.
Anyways, SnarlingSheep, how about a dirt brown Pinto? _________________
|
|
Back to top |
|
|
SnarlingSheep Professional Member
Joined: 13 Mar 2001 Posts: 759 Location: Michigan
|
Posted: Fri Feb 21, 2003 6:02 am Post subject: |
|
|
As long as it starts and gets more than 10 miles per gallon it's fine with me, lol _________________ -Sheep
My pockets hurt... |
|
Back to top |
|
|
GeoTrail Valued Contributor
Joined: 18 Feb 2003 Posts: 572 Location: Bergen, Norway
|
Posted: Fri Feb 21, 2003 6:16 am Post subject: |
|
|
Yeah it starts just fine, but you have to reboot every 5 minutes _________________
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|