RE: Win32LIB question

new topic     » topic index » view thread      » older message » newer message

> -----Original Message-----
> From: Guest [mailto:guest at RapidEuphoria.com]
> Subject: Win32LIB question
>
>
>
> posted by: shenpen at freemail.hu
>
> Hi all,
>
> thanx to Rob for the answer.
>
> Now I started to make a GUI library, which enables one create GUI with
> very little code. It's basic logic is that many applications
> want to display something in lines (files in an archive etc.)
> and some menus to do something with it, and thus a
> standardized "browse window" can be created very easily. I
> ran into a seemingly serious problem, so I created a very
> simple scenario that show the main logic of this concept. My
> problem is commented in the code. Could anyone help a bit?
>
> -- start of include file
> include win32LIB.ew
> global function CreateWindowWithMenu(sequence Menu)
>   sequence retval
>   retval={}
>
>   retval=append(retval,{}) -- will contain the window handle
>   retval[1] = createEx( Window, "Something", 0, Default, Default,
>   800, 600, {WS_DLGFRAME, WS_SYSMENU, WS_MINIMIZEBOX},
>  {WS_EX_DLGMODALFRAME} ) -- window handle is now in retval[1]
>
>   retval=append(retval,{}) -- will contain the data of the menu
>   retval[2]=append(retval[2],createEx( Menu, Menu[1], retval[1], 0,
>   1, 0, 0, 0, 0 )) -- menu handle is now in retval[2][1]
>   retval[2]=append(retval[2],Menu[2]) -- routine name is
>                                       -- now in retval[2][2]
>
>   return retval
> end function
>
> procedure OnClickMenu(integer self, integer event, sequence params)
>   sequence routinename
>   routinename="???????????????"
>   call_proc(routine_id(routinename),{})
>
>   -- it's my problem: how to find the routine name? It's stored in
>   --  the return
>   -- value of the previous function, and also available from the
>   -- next one but not from here!
>
> end procedure
>
> global procedure RunWindow(sequence WindowToRun)
>   -- routine name is available here as WindowToRun[2][2] but
>   -- it can't be used here, I think
>   setHandler(WindowToRun[2][1], w32HClick, routine_id("OnClickMenu"))
>   WinMain(WindowToRun[1],Normal)
> end procedure
>
> --------- end of include file, main program ---------------------
>
> procedure RunThisProcedureWhenMenuIsClicked()
>   -- do something
> end procedure
>
> sequence myWindow
> myWindow=CreateWindowWithMenu(
>                         {"Menu1","RunThisProcedureWhenMenuIsClicked"}
>                     )
>
> RunWindow(MyWindow)
>
> -----------
>
> My problem is that how do I put the routine name to the ????-s.

There is a set of routines, setUserProperty(), getUserProperty() which
allows you to define your own properties for any controls you create. This
means that you can store data associated with a specific control, with that
control. All you need to get access to it is the control ID.

Try this sort of approach and  see if it helps ....

-- start of include file
without warning
include win32LIB.ew
global function CreateWindowWithMenu(sequence pMenu)
  sequence retval
  integer MenuCtl
  retval={0,{}}

  retval[1] = createEx( Window, "Something", 0, Default, Default,
  800, 600, {WS_DLGFRAME, WS_SYSMENU, WS_MINIMIZEBOX},
 {WS_EX_DLGMODALFRAME} ) -- window handle is now in retval[1]

  MenuCtl = createEx(Menu, "Menu", retval[1], 0, 0, 0, 0, 0,0)
  retval[2]=append(retval[2],createEx( MenuItem, pMenu[1], MenuCtl, 0,
  1, 0, 0, 0, 0 )) -- menu handle is now in retval[2][1]
  setUserProperty(retval[2][1],"handler",pMenu[2]) -- routine name is
                                      -- now in a new property of
                                      -- the menu

  return retval
end function

procedure OnClickMenu(integer self, integer event, sequence params)
  sequence lHandler
  lHandler=getUserProperty(self, "handler")
  if length(lHandler) > 0 then
    call_proc(lHandler[1],{})
  end if

end procedure

global procedure RunWindow(sequence WindowToRun)
  -- routine name is available here as WindowToRun[2][2] but
  -- it can't be used here, I think
  setHandler(WindowToRun[2][1], w32HClick, routine_id("OnClickMenu"))
  WinMain(WindowToRun[1],Normal)
end procedure

--------- end of include file, main program ---------------------

procedure RunThisProcedureWhenMenuIsClicked()
  -- do something

end procedure

sequence myWindow
myWindow=CreateWindowWithMenu(

{"Menu1",routine_id("RunThisProcedureWhenMenuIsClicked")}
                    )

RunWindow(myWindow)



> I hope you like logic of this stuff - I think it will be a
> nicely usable thing if I get through the obstacles.

Good luck this project.

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu