1. Dialog wanders when shown repeatedly

Hello ;D  I'm trying to get into programming again after a very long hiatus,
and am running into a problem too simple to wrap my head around XD

I've defined two windows with the create() function; one of which is intended
to be the main window, and the other will be called in a button-click handler
as the need arises.  Depending on the button clicked, setText is used to give
this secondary window the appropriate title (works OK), and a text label is
created to 

My code looks like this:

include win32lib.ew
without warning

--Main program window
constant MainWin = create(Window, "etS beta 0.0", 0, Default, Default, 100, 100,
{WS_DLGFRAME, WS_SYSMENU, WS_MINIMIZEBOX})
--Secondary message window/dialogue
constant MsgWin = create(Window, "", MainWin, 200, 200, 100, 100, {WS_DLGFRAME,
WS_SYSMENU})

--Button click handler
procedure ButClick(integer self, integer event, sequence parms)
	atom hTemp

	if self=hHistBut then
		setClientRect(MsgWin, 150, 150)
		setText(MsgWin, "History..")
		hTemp = create(CText, "Blahblahblah", MsgWin, 0, 0, 150, 150, 0)
		openDialog(MsgWin)
	elsif self=hAboutBut then
		setClientRect(MsgWin, 150, 150)
		setText(MsgWin, "About")
		hTemp = create(CText, "Blarghblargh", MsgWin, 0, 0, 150, 150, 0)
		openDialog(MsgWin)
	end if

end procedure

global procedure IntroScreen()
	atom hSplash, hTrim

hSplash = create(Bitmap, ImageSource & "starmap.bmp", MainWin, 0, 0, 668, 546,
0)
hTrim = create(Bitmap, ImageSource & "startrim.bmp", MainWin, 668, 0, 60, 486,
0)
hStoryBut = create(PictureButton, {"", "History"}, MainWin, 668, 486, 60, 30,
ImageSource & "storybut.bmp")
hAboutBut = create(PictureButton, {"", "About"}, MainWin, 668, 516, 60, 30,
ImageSource & "aboutbut.bmp")
	setHandler({hHistBut, hAboutBut}, w32HClick, routine_id("ButClick"))
	setFocus(hStoryBut)
end procedure

global procedure main()
	setClientRect(MainWin, 728, 546)
	IntroScreen()
end procedure

new topic     » topic index » view message » categorize

2. Dialog wanders when shown repeatedly

--Great first posting, huh?  Didn't mean to hit Send Now, previously.  Sorry
for the incomplete post + double posting :(

Hello ;D  I'm trying to get into programming again after a very long hiatus,
and am running into a problem too simple to wrap my head around XD

I've defined two windows with the create() function; one of which is intended
to be the main window, and the other will be called in a button-click handler
as the need arises.  Depending on the button clicked, setText is used to give
this secondary window the appropriate title (works OK), and a text label is
created to show whatever text is appropriate (works OK).  But, this window
doesn't appear in a consistant (x,y) location relative to the screen corners
or the primary window, and appears farther up (and usually, but not always,
farther to the left) relative to its prior position every time it's shown
after the first time it's displayed during a program run.

My code looks like this:

include win32lib.ew
without warning

--Main program window
constant MainWin = create(Window, "etS beta 0.0", 0, Default, Default, 100, 100,
{WS_DLGFRAME, WS_SYSMENU, WS_MINIMIZEBOX})
--Secondary message window/dialogue
constant MsgWin = create(Window, "", MainWin, 200, 200, 100, 100, {WS_DLGFRAME,
WS_SYSMENU})

--Button click handler
procedure ButClick(integer self, integer event, sequence parms)
	atom hTemp

	if self=hHistBut then
		setClientRect(MsgWin, 150, 150)
		setText(MsgWin, "History..")
		hTemp = create(CText, "Blahblahblah", MsgWin, 0, 0, 150, 150, 0)
		openDialog(MsgWin)
	elsif self=hAboutBut then
		setClientRect(MsgWin, 150, 150)
		setText(MsgWin, "About")
		hTemp = create(CText, "Blarghblargh", MsgWin, 0, 0, 150, 150, 0)
		openDialog(MsgWin)
	end if

        destroy(hTemp)
end procedure

global procedure IntroScreen()
	atom hSplash, hTrim

hSplash = create(Bitmap, ImageSource & "starmap.bmp", MainWin, 0, 0, 668, 546,
0)
hTrim = create(Bitmap, ImageSource & "startrim.bmp", MainWin, 668, 0, 60, 486,
0)
hStoryBut = create(PictureButton, {"", "History"}, MainWin, 668, 486, 60, 30,
ImageSource & "storybut.bmp")
hAboutBut = create(PictureButton, {"", "About"}, MainWin, 668, 516, 60, 30,
ImageSource & "aboutbut.bmp")
	setHandler({hHistBut, hAboutBut}, w32HClick, routine_id("ButClick"))
	setFocus(hStoryBut)
end procedure

global procedure main()
	setClientRect(MainWin, 728, 546)
	IntroScreen()
end procedure

new topic     » goto parent     » topic index » view message » categorize

3. Re: Dialog wanders when shown repeatedly

Tony Bohm wrote:
> 
> --Great first posting, huh?  Didn't mean to hit Send Now, previously.  Sorry
> for the incomplete post + double posting :(
> 
> Hello ;D  I'm trying to get into programming again after a very long hiatus,
> and am running into a problem too simple to wrap my head around XD
> 
> I've defined two windows with the create() function; one of which is intended
> to be the main window, and the other will be called in a button-click handler
> as the need arises.  Depending on the button clicked, setText is used to give
> this secondary window the appropriate title (works OK), and a text label is
> created to show whatever text is appropriate (works OK).  But, this window
> doesn't appear in a consistant (x,y) location relative to the screen corners
> or the primary window, and appears farther up (and usually, but not always,
> farther to the left) relative to its prior position every time it's shown
> after the first time it's displayed during a program run.
> 
> My code looks like this:
> 
> include win32lib.ew
> without warning
> 
> --Main program window
> constant MainWin = create(Window, "etS beta 0.0", 0, Default, Default, 100,
> 100, {WS_DLGFRAME, WS_SYSMENU, WS_MINIMIZEBOX})
> --Secondary message window/dialogue
> constant MsgWin = create(Window, "", MainWin, 200, 200, 100, 100,
> {WS_DLGFRAME,
> WS_SYSMENU})
> 
> --Button click handler
> procedure ButClick(integer self, integer event, sequence parms)
> 	atom hTemp
> 
> 	if self=hHistBut then
> 		setClientRect(MsgWin, 150, 150)
> 		setText(MsgWin, "History..")
> 		hTemp = create(CText, "Blahblahblah", MsgWin, 0, 0, 150, 150, 0)
> 		openDialog(MsgWin)
> 	elsif self=hAboutBut then
> 		setClientRect(MsgWin, 150, 150)
> 		setText(MsgWin, "About")
> 		hTemp = create(CText, "Blarghblargh", MsgWin, 0, 0, 150, 150, 0)
> 		openDialog(MsgWin)
> 	end if
> 
>         destroy(hTemp)
> end procedure
> 
> global procedure IntroScreen()
> 	atom hSplash, hTrim
> 
> 	hSplash = create(Bitmap, ImageSource & "starmap.bmp", MainWin, 0, 0, 668,
> 546, 0)
> 	hTrim = create(Bitmap, ImageSource & "startrim.bmp", MainWin, 668, 0, 60,
> 486, 0)
> 	hStoryBut = create(PictureButton, {"", "History"}, MainWin, 668, 486, 60, 30,
> ImageSource & "storybut.bmp")
> 	hAboutBut = create(PictureButton, {"", "About"}, MainWin, 668, 516, 60, 30,
> ImageSource
> & "aboutbut.bmp")
> 	setHandler({hHistBut, hAboutBut}, w32HClick, routine_id("ButClick"))
> 	setFocus(hStoryBut)
> end procedure
> 
> global procedure main()
> 	setClientRect(MainWin, 728, 546)
> 	IntroScreen()
> end procedure

Problem confirmed. This appears to be a very old bug.
Around line 19063 in win32lib.ew, find this line
posn = getPosition( id )

and change it to read
posn =
        getWindowInfo(id,{{WINDOWINFO_CRect,rectLeft},{WINDOWINFO_CRect,rectTop}})

The call to setClientRect() are redundant, but shouldn't cause the effect you
just reported. Fix will be in 70.4.

CChris

new topic     » goto parent     » topic index » view message » categorize

4. Re: Dialog wanders when shown repeatedly

Thank you!

The dialog now moves straight down in increments of 29 pixels XD  It stays in
place with setClientRect remarked, so that is doing something unexpected.

I've got the result I was seeking using setRect, though ;D

I notice that the create() documentation states that the x,y coordinates
specified in the create() parameters are in relation to the parent window client
area, but MsgWin appears relative to the top-left of the screen even with MainWin
specified as its parent, if I remark the setClientRect and do not use setRect. 
Is this expected, or is there a problem/misunderstanding in my use of create()?

Thanks for the help and for all the work on the library; I probably wouldn't
have touched programming again without it!

new topic     » goto parent     » topic index » view message » categorize

5. Re: Dialog wanders when shown repeatedly

Tony Bohm wrote:
> 
> Thank you!
> 
> The dialog now moves straight down in increments of 29 pixels XD  It stays in
> place with setClientRect remarked, so that is doing something unexpected.
> 
> I've got the result I was seeking using setRect, though ;D
> 
> I notice that the create() documentation states that the x,y coordinates
> specified
> in the create() parameters are in relation to the parent window client area,
> but MsgWin appears relative to the top-left of the screen even with MainWin
> specified as its parent, if I remark the setClientRect and do not use setRect.
>  Is this expected, or is there a problem/misunderstanding in my use of
>  create()?
> 
> Thanks for the help and for all the work on the library; I probably wouldn't
> have touched programming again without it!

I don't think so. The fix I provided you with has other unwelcome side effects,
so I have to figure this out. I don't think your understanding of create() is at
stake, it's just that you used a combination of things that obviously had never
been tested. I'll post later when I get a consistent behaviour.

CChris

new topic     » goto parent     » topic index » view message » categorize

6. Re: Dialog wanders when shown repeatedly

Tony Bohm wrote:
> 
> Thank you!
> 
> The dialog now moves straight down in increments of 29 pixels XD  It stays in
> place with setClientRect remarked, so that is doing something unexpected.
> 
> I've got the result I was seeking using setRect, though ;D
> 
> I notice that the create() documentation states that the x,y coordinates
> specified
> in the create() parameters are in relation to the parent window client area,
> but MsgWin appears relative to the top-left of the screen even with MainWin
> specified as its parent, if I remark the setClientRect and do not use setRect.
>  Is this expected, or is there a problem/misunderstanding in my use of
>  create()?
> 

As I mentioned earlier, the problm is with setCtlSize(), which setClientRect()
calls. The former routineperforms one client area correction too many, resulting
in the problem you report.
In setCtlSize(), locate the line hat says
posn = getPosition( id )

(close to line 19063) and replace it like this
oldBmp=w32acquire_mem(0,16)
        if not w32Func(xGetWindowRect,{getHandle(id),oldBmp}) then ?
            warnErr(Err_GRGETWINDRECT)
        end if
        posn=peek4u({oldBmp,4})
        w32release_mem(oldBmp)

This way, the dialog opens at the same place it was closed.
Anyway, you didn't need the calls to setClientRect(), since the "child" window
doesn't change size.

CChris
> Thanks for the help and for all the work on the library; I probably wouldn't
> have touched programming again without it!

new topic     » goto parent     » topic index » view message » categorize

7. Re: Dialog wanders when shown repeatedly

Tony Bohm wrote:
> 
> --Great first posting, huh?  Didn't mean to hit Send Now, previously.  Sorry
> for the incomplete post + double posting :(
> 
> Hello ;D  I'm trying to get into programming again after a very long hiatus,
> and am running into a problem too simple to wrap my head around XD
> 
> I've defined two windows with the create() function; one of which is intended
> to be the main window, and the other will be called in a button-click handler
> as the need arises.  Depending on the button clicked, setText is used to give
> this secondary window the appropriate title (works OK), and a text label is
> created to show whatever text is appropriate (works OK).  But, this window
> doesn't appear in a consistant (x,y) location relative to the screen corners
> or the primary window, and appears farther up (and usually, but not always,
> farther to the left) relative to its prior position every time it's shown
> after the first time it's displayed during a program run.
> 
> My code looks like this:
> 
> include win32lib.ew
> without warning
> 
> --Main program window
> constant MainWin = create(Window, "etS beta 0.0", 0, Default, Default, 100,
> 100, {WS_DLGFRAME, WS_SYSMENU, WS_MINIMIZEBOX})
> --Secondary message window/dialogue
> constant MsgWin = create(Window, "", MainWin, 200, 200, 100, 100,
> {WS_DLGFRAME,
> WS_SYSMENU})
> 
> --Button click handler
> procedure ButClick(integer self, integer event, sequence parms)
> 	atom hTemp
> 
> 	if self=hHistBut then
> 		setClientRect(MsgWin, 150, 150)
> 		setText(MsgWin, "History..")
> 		hTemp = create(CText, "Blahblahblah", MsgWin, 0, 0, 150, 150, 0)
> 		openDialog(MsgWin)
> 	elsif self=hAboutBut then
> 		setClientRect(MsgWin, 150, 150)
> 		setText(MsgWin, "About")
> 		hTemp = create(CText, "Blarghblargh", MsgWin, 0, 0, 150, 150, 0)
> 		openDialog(MsgWin)
> 	end if
> 
>         destroy(hTemp)
> end procedure
> 
> global procedure IntroScreen()
> 	atom hSplash, hTrim
> 
> 	hSplash = create(Bitmap, ImageSource & "starmap.bmp", MainWin, 0, 0, 668,
> 546, 0)
> 	hTrim = create(Bitmap, ImageSource & "startrim.bmp", MainWin, 668, 0, 60,
> 486, 0)
> 	hStoryBut = create(PictureButton, {"", "History"}, MainWin, 668, 486, 60, 30,
> ImageSource & "storybut.bmp")
> 	hAboutBut = create(PictureButton, {"", "About"}, MainWin, 668, 516, 60, 30,
> ImageSource
> & "aboutbut.bmp")
> 	setHandler({hHistBut, hAboutBut}, w32HClick, routine_id("ButClick"))
> 	setFocus(hStoryBut)
> end procedure
> 
> global procedure main()
> 	setClientRect(MainWin, 728, 546)
> 	IntroScreen()
> end procedure

Actually, the problem was not in the library, but in your code. The following
does work properly (I had to simplify it a little):
include win32lib.ew
without warning

--Main program window
constant MainWin = create(Window, "etS beta 0.0", 0, Default, Default, 100,
100, {WS_DLGFRAME, WS_SYSMENU, WS_MINIMIZEBOX})
--Secondary message window/dialogue
constant MsgWin = create(Window, "", MainWin, 200, 200, 100, 100,
{WS_DLGFRAME,WS_SYSMENU,
-- NOTE THIS
WS_CAPTION,WS_CHILD})

--Button click handler
procedure ButClick(integer self, integer event, sequence parms)
	atom hTemp

		setClientRect(MsgWin, 150, 150)
		setText(MsgWin, "History..")
		hTemp = create(CText, "Blahblahblah", MsgWin, 0, 0, 150, 150, 0)
		openDialog(MsgWin)

        destroy(hTemp)
end procedure
atom hStoryBut
	hStoryBut = create(PushButton, {"", "History"}, MainWin, 168, 186, 60, 30,0)
	setHandler(hStoryBut, w32HClick, routine_id("ButClick"))
	setFocus(hStoryBut)

global procedure main()
	setClientRect(MainWin, 728, 546)
end procedure
main()
WinMain(MainWin,Normal)


create() sets the position of the owned window in terms of the parent window,
but *does not track it afterwards*. For the tracking to take place, you need to
specify the WS_CHILD style, which has a few consequences, some of which are not
always desirable.

Having controls that resize or reposition dynamically according to rules fixed
at creation time is on the to-do list for win32lib, but not for next release.

CChris

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu