Re: Dialog wanders when shown repeatedly
- Posted by CChris <christian.cuvier at agricu?ture.gou?.fr> Jan 28, 2008
- 636 views
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