--attrib1.exw--
--start code--

include win32lib.ew
without warning

atom junk, file_id_ptr, attribs

--FILE_ATTRIBUTE_READONLY = 1
--FILE_ATTRIBUTE_HIDDEN = 2
--FILE_ATTRIBUTE_ARCHIVE = 32
--FILE_ATTRIBUTE_NORMAL = 128

constant
zOPEN_EXISTING = 3,

Win     = create(Window,"File Attributes",0,0,0,205,225,0),
Label0  = create(LText,"filename:",Win,10,12,70,20,0),
Entry   = create(EditText,"",Win,75,10,110,20,0),
Label1  = create(LText,"",Win,10,40,180,20,0),
Label2  = create(LText,"",Win,10,65,180,20,0),
Check1  = create(CheckBox," Read-Only (1)",Win,10,90,170,20,0),
Check2  = create(CheckBox," Hidden    (2)",Win,10,115,170,20,0),
Check3  = create(CheckBox," Archive   (32)",Win,10,140,170,20,0),
Button1 = create(PushButton,"Change Attributes",Win,10,165,130,25,0),
--**
zGetFileAttributes=registerw32Function(kernel32,"GetFileAttributesA",
                   {C_POINTER},C_LONG),
zSetFileAttributes=registerw32Function(kernel32,"SetFileAttributesA"
                  ,{C_POINTER,C_LONG},C_LONG),
zCreateFile=registerw32Function(kernel32,"CreateFileA",
            {C_POINTER,C_LONG,C_LONG,C_LONG,C_LONG,C_LONG,C_LONG},C_LONG),
zCloseHandle=registerw32Function(kernel32,"CloseHandle",{C_LONG},C_LONG),
zGetFileSize=registerw32Function(kernel32,"GetFileSize",{C_LONG,C_LONG},C_LONG)

for i=Check1 to Check3 do
setFont( i,"Courier New",11,Bold)
end for

procedure onLoad_Win(atom self, atom event, sequence params)
atom size
setText(Entry,"attrib1.exw")
file_id_ptr=acquire_mem(0,"attrib1.exw")
junk=w32Func(zCreateFile,{file_id_ptr,0,0,0,zOPEN_EXISTING,0,0})
size=w32Func(zGetFileSize,{junk,0})
setText(Label1,"file size = " & sprintf("%d",size))
junk=w32Func(zCloseHandle,{junk})
junk=w32Func(zGetFileAttributes,{file_id_ptr})
setText(Label2,"current attributes = " & sprintf("%d",junk))
if junk < 128 then
if junk >= 32 then setCheck(Check3,1) junk=junk-32 end if
if junk >= 2 then setCheck(Check2,1) junk=junk-2 end if
if junk = 1 then setCheck(Check1,1) end if
end if
release_mem(file_id_ptr)
end procedure

procedure set_attribs(atom self, atom event, sequence params)
attribs=0
if isChecked(Check1) then attribs=attribs+1 end if
if isChecked(Check2) then attribs=attribs+2 end if
if isChecked(Check3) then attribs=attribs+32 end if
file_id_ptr=acquire_mem(0,"attrib1.exw")
junk=w32Func(zSetFileAttributes,{file_id_ptr,attribs})
junk=w32Func(zGetFileAttributes,{file_id_ptr})
setText(Label2,"current attributes = " & sprintf("%d",junk))
release_mem(file_id_ptr)
end procedure

setHandler( Win, w32HOpen, routine_id( "onLoad_Win") )
setHandler( Button1, w32HClick, routine_id( "set_attribs") )


WinMain( Win, Normal )
--end code--


