/* a simple SDI editor (like notepad). Created by using a multiline edit control sized to the window version 1.2 for EBASIC. Compile with a WINDOWS target */ OPENCONSOLE $include "windows.inc" def win:window def left,top,width,height,hprinter:int def startpg,endpg,copies,collate:int def filename,ln,printer,filter:string def file1:FILE def buffer[32766]:ISTRING run = 0 TYPE CHARFORMAT UINT cbSize WORD dwMask WORD dwEffects UINT yHeight UINT yOffset UINT crTextColor CHAR bCharSet CHAR bPitchAndFamily CHAR szFaceName[LF_FACESIZE] ENDTYPE CHARFORMAT cf const EM_SETSEL = 0xB1 const CFM_COLOR = 0x40000000 const EM_SETCHARFORMAT = (WM_USER + 68) const SCF_SELECTION = 0x0001 int hrich 'Open our main window, get its client size and create the control openwindow win,0,0,640,400,@SIZE|@MINBOX|@MAXBOX|@MAXIMIZED|@NOAUTODRAW,0,"EDITOR V1.2",&mainwindow getclientsize win,left,top,width,height CONTROL win,@RICHEDIT,"",7,35,570,294,0x50B010C4,1 int rHandle rHandle = GETCONTROLHANDLE(win,1) 'hrich = controlex win,"riched20","syntax color",10,10,400,300,0x50B010C4,@EXCLIENTEDGE,1 'CONTROLEX win,"msctls_progress32","",4,40,236,20,@BORDER,,20 'CONTROLEX(parent, class as STRING,title as STRING,l as INT,t as INT,w as INT,h as INT,style as INT,exStyle as INT,id as UINT) BEGINMENU win MENUTITLE "&File" MENUITEM "&Load File\tCtrl+L",0,1 MENUITEM "&Save\tCtrl+S",0,2 MENUITEM "&Print\tAlt+P",0,4 MENUITEM "&Quit\tCtrl+C",0,3 MENUTITLE "&Options" MENUITEM "Change Font\tF4",0,5 ENDMENU DoOpen() PRINT SENDMESSAGE(rHandle,EM_SETSEL,0,100) cf.dwMask = CFM_COLOR cf.crTextColor = RGB(255,0,0) cf.cbSize = len(CHARFORMAT) + 4 PRINT cf.cbSize SETCAPTION win,STR$(rHandle) SENDMESSAGE(rHandle,EM_SETCHARFORMAT,SCF_SELECTION,&cf) 'process messages until somebody closes us run = 1 waituntil run=0 closewindow win CLOSECONSOLE end 'this is the handler subroutine for the window 'process @IDSIZE to size the edit control 'process the menus 'process @IDCLOSEWINDOW to quit the program sub mainwindow select @MESSAGE case @IDCLOSEWINDOW run = 0 case @IDSIZE 'size the edit control to match the client size of the window 'we use CONTROLEXISTS to verify the existance of the edit control 'because the first @IDSIZE message is sent while the window is being created 'but before we have a chance to add the edit control. if CONTROLEXISTS(win,1) getclientsize win,left,top,width,height setsize win,left,top,width,height,1 endif case @IDMENUPICK select @MENUNUM case 5 GOSUB changefont case 4 'dump the edit control to the printer GOSUB doprint case 3 'quit the program run = 0 case 2 'save the file GOSUB dosave case 1 'open a file GOSUB doopen endselect endselect return endsub '------------- DOOPEN ---------------- SUB doopen filename = FILEREQUEST("Load file",win,1,filter,"rtf") if(len(filename)) if(OPENFILE(file1,filename,"R")=0) CONTROLCMD win,1,@RTLOAD,file1,1 CLOSEFILE file1 endif endif RETURN endsub '------------- DOSAVE ----------------- SUB dosave filename = filerequest("Save File",win,0) if(len(filename) > 0) if(openfile(file1,filename,"W") = 0) buffer = getcontroltext(win,1) write file1,buffer closefile file1 endif endif RETURN endsub '------------- DOPRINT ---------------- 'prints the contents of the edit control 'using straight text printing. 'This method won't work for GDI only printers '-------------------------------------- SUB doprint startpg = 1 endpg = 1 copies = 1 collate = 1 printer = PRTDIALOG(win,startpg,endpg,copies,collate) hprinter = OPENPRINTER(printer,"Document","TEXT") if(hprinter) buffer = getcontroltext(win,1) WRITEPRINTER hprinter, buffer CLOSEPRINTER hprinter endif RETURN endsub '------------- CHANGEFONT ------------- SUB changefont DEF size,weight,flags,col:int DEF fontname:string size = 12 weight = 400 flags = 0 col = 0 fontname = FONTREQUEST(win,size,weight,flags,col) if(fontname <> "") SETFONT win,fontname,size,weight,flags,1 endif SETCONTROLCOLOR win,1,col,RGB(255,255,255) RETURN endsub