March 28, 2024, 07:34:22 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Method address

Started by fasecero, July 12, 2009, 02:42:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fasecero

Hi, can we pass a method as the address of a subroutine to process messages for a window?
I can't build this code:


' -----------------------------------------------------------
' MYWIN

' MyWin definition
CLASS MyWin
DECLARE Init(STRING caption, INT width, INT height, pointer parent, int style)
DECLARE Run()
DECLARE VIRTUAL OnCreate(), INT
DECLARE VIRTUAL OnDestroy(), INT

PRIVATE
DECLARE WinProc()
PROTECTED
' members
window win
ENDCLASS

SUB MyWin::Init(STRING caption, INT width, INT height, pointer parent, int style)
OPENWINDOW win,0,0,width,height,style,parent,caption,&WinProc   ' <----------- FAIL
ENDSUB

SUB MyWin::Run(), INT
WAITUNTIL win=0
ENDSUB

SUB MyWin::OnCreate(), INT
RETURN 0
ENDSUB

SUB MyWin::OnDestroy(), INT
CLOSEWINDOW win
RETURN 0
ENDSUB

SUB MyWin::WinProc()
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW win
/* Initialize any controls here */
OnCreate()
CASE @IDCLOSEWINDOW
OnDestroy()
ENDSELECT
RETURN
ENDSUB

' -----------------------------------------------------------
' EXAMPLE

MyWin w
w.Init("MyWin example", 400, 300, 0, @CAPTION|@SYSMENU)

w.Run()
END


LarryMc

I had similar problems a couple of years ago.
Look at this topic and see if it helps.

http://www.ionicwind.com/forums/index.php/topic,1853.msg17167.html#msg17167

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

fasecero

The "COpenWindow" class developed by Sapero seems to be the base of the solution, thanks for the help, Larry :)

fasecero

With these changes I get what I wanted  8)



' -----------------------------------------------------------
' win - base
' -----------------------------------------------------------

' declarations
declare import, SetPropA(hwnd as uint,name as string,prop as uint),uint
declare import, GetPropA(hwnd as uint,name as string),uint
declare import, RemovePropA(hwnd as uint,name as string),int

CONST TIMER_START = 32145

' mywin basic class
CLASS MYWIN
DECLARE Init(STRING caption, INT width, INT height, pointer parent, int style)
DECLARE Run()
DECLARE Finish()

DECLARE VIRTUAL OnCreate()
DECLARE VIRTUAL OnDestroy()

' members
window win
ENDCLASS

SUB MYWIN::Init(STRING caption, INT width, INT height, pointer parent, int style)
OPENWINDOW win,0,0,width,height,style,parent,caption,&WinProc
SetPropA(win.hwnd, "instance_", this)
ENDSUB

SUB MYWIN::Run(), INT
WAITUNTIL win=0
ENDSUB

SUB MYWIN::Finish(), INT
RemovePropA(win.hwnd, "instance_")
CLOSEWINDOW win
ENDSUB

SUB MYWIN::OnCreate()
MESSAGEBOX win, "Base Class Init", "MyWin"
ENDSUB

SUB MYWIN::OnDestroy()
MESSAGEBOX win, "Base Class Finish", "MyWin"
Finish()
ENDSUB

' win procedure
SUB WinProc
uint this_ : this_=0
INT hwnd : hwnd=*<window>@hitwindow.hwnd
this_ = GetPropA(hwnd, "instance_")

SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW *<window>@hitwindow
STARTTIMER(*<window>@hitwindow, 10, TIMER_START)
CASE @IDTIMER
SELECT @WPARAM
CASE TIMER_START
IF this_ THEN STOPTIMER *<window>@hitwindow, TIMER_START : *<MYWIN>this_.OnCreate()
ENDSELECT
CASE @IDCLOSEWINDOW
IF this_ THEN *<MYWIN>this_.OnDestroy()
ENDSELECT
RETURN 0
ENDSUB

' -----------------------------------------------------------
' example
' -----------------------------------------------------------
CLASS DMYWIN, MYWIN
DECLARE VIRTUAL OnCreate()
DECLARE VIRTUAL OnDestroy()
ENDCLASS

SUB DMYWIN::OnCreate()
MYWIN::OnCreate() ' call the base method
MESSAGEBOX win, "Derived Class Init", "MyWin"
ENDSUB

SUB DMYWIN::OnDestroy()
MESSAGEBOX win, "Derived Class Finish", "MyWin"
MYWIN::OnDestroy() ' call the base method
ENDSUB

' main
DMYWIN w

w.Init("MYWIN example", 400, 300, 0, @CAPTION|@SYSMENU)
w.Run()
END


aurelCB

That is very very interesting...

fasecero

July 13, 2009, 12:39:13 PM #5 Last Edit: July 13, 2009, 12:41:08 PM by fasecero
:) my intention is to have a base class that gives to a each event (create, destroy, size, etc) a default behavior. Then when to make a window, I only need to modify the events that need to have a different behavior. I think it is something similar to the Aurora mode.

aurelCB

Yeah i know that this topic is old but i have question....

Do i can on similiar way produce more windows?