D - Design Question
- Charles Sanders (27/27) Nov 15 2003 Hey all,
- Andy Friesen (21/47) Nov 16 2003 dfbth (Yet Another Windowing Toolkit coded in D) has an abstract
- Ben Hinkle (5/6) Nov 16 2003 speaking of which, is there a standard Dism for "C++ long" when writing ...
- Andy Friesen (6/14) Nov 16 2003 You could use the std.stdint module if you want a specific number of
- Charles Sanders (16/68) Nov 16 2003 Yes its in the DLL (
- Charles Sanders (8/55) Nov 16 2003 from
- Charles Sanders (13/80) Nov 16 2003 What attached menu ? The only paramater that comes with the WM_COMMAMD
- J C Calvarese (5/18) Nov 16 2003 It looks like Andy posts all of his cool stuff at:
- Andy Friesen (27/36) Nov 16 2003 I haven't gotten to implementing menus in dfbth just yet. But,
Hey all, Im running into some trouble implementing Windy , a GUI kit for windows. The problem arises when handling the WM_COMMAND messages originating from Menu's. The event handling now is to associate a HWND with a Wnd class, and have the Wnd class process the message with its own internal map of messages and event handlers. But the WM_COMMAND generated by menu's doesnt contain a HWND to a Window, so I cant get a Wnd class to handle the message. There are two ways I can handle this, I can associate a MENUINFO structure with the menu, which will change the generated messages to WM_MENUCOMMAND, with that I can call GetMenuInfo, and I can assocaite a HWND with a menu this way, and leave the message handling system consistent OR I can add a function [ addMenuHandler ] ( on top of the existing addHandler ) , and just keep the menu message handlers in a global map. This will be faster, but requires the user to memorize another function, which could easily cause trouble for users of the lib. I hate these design / perfornace tradeoff choices, and would like your opinions on what you think is best. Also the USER32.lib that comes with the Digital Mars CD doesnt have SetMenuInfo function in it, I tried implib /system USER32.lib USER32.dll But it still doesnt contain the _function 16 format that is required ( I learned finally that the last number is the total size of the parameters being passed ). Does anyone have a valid USER32.lib ? Walter can you update the libs that come with the CD ? Charles
Nov 15 2003
Charles Sanders wrote:Hey all, Im running into some trouble implementing Windy , a GUI kit for windows. The problem arises when handling the WM_COMMAND messages originating from Menu's. The event handling now is to associate a HWND with a Wnd class, and have the Wnd class process the message with its own internal map of messages and event handlers. But the WM_COMMAND generated by menu's doesnt contain a HWND to a Window, so I cant get a Wnd class to handle the message.dfbth (Yet Another Windowing Toolkit coded in D) has an abstract handleCommand method in the base Control class. Control.WndProc relays the command here. CompositeCommand overrides and looks for an applicable child, and relays it yet again. Other subclasses do interesting things depending on what they are. (Button just fires its onClick signal, et cetera) I hate to blow my own horn, but it works really well. :) You could first check the attached menu and see if it will handle the command. If not, fall back on whatever the superclass does.There are two ways I can handle this, I can associate a MENUINFO structure with the menu, which will change the generated messages to WM_MENUCOMMAND, with that I can call GetMenuInfo, and I can assocaite a HWND with a menu this way, and leave the message handling system consistentInternally allocate unique command IDs to menu items. Then you don't need any weird hacks.OR I can add a function [ addMenuHandler ] ( on top of the existing addHandler ) , and just keep the menu message handlers in a global map. This will be faster, but requires the user to memorize another function, which could easily cause trouble for users of the lib. I hate these design / perfornace tradeoff choices, and would like your opinions on what you think is best.Performance isn't really critical in this sort of thing. Nobody's selecting menu items three billion times per second, and, if your dispatching code really does cause a noticible delay, then you're doing something very, very wrong. Do whatever's easier to implement and use, and forget speed until you have proof that it's not up to par.Also the USER32.lib that comes with the Digital Mars CD doesnt have SetMenuInfo function in it, I tried implib /system USER32.lib USER32.dllIf it's not in the resultant lib, then I would believe that it's not in the DLL either. Are you sure you're translating the parameter types properly? (C++ long is still only 32 bits on x86) -- andy
Nov 16 2003
(C++ long is still only 32 bits on x86)speaking of which, is there a standard Dism for "C++ long" when writing the interface to a C/C++ library? I made a typdef gmp_long when translating gmp.h to gmp.d thanks, -Ben
Nov 16 2003
Ben Hinkle wrote:You could use the std.stdint module if you want a specific number of bits. Failing that, I would use an alias instead of a typedef. Typedefs like that tend to cause many a cast to be required later on. Personally, I would just call it an int and be done with it. :) -- andy(C++ long is still only 32 bits on x86)speaking of which, is there a standard Dism for "C++ long" when writing the interface to a C/C++ library? I made a typdef gmp_long when translating gmp.h to gmp.d thanks, -Ben
Nov 16 2003
"Andy Friesen" <andy ikagames.com> wrote in message news:bp88h1$15ja$1 digitaldaemon.com...Ben Hinkle wrote:thespeaking of which, is there a standard Dism for "C++ long" when writingSo would I <g>.interface to a C/C++ library? I made a typdef gmp_long when translating gmp.h to gmp.dPersonally, I would just call it an int and be done with it. :)
Nov 18 2003
"Walter" <walter digitalmars.com> wrote in message news:bpet6l$1r31$1 digitaldaemon.com..."Andy Friesen" <andy ikagames.com> wrote in message news:bp88h1$15ja$1 digitaldaemon.com...writingBen Hinkle wrote:speaking of which, is there a standard Dism for "C++ long" whenthetranslatinginterface to a C/C++ library? I made a typdef gmp_long whenI'm dipping in here without having read the previous postings in the thread (newsreader "issues"), but I think this is a bad move. When porting from an external API, you centralise all the type translations in one place if you define and use the requisite types in the D form. For example, in the D mapping of recls - which will be in D std lib from 0.76 onwards - I use the type recls_rc_t (the return type), rather than int, since it may conceivably change in recls at some point, and I don't want to have to go around the D mapping guessing which int is a return code, and which is just an int. Frankly, I'm surprised to hear counter opinions. This is integration lesson 1. Or am I missing something?So would I <g>.gmp.h to gmp.dPersonally, I would just call it an int and be done with it. :)
Nov 18 2003
"Matthew Wilson" <matthew-hat -stlsoft-dot.-org> wrote in message news:bpf1c5$21id$1 digitaldaemon.com...Frankly, I'm surprised to hear counter opinions. This is integrationlesson1. Or am I missing something?I'm not a very orthodox programmer. I tend to use far fewer typedefs than others, usually only for either 1) documentation purposes or if 2) I *know* it will change, rather than worry that it might. The reason for (2) is my experience migrating from the 16 bit world to 32 bits. 16 bit programmers would really load up their code with typedef's for portability reasons, and yet when the code was ported to 32 bits it still broke all over the place and was just as much trouble to fix as code with no typedefs at all. The trouble comes from subtle dependencies on the type of a typedef creeping in from all sides. Another part of my reluctance to use typedefs is I have spent too many hours tracing through too many layers of typedefs, macros, #include's, #if's, etc., trying to figure out just what type foo_x_t_bar_abc__t_my_x_t actually is. Some things I know are going to change? For 64 bits, size_t and ptrdiff_t are not going to be int-sized any more. File sizes and file offsets are going to 64 bits. time_t is going to change. The size of a pointer is going to change. Things that I am sure won't change? sizeof(char) is going to stay 1. The number of bits in a byte is going to stay at 8 (10 bit bytes and 18 bit half-words are machines of the past, and are not going to be resurrected). Ones-complement isn't coming back. IEEE 754 floating point is here to stay. Worrying about these things changing is fruitless because (aside from those changes not happening) despite one's best efforts, one will get it wrong anyway trying to be portable to such architectures without actually testing it on such. I think the 16 to 32 bit conversion proved that <g>.
Dec 26 2003
In article <bsgv5n$11m4$1 digitaldaemon.com>, Walter says...I'm not a very orthodox programmer. I tend to use far fewer typedefs than others, usually only for either 1) documentation purposes or if 2) I *know* it will change, rather than worry that it might. The reason for (2) is my experience migrating from the 16 bit world to 32 bits. 16 bit programmers would really load up their code with typedef's for portability reasons, and yet when the code was ported to 32 bits it still broke all over the place and was just as much trouble to fix as code with no typedefs at all. The trouble comes from subtle dependencies on the type of a typedef creeping in from all sides.Of course poorly done typedefs are always a problem partly because C/C++ does not actually create a new type. A few years of Ada programming makes you appreciate what types can be.
Dec 26 2003
"Mark T" <Mark_member pathlink.com> wrote in message news:bshlgj$25mu$1 digitaldaemon.com...In article <bsgv5n$11m4$1 digitaldaemon.com>, Walter says...*know*I'm not a very orthodox programmer. I tend to use far fewer typedefs than others, usually only for either 1) documentation purposes or if 2) Iandit will change, rather than worry that it might. The reason for (2) is my experience migrating from the 16 bit world to 32 bits. 16 bit programmers would really load up their code with typedef's for portability reasons,inyet when the code was ported to 32 bits it still broke all over the place and was just as much trouble to fix as code with no typedefs at all. The trouble comes from subtle dependencies on the type of a typedef creepingdoesfrom all sides.Of course poorly done typedefs are always a problem partly because C/C++not actually create a new type. A few years of Ada programming makes you appreciate what types can be.I've never programmed in Ada so I'll take your word for it. BTW, D does have strong typedef's unlike C/C++.
Dec 26 2003
"Walter" <walter digitalmars.com> wrote in message news:bsicou$cjv$1 digitaldaemon.com..."Mark T" <Mark_member pathlink.com> wrote in message news:bshlgj$25mu$1 digitaldaemon.com...thanIn article <bsgv5n$11m4$1 digitaldaemon.com>, Walter says...I'm not a very orthodox programmer. I tend to use far fewer typedefsmy*know*others, usually only for either 1) documentation purposes or if 2) Iit will change, rather than worry that it might. The reason for (2) isprogrammersexperience migrating from the 16 bit world to 32 bits. 16 bitplaceandwould really load up their code with typedef's for portability reasons,yet when the code was ported to 32 bits it still broke all over theTheand was just as much trouble to fix as code with no typedefs at all.creepingtrouble comes from subtle dependencies on the type of a typedefinhavedoesfrom all sides.Of course poorly done typedefs are always a problem partly because C/C++not actually create a new type. A few years of Ada programming makes you appreciate what types can be.I've never programmed in Ada so I'll take your word for it. BTW, D doesstrong typedef's unlike C/C++.STLSoft does provide strong typedefs, called "True Typedefs". See the file stlsoft_true_typedef.h
Dec 27 2003
If it's not in the resultant lib, then I would believe that it's not in the DLL either.Yes its in the DLL ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Resources/Menus/MenuReference/MenuFunct ons/SetMenuInfo.asp ) even though I probably wont use this approach I'd still like the ability to use this function.Are you sure you're translating the parameter types properly? (C++ long is still only 32 bits on x86)Yea just an example not the actual entry.dfbth (Yet Another Windowing Toolkit coded in D)Aww, we should have teamed up! I've seen hundreds of individual projects but have not yet seen a team one :/. C "Andy Friesen" <andy ikagames.com> wrote in message news:bp7c0c$30oh$1 digitaldaemon.com...Charles Sanders wrote:fromHey all, Im running into some trouble implementing Windy , a GUI kit for windows. The problem arises when handling the WM_COMMAND messages originatingandMenu's. The event handling now is to associate a HWND with a Wnd class,messageshave the Wnd class process the message with its own internal map ofcontain aand event handlers. But the WM_COMMAND generated by menu's doesntstructureHWND to a Window, so I cant get a Wnd class to handle the message.dfbth (Yet Another Windowing Toolkit coded in D) has an abstract handleCommand method in the base Control class. Control.WndProc relays the command here. CompositeCommand overrides and looks for an applicable child, and relays it yet again. Other subclasses do interesting things depending on what they are. (Button just fires its onClick signal, et cetera) I hate to blow my own horn, but it works really well. :) You could first check the attached menu and see if it will handle the command. If not, fall back on whatever the superclass does.There are two ways I can handle this, I can associate a MENUINFOWM_MENUCOMMAND,with the menu, which will change the generated messages towith that I can call GetMenuInfo, and I can assocaite a HWND with a menu this way, and leave the message handling system consistentInternally allocate unique command IDs to menu items. Then you don't need any weird hacks.OR I can add a function [ addMenuHandler ] ( on top of the existing addHandler ) , and just keep the menu message handlers in a global map. This will be faster, but requires the user to memorize another function, which could easily cause trouble for users of the lib. I hate these design / perfornace tradeoff choices, and would like your opinions on what you think is best.Performance isn't really critical in this sort of thing. Nobody's selecting menu items three billion times per second, and, if your dispatching code really does cause a noticible delay, then you're doing something very, very wrong. Do whatever's easier to implement and use, and forget speed until you have proof that it's not up to par.Also the USER32.lib that comes with the Digital Mars CD doesnt have SetMenuInfo function in it, I tried implib /system USER32.lib USER32.dllIf it's not in the resultant lib, then I would believe that it's not in the DLL either. Are you sure you're translating the parameter types properly? (C++ long is still only 32 bits on x86) -- andy
Nov 16 2003
"Andy Friesen" <andy ikagames.com> wrote in message news:bp7c0c$30oh$1 digitaldaemon.com...Charles Sanders wrote:fromHey all, Im running into some trouble implementing Windy , a GUI kit for windows. The problem arises when handling the WM_COMMAND messages originatingandMenu's. The event handling now is to associate a HWND with a Wnd class,messageshave the Wnd class process the message with its own internal map ofcontain aand event handlers. But the WM_COMMAND generated by menu's doesntstructureHWND to a Window, so I cant get a Wnd class to handle the message.dfbth (Yet Another Windowing Toolkit coded in D) has an abstract handleCommand method in the base Control class. Control.WndProc relays the command here. CompositeCommand overrides and looks for an applicable child, and relays it yet again. Other subclasses do interesting things depending on what they are. (Button just fires its onClick signal, et cetera) I hate to blow my own horn, but it works really well. :) You could first check the attached menu and see if it will handle the command. If not, fall back on whatever the superclass does.There are two ways I can handle this, I can associate a MENUINFOWM_MENUCOMMAND,with the menu, which will change the generated messages towith that I can call GetMenuInfo, and I can assocaite a HWND with a menu this way, and leave the message handling system consistentInternally allocate unique command IDs to menu items. Then you don't need any weird hacks.OR I can add a function [ addMenuHandler ] ( on top of the existing addHandler ) , and just keep the menu message handlers in a global map. This will be faster, but requires the user to memorize another function, which could easily cause trouble for users of the lib. I hate these design / perfornace tradeoff choices, and would like your opinions on what you think is best.Performance isn't really critical in this sort of thing. Nobody's selecting menu items three billion times per second, and, if your dispatching code really does cause a noticible delay, then you're doing something very, very wrong. Do whatever's easier to implement and use, and forget speed until you have proof that it's not up to par.Also the USER32.lib that comes with the Digital Mars CD doesnt have SetMenuInfo function in it, I tried implib /system USER32.lib USER32.dllIf it's not in the resultant lib, then I would believe that it's not in the DLL either. Are you sure you're translating the parameter types properly? (C++ long is still only 32 bits on x86) -- andy
Nov 16 2003
Oops, stupid outlook.You could first check the attached menu and see if it will handle the command. If not, fall back on whatever the superclass does.What attached menu ? The only paramater that comes with the WM_COMMAMD messages generated from menu's is the control ID you've assigned it. Can you show me your code ? Thanks, C "Charles Sanders" <sanders-consulting comcast.net> wrote in message news:bp8fbj$1f4t$1 digitaldaemon.com..."Andy Friesen" <andy ikagames.com> wrote in message news:bp7c0c$30oh$1 digitaldaemon.com...windows.Charles Sanders wrote:Hey all, Im running into some trouble implementing Windy , a GUI kit forclass,fromThe problem arises when handling the WM_COMMAND messages originatingMenu's. The event handling now is to associate a HWND with a Wndandmenumessageshave the Wnd class process the message with its own internal map ofcontain aand event handlers. But the WM_COMMAND generated by menu's doesntstructureHWND to a Window, so I cant get a Wnd class to handle the message.dfbth (Yet Another Windowing Toolkit coded in D) has an abstract handleCommand method in the base Control class. Control.WndProc relays the command here. CompositeCommand overrides and looks for an applicable child, and relays it yet again. Other subclasses do interesting things depending on what they are. (Button just fires its onClick signal, et cetera) I hate to blow my own horn, but it works really well. :) You could first check the attached menu and see if it will handle the command. If not, fall back on whatever the superclass does.There are two ways I can handle this, I can associate a MENUINFOWM_MENUCOMMAND,with the menu, which will change the generated messages towith that I can call GetMenuInfo, and I can assocaite a HWND with amap.this way, and leave the message handling system consistentInternally allocate unique command IDs to menu items. Then you don't need any weird hacks.OR I can add a function [ addMenuHandler ] ( on top of the existing addHandler ) , and just keep the menu message handlers in a globalfunction,This will be faster, but requires the user to memorize anotherwhich could easily cause trouble for users of the lib. I hate these design / perfornace tradeoff choices, and would like your opinions on what you think is best.Performance isn't really critical in this sort of thing. Nobody's selecting menu items three billion times per second, and, if your dispatching code really does cause a noticible delay, then you're doing something very, very wrong. Do whatever's easier to implement and use, and forget speed until you have proof that it's not up to par.Also the USER32.lib that comes with the Digital Mars CD doesnt have SetMenuInfo function in it, I tried implib /system USER32.lib USER32.dllIf it's not in the resultant lib, then I would believe that it's not in the DLL either. Are you sure you're translating the parameter types properly? (C++ long is still only 32 bits on x86) -- andy
Nov 16 2003
Charles Sanders wrote:Oops, stupid outlook.It looks like Andy posts all of his cool stuff at: http://ikagames.com/andy/d/ dfbth is listed there. JustinYou could first check the attached menu and see if it will handle the command. If not, fall back on whatever the superclass does.What attached menu ? The only paramater that comes with the WM_COMMAMD messages generated from menu's is the control ID you've assigned it. Can you show me your code ?
Nov 16 2003
Charles Sanders wrote:http://ikagames.com/andy/d/dfbth-15-nov-2003.zipYou could first check the attached menu and see if it will handle the command. If not, fall back on whatever the superclass does.What attached menu ? The only paramater that comes with the WM_COMMAMD messages generated from menu's is the control ID you've assigned it. Can you show me your code ?Thanks, CI haven't gotten to implementing menus in dfbth just yet. But, basically, what you'd do is something like this: class Form : CompositeControl { int handleMessage(int code, int notifyCode) { if (_menuBar !== null) { int result = _menuBar.handleCommand(code, notifyCode); // relay the call if (result) return result; // we're done if the menu dealt with it } // if there's no menu, or it didn't recognize the command ID, // fall back on the default behaviour. (find a child that // will handle it, discard it, whatever) return super.handleMessage(code, notifyCode); } // ... } The menubar would just see if any of its menu items will respond to the command code, and dispatch the correct signal if it can. (generate command codes on the fly, make sure each is unique) If not, return 0, let the caller fish around elsewhere for someone that will handle it. -- andy
Nov 16 2003