1. better example
- Posted by jordah ferguson <jorfergie03 at yahoo.com> Jun 13, 2002
- 571 views
--** This is a modification of ex01.exw in win32lib package without warning include win32lib.ew constant SimpleWin = create( Window, "Simple Window", 0, 0, 0, 200, 100, 0 ), menu = create(Menu,"File",SimpleWin,0,0,0,0,0), menu1 = create(MenuItem,"New",menu,0,0,0,0,0), menu2 = create(MenuItem,"Old",menu,0,0,0,0,0) constant zCheckMenuRadioItem = registerw32Function(user32,"CheckMenuRadioItem",{C_LONG, C_UINT, C_UINT, C_UINT, C_UINT}, C_USHORT), MFT_RADIOCHECK = 512, MFS_CHECKED = 8 procedure setMenuRadio(integer start,integer last,integer current) atom retval,mask mask = or_all({MFS_CHECKED,MFT_RADIOCHECK}) retval = w32Func(zCheckMenuRadioItem,{getHandle(current),start,last,current,mask}) end procedure constant zSetMenuItemInfo=registerw32Function(user32,"SetMenuItemInfoA",{C_LONG, C_UINT, C_SHORT, C_POINTER}, C_USHORT) global procedure setMenuBitmap(integer item,object bit1) integer bool atom MENUITEMINFO MENUITEMINFO = acquire_mem(0,48) mem_set(MENUITEMINFO,0,48) if sequence(bit1) then bit1 = loadBitmapFromFile(bit1) end if poke4(MENUITEMINFO+0,48) poke4(MENUITEMINFO+4,#80) --MIIM_BITMAP poke4(MENUITEMINFO+44,bit1) bool = w32Func(zSetMenuItemInfo,{getHandle(item),item,0,MENUITEMINFO}) bool = w32Func(xDrawMenuBar,{getHandle(item)}) release_mem(MENUITEMINFO) end procedure setMenuRadio(menu1,menu2,menu1) setMenuBitmap(menu2,"c:\\full\\conn1.bmp") procedure w32HClick_menu1(integer self,integer event,sequence params) setMenuRadio(menu1,menu2,menu1) end procedure setHandler(menu1,w32HClick,routine_id("w32HClick_menu1")) procedure w32HClick_menu2(integer self,integer event,sequence params) setMenuRadio(menu1,menu2,menu2) end procedure setHandler(menu2,w32HClick,routine_id("w32HClick_menu2")) WinMain( SimpleWin, Normal)
2. Re: better example
- Posted by Wolf <wolfritz at KING.IGS.NET> Jun 14, 2002
- 525 views
Hey, Jordah, I answered this on the 8'th already, but here goes again... < quoting <snipped> from your example > constant SimpleWin = create( Window, "Simple Window", 0, 0, 0, 300, 100, 0 ), menu = create(Menu,"File",SimpleWin,0,0,0,0,0), menu1 = create(MenuItem,"New",menu,0,0,0,0,0), menu2 = create(MenuItem,"Old",menu,0,0,0,0,0), -- added ! menu3 = create(MenuItem,"Check First Item",menu,0,0,0,0,0) -- new stuff ! -- crude, but ... constant MIIM_STATE = 1, zGetMenuItemInfo=registerw32Function(user32,"GetMenuItemInfoA",{C_INT, C_INT, C_INT, C_INT}, C_INT) function isMenuRadioed(atom hMenu,atom uItem,integer fByPosition) atom MENUITEMINFO,junk,out MENUITEMINFO = acquire_mem(0,48) mem_set(MENUITEMINFO,0,48) poke4(MENUITEMINFO+0,48) poke4(MENUITEMINFO+4,MIIM_STATE) junk=w32Func(zGetMenuItemInfo,{hMenu,uItem,fByPosition,MENUITEMINFO}) if junk then out = and_bits(peek4u(MENUITEMINFO+12),MFS_CHECKED) else -- crash_error! end if release_mem(MENUITEMINFO) return out end function procedure w32HClick_menu3(integer self,integer event,sequence params) --check item zero/by position if isMenuRadioed(getHandle(menu),0,1) then setText(SimpleWin," YES") else setText(SimpleWin," NO") end if end procedure setHandler(menu3,w32HClick,routine_id("w32HClick_menu3")) Now, for a 'philosophical' question, to one and all. Since your nice example proves that it's rather easy to add all this functionality to a win32lib program *without* adding it to the win32lib core, do we really need them 'included' ? "Win32lib created" programs that actually use "bitmapped" menu's, and "radio's", will probably be quite rare, in most cases. Things will be different, of course, when Derek 'breaks' win32lib into smaller bits, but for now.... ??? Wolf
3. Re: better example
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 15, 2002
- 551 views
Thanks Wolf for answering this, however I'd like to suggest that one might use the stuff that is already built into the library. Here is my example based on yours... -------------------- include win32lib.ew constant SimpleWin = create( Window, "Simple Window", 0, 0, 0, 300, 100, 0 ), menu = create(Menu,"File",SimpleWin,0,0,0,0,0), menu1 = create(MenuItem,"New",menu,0,0,0,0,0), menu2 = create(MenuItem,"Old",menu,0,0,0,0,0), menu3 = create(MenuItem,"Check First Item",menu,0,0,0,0,0) procedure w32HClick_menu3(integer self,integer event,sequence params) integer curval curval = isChecked(menu1) setText(SimpleWin, "The first menuitem is " & iff(curval, "", "NOT") & "checked.") setCheck(menu1, not curval) end procedure setHandler(menu3,w32HClick,routine_id("w32HClick_menu3")) WinMain(SimpleWin, Normal) ------------------ Derek. ----- Original Message ----- From: "Wolf" <wolfritz at KING.IGS.NET> To: "EUforum" <EUforum at topica.com> Sent: Saturday, June 15, 2002 1:00 AM Subject: Re: better example > > Hey, Jordah, I answered this on the 8'th already, but here goes again... > < quoting <snipped> from your example > > > constant SimpleWin = create( Window, "Simple Window", 0, 0, 0, 300, > 100, 0 ), > menu = create(Menu,"File",SimpleWin,0,0,0,0,0), > menu1 = create(MenuItem,"New",menu,0,0,0,0,0), > menu2 = create(MenuItem,"Old",menu,0,0,0,0,0), > -- added ! > menu3 = create(MenuItem,"Check First Item",menu,0,0,0,0,0) > > -- new stuff ! -- crude, but ... > constant > MIIM_STATE = 1, > zGetMenuItemInfo=registerw32Function(user32,"GetMenuItemInfoA",{C_INT, > C_INT, C_INT, C_INT}, C_INT) > > function isMenuRadioed(atom hMenu,atom uItem,integer fByPosition) > atom MENUITEMINFO,junk,out > MENUITEMINFO = acquire_mem(0,48) > mem_set(MENUITEMINFO,0,48) > poke4(MENUITEMINFO+0,48) > poke4(MENUITEMINFO+4,MIIM_STATE) > junk=w32Func(zGetMenuItemInfo,{hMenu,uItem,fByPosition,MENUITEMINFO}) > if junk then > out = and_bits(peek4u(MENUITEMINFO+12),MFS_CHECKED) > else -- crash_error! > end if > release_mem(MENUITEMINFO) > return out > end function > > procedure w32HClick_menu3(integer self,integer event,sequence params) > --check item zero/by position > if isMenuRadioed(getHandle(menu),0,1) then > setText(SimpleWin," YES") else setText(SimpleWin," NO") > end if > end procedure > setHandler(menu3,w32HClick,routine_id("w32HClick_menu3")) > > Now, for a 'philosophical' question, to one and all. > Since your nice example proves that it's rather easy to add all this functionality to a win32lib program *without* > adding it to the win32lib core, do we really need them 'included' ? > "Win32lib created" programs that actually use "bitmapped" menu's, and "radio's", will probably be quite rare, in most > cases. > Things will be different, of course, when Derek 'breaks' win32lib into smaller bits, but for now.... ??? > > Wolf > > > >
4. Re: better example
- Posted by Dan Moyer <DANIELMOYER at prodigy.net> Jun 15, 2002
- 501 views
Derek, Interesting! I'd never noticed that "iff" hiding in tk_misc.e! --/func iff (atom test, object ifTrue, object ifFalse) --/desc Used to embed an 'if' test inside an expression. --/ret If /i test is /b true then /i ifTrue is returned otherwise /i ifFalse is returned. But you've used it too soon in your code :) See correction below. Or, alternatively, you could leave the "iff" as it is and delete : > setCheck(menu1, not curval) from where it is, and add: setCheck(menu1, not curval) curval = isChecked(menu1) just below the current: curval = isChecked(menu1) Dan Moyer ----- Original Message ----- From: "Derek Parnell" <ddparnell at bigpond.com> To: "EUforum" <EUforum at topica.com> Sent: Saturday, June 15, 2002 9:50 AM Subject: Re: better example > > Thanks Wolf for answering this, however I'd like to suggest that one might > use the stuff that is already built into the library. Here is my example > based on yours... > > -------------------- > include win32lib.ew > > constant SimpleWin = create( Window, "Simple Window", 0, 0, 0, 300, > 100, 0 ), > menu = create(Menu,"File",SimpleWin,0,0,0,0,0), > menu1 = create(MenuItem,"New",menu,0,0,0,0,0), > menu2 = create(MenuItem,"Old",menu,0,0,0,0,0), > menu3 = create(MenuItem,"Check First Item",menu,0,0,0,0,0) > > > procedure w32HClick_menu3(integer self,integer event,sequence params) > integer curval > curval = isChecked(menu1) -- SHOULD BE THIS: setText(SimpleWin, "The first menuitem is " & iff(curval, "NOT checked.","checked.")) -- NOT THIS: --> setText(SimpleWin, "The first menuitem is " & --> iff(curval, "", "NOT") & --> "checked.") > setCheck(menu1, not curval) > > end procedure > setHandler(menu3,w32HClick,routine_id("w32HClick_menu3")) > > WinMain(SimpleWin, Normal) > ------------------ > Derek. > > ----- Original Message ----- > From: "Wolf" <wolfritz at KING.IGS.NET> > To: "EUforum" <EUforum at topica.com> > Sent: Saturday, June 15, 2002 1:00 AM > Subject: Re: better example > > > > > > Hey, Jordah, I answered this on the 8'th already, but here goes again... > > < quoting <snipped> from your example > > > > > constant SimpleWin = create( Window, "Simple Window", 0, 0, 0, 300, > > 100, 0 ), > > menu = create(Menu,"File",SimpleWin,0,0,0,0,0), > > menu1 = create(MenuItem,"New",menu,0,0,0,0,0), > > menu2 = create(MenuItem,"Old",menu,0,0,0,0,0), > > -- added ! > > menu3 = create(MenuItem,"Check First Item",menu,0,0,0,0,0) > > > > -- new stuff ! -- crude, but ... > > constant > > MIIM_STATE = 1, > > zGetMenuItemInfo=registerw32Function(user32,"GetMenuItemInfoA",{C_INT, > > C_INT, C_INT, C_INT}, C_INT) > > > > function isMenuRadioed(atom hMenu,atom uItem,integer fByPosition) > > atom MENUITEMINFO,junk,out > > MENUITEMINFO = acquire_mem(0,48) > > mem_set(MENUITEMINFO,0,48) > > poke4(MENUITEMINFO+0,48) > > poke4(MENUITEMINFO+4,MIIM_STATE) > > junk=w32Func(zGetMenuItemInfo,{hMenu,uItem,fByPosition,MENUITEMINFO}) > > if junk then > > out = and_bits(peek4u(MENUITEMINFO+12),MFS_CHECKED) > > else -- crash_error! > > end if > > release_mem(MENUITEMINFO) > > return out > > end function > > > > procedure w32HClick_menu3(integer self,integer event,sequence params) > > --check item zero/by position > > if isMenuRadioed(getHandle(menu),0,1) then > > setText(SimpleWin," YES") else setText(SimpleWin," NO") > > end if > > end procedure > > setHandler(menu3,w32HClick,routine_id("w32HClick_menu3")) > > > > Now, for a 'philosophical' question, to one and all. > > Since your nice example proves that it's rather easy to add all this > functionality to a win32lib program *without* > > adding it to the win32lib core, do we really need them 'included' ? > > "Win32lib created" programs that actually use "bitmapped" menu's, and > "radio's", will probably be quite rare, in most > > cases. > > Things will be different, of course, when Derek 'breaks' win32lib into > smaller bits, but for now.... ??? > > > > Wolf > > > > > > > > >
5. Re: better example
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 15, 2002
- 497 views
Hi Dan, my example is not wrong and neither is yours. It all depends on what one is trying to do. In my code, I was trying to display the state of the menu item at the time it was examined. In your code, you are displaying the state of the menu item after it has been changed. I could have made my code more obvious if I had written ... setText(SimpleWin, "The first menuitem was " & iff(curval, "", "NOT") & "checked.") Once again, we are stung by poor user requirement specification----------- Derek.