|
Prev: Date/Time Picker dialog
Next: Call web service
From: gw7rib on 28 Jun 2008 07:05 My program uses a few dialog boxes to allow the user to edit data. The dialog box needs to find the data, in order to show it, and it needs to be able to store the altered data back if the user clicks OK. At present I am using a global to point to the class which contains the data. This seems a bit shaky, and it also mean that only one lot of data can be edited at once. I was wondering whether this could be improved. My first thought was to use GetParent on the dialog box to get back to one of my own windows, from which I can find the class. But this seems a little long-winded, and prone to error if I don't set the parent up properly. Another possibility would be to search through all the classes to see if the handle of their dialog box (if any) is the same as the handle of the dialog box in question. But this seems time-consuming. I've had a quick look on MSDN, and I note that there is a function called DialogBoxParam, which will allow a parameter to be passed in. Thuis would work while the WM_INITDIALOG message is running. But is there a way to store this value in the dialog window? Presumably I could store it in a child window somehow (eg in the text of an edit box which is off-screen) but this seems a bit exotic. So is there a recommended way of doing this? And am I worrying about this unduly, in that if I stick to modal dialog boxes I won't be editting two lots of data simultaneously anyway? Thanks for any advice. Paul.
From: Armel on 28 Jun 2008 10:49 <gw7rib(a)aol.com> a �crit dans le message de news: fd3f86a3-8fa7-44ab-b0f8-e51caa5ef6c1(a)59g2000hsb.googlegroups.com... > My program uses a few dialog boxes to allow the user to edit data. The > dialog box needs to find the data, in order to show it, and it needs > to be able to store the altered data back if the user clicks OK. > > At present I am using a global to point to the class which contains > the data. This seems a bit shaky, and it also mean that only one lot > of data can be edited at once. I was wondering whether this could be > improved. My first thought was to use GetParent on the dialog box to > get back to one of my own windows, from which I can find the class. > But this seems a little long-winded, and prone to error if I don't set > the parent up properly. Another possibility would be to search through > all the classes to see if the handle of their dialog box (if any) is > the same as the handle of the dialog box in question. But this seems > time-consuming. > > I've had a quick look on MSDN, and I note that there is a function > called DialogBoxParam, which will allow a parameter to be passed in. > Thuis would work while the WM_INITDIALOG message is running. But is > there a way to store this value in the dialog window? Presumably I > could store it in a child window somehow (eg in the text of an edit > box which is off-screen) but this seems a bit exotic. > > So is there a recommended way of doing this? And am I worrying about > this unduly, in that if I stick to modal dialog boxes I won't be > editting two lots of data simultaneously anyway? Generally you use a SetWindowLong (or something like SetWindowPtr) to set a pointer to your data in a user slot in the window's data. You can then use this pointer in your WindowProc with the matching GetWindowLong > Thanks for any advice. > Paul. Armel
From: r_z_aret on 28 Jun 2008 10:52 On Sat, 28 Jun 2008 04:05:37 -0700 (PDT), gw7rib(a)aol.com wrote: >My program uses a few dialog boxes to allow the user to edit data. The >dialog box needs to find the data, in order to show it, and it needs >to be able to store the altered data back if the user clicks OK. > >At present I am using a global to point to the class which contains >the data. This seems a bit shaky, and it also mean that only one lot >of data can be edited at once. I was wondering whether this could be >improved. My first thought was to use GetParent on the dialog box to >get back to one of my own windows, from which I can find the class. >But this seems a little long-winded, and prone to error if I don't set >the parent up properly. Another possibility would be to search through >all the classes to see if the handle of their dialog box (if any) is >the same as the handle of the dialog box in question. But this seems >time-consuming. > >I've had a quick look on MSDN, and I note that there is a function >called DialogBoxParam, which will allow a parameter to be passed in. >Thuis would work while the WM_INITDIALOG message is running. But is >there a way to store this value in the dialog window? Presumably I >could store it in a child window somehow (eg in the text of an edit >box which is off-screen) but this seems a bit exotic. I think the answers to your specific question are GetWindowLong and SetWindowLong. > >So is there a recommended way of doing this? And am I worrying about >this unduly, in that if I stick to modal dialog boxes I won't be >editting two lots of data simultaneously anyway? I think we (collectively) would have more useful comments if we knew more about the data and your larger problem. > >Thanks for any advice. >Paul. ----------------------------------------- To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message). Robert E. Zaret, eMVP PenFact, Inc. 20 Park Plaza, Suite 400 Boston, MA 02116 www.penfact.com Useful reading (be sure to read its disclaimer first): http://catb.org/~esr/faqs/smart-questions.html
From: gw7rib on 29 Jun 2008 15:25 On 28 Jun, 15:52, r_z_aret(a)pen_fact.com wrote: > On Sat, 28 Jun 2008 04:05:37 -0700 (PDT), gw7...(a)aol.com wrote: > >My program uses a few dialog boxes to allow the user to edit data. The > >dialog box needs to find the data, in order to show it, and it needs > >to be able to store the altered data back if the user clicks OK. > > >At present I am using a global to point to the class which contains > >the data. This seems a bit shaky, and it also mean that only one lot > >of data can be edited at once. I was wondering whether this could be > >improved. My first thought was to use GetParent on the dialog box to > >get back to one of my own windows, from which I can find the class. > >But this seems a little long-winded, and prone to error if I don't set > >the parent up properly. Another possibility would be to search through > >all the classes to see if the handle of their dialog box (if any) is > >the same as the handle of the dialog box in question. But this seems > >time-consuming. > > >I've had a quick look on MSDN, and I note that there is a function > >called DialogBoxParam, which will allow a parameter to be passed in. > >Thuis would work while the WM_INITDIALOG message is running. But is > >there a way to store this value in the dialog window? Presumably I > >could store it in a child window somehow (eg in the text of an edit > >box which is off-screen) but this seems a bit exotic. > > I think the answers to your specific question are GetWindowLong and > SetWindowLong. Ah. I'm using these (or more specifically SetWindowLongPtr) with my own windows but when I registered the window class for my own windows I specifically reserved some space to store a pointer, using the cbWndExtra member. When I create a dialog box I don't use a class that I have registered. Are you saying that, nevertheless, there is room in the dialog box for me to store a pointer? Would this be the GWLP_USERDATA attribute? Furthermore, does a normal window class have space to store a single pointer, even if cbWndExtra is set to zero, by this method? See below for more details, if I'm still being unclear. > >So is there a recommended way of doing this? And am I worrying about > >this unduly, in that if I stick to modal dialog boxes I won't be > >editting two lots of data simultaneously anyway? > > I think we (collectively) would have more useful comments if we knew > more about the data and your larger problem. My program allows a user to make notes. Each note may or may not be visible on the screen - if it is, it appears in a pop-up window. The notes can be saved en masse to a file. The program is flexible in that, if the user simply wants to create a note and write something in it, they can, without further ado. However, the notes have properties which, if the user sets them appropriately, allows some processing of the notes. The properties include a description (this appears in the title bar when a note is shown), a flag to show whether the noted is locked (ie cannot be edited), a priority (from 1 to 7), a date, and the note may also belong to one or more user-defined categories. So if the user wants to see what things he needs to do in the next week, in order of priorty, the program will show him a list of descriptions each with a link to the full note. I am using a class Note to store each note. If a note is displayed, the window stores a pointer to the Note (used in the window function) and the Note also stores a pointer to the window handle. If the user wants to edit the properties of a note, I create a dialog box which shows the relevant properties and allows the user to edit them. At present, the dialog box gets its data, and writes it back if required, using a global which points to the note whose properties are being edited. This is the bit which I am trying to improve.
From: r_z_aret on 30 Jun 2008 10:50 On Sun, 29 Jun 2008 12:25:17 -0700 (PDT), gw7rib(a)aol.com wrote: >On 28 Jun, 15:52, r_z_aret(a)pen_fact.com wrote: clip >> >> I think the answers to your specific question are GetWindowLong and >> SetWindowLong. > >Ah. I'm using these (or more specifically SetWindowLongPtr) with my >own windows but when I registered the window class for my own windows >I specifically reserved some space to store a pointer, using the >cbWndExtra member. When I create a dialog box I don't use a class that >I have registered. Are you saying that, nevertheless, there is room in >the dialog box for me to store a pointer? Would this be the >GWLP_USERDATA attribute? A relevant comment from my code says: See thread called "Use GWL_USERDATA & SetWindowLong/GetWindowLong or SetProp/GetProp to store user data" around 14 Apr 03 in comp.os.ms-windows.programmer.win32 for advice to use DWL_USER instead of GWL_USERDATA for dialogs > >Furthermore, does a normal window class have space to store a single >pointer, even if cbWndExtra is set to zero, by this method? > >See below for more details, if I'm still being unclear. The details did help, although not directly. ----------------------------------------- To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message). Robert E. Zaret, eMVP PenFact, Inc. 20 Park Plaza, Suite 400 Boston, MA 02116 www.penfact.com Useful reading (be sure to read its disclaimer first): http://catb.org/~esr/faqs/smart-questions.html
|
Pages: 1 Prev: Date/Time Picker dialog Next: Call web service |