home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / mswindo / programm / misc / 4814 < prev    next >
Encoding:
Internet Message Format  |  1993-01-10  |  10.1 KB

  1. From: defaria@hpcuhe.cup.hp.com (Andy DeFaria)
  2. Date: Sun, 10 Jan 1993 23:54:22 GMT
  3. Subject: Re: Help needed with BC++ 3.0 Windows Programming without OWL
  4. Message-ID: <115310002@hpcuhe.cup.hp.com>
  5. Organization: Hewlett Packard, Cupertino
  6. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!hpscit.sc.hp.com!hplextra!hpcss01!hpcuhe!defaria
  7. Newsgroups: comp.os.ms-windows.programmer.misc
  8. References: <115310001@hpcuhe.cup.hp.com>
  9. Lines: 208
  10.  
  11. I had gotten email from somebody about this and in attempting to respond I
  12. lost their address.  Still my response serves to help describe my application
  13. and problems a little bit better:
  14.  
  15.  
  16. >    to just try plain C and the API to start.  I bought Petzold's
  17. >    book (it's VERY good, although a bit pricey).  It was exactly
  18. >    what I needed, but it may be too slow for you if you already
  19. >    are experienced with event-driven programming in X.  For me,
  20. >    it was my first taste of it.
  21.  
  22. Who's Petzold and what is the name of his book?  My book is called _Developing
  23. Windows Applications with Borland C++ 3.1_ (Second edition) by James McCord.
  24. It discusses some basic raw Windows API calls and then delves into OWL.  The,
  25. remainder of the book is like you say, merely a funciton reference.
  26.  
  27. >    Borland's Resource Workshop (the best!) is so easy to design
  28. >    all of the resources (menus, dialogs, icons, bitmaps etc etc)
  29.  
  30. I had a lot of trouble trying to do this.  As you say, you don't do this in X.
  31. My problem was that I'd do things in the Resource Workshop (RW) and then try
  32. it out with my program.  First I'd get a "Can't find the .res" messages.  Then
  33. I noticed the RW's File:Preferences setting saying to save the RW changes in a
  34. .res file.  Now why would I not want that one checked?  Then, of course, you
  35. have to deal with remembering that if you make a change in RW you gotta
  36. File:Save Project and then go back to BC++ and re-bind resources.
  37.  
  38. >    The rest of the hard work was not really windows related
  39. >    (i.e. message handling, dialog boxes, menus, buttons),
  40. >    but rather was application specific.  The way I see it,
  41. >    the classes primarily help with message handling, but
  42. >    I'm old fashioned - I don't like to have 100 5-line
  43. >    functions, one for each message (i.e. member functions
  44. >    of classes). I prefer a large 'switch' to handle each
  45. >    message, so I can see them all at once.  BTW, the
  46. >    giant 10-page long 'switch' statement for messages is
  47. >    somewhat out-of-date now - the idea is to have a
  48. >    table of functions & message ids and the 'switch'    
  49. >    statement then becomes a 5-line loop to lookup the
  50. >    appropriate function and then call it.  This is
  51. >    sort of a hybrid between C and C++, I guess.
  52.  
  53. To me that's out of date.  Here's a snippet of X/Motif code:
  54.  
  55.    workButton = XtVaCreateManagedWidget
  56.      ("work", xmPushButtonWidgetClass, numberForm,
  57.       XmNlabelString,         XmStringCreateSimple ("Work #:"),
  58.       XmNtopAttachment,        XmATTACH_FORM,
  59.       XmNtopOffset,            3,
  60.       XmNleftAttatchment,        XmATTACH_FORM,
  61.       NULL);
  62.  
  63.    XtAddCallback (workButton, XtNactivateCallback, (XtCallbackProc) dialNumber,
  64.           (XtPointer) workNbr);
  65.  
  66. Here I create a pushbutton labeled "Work #:" that is attached on the top and
  67. the left to a "form" container window offset 3 pixels from the top.  Further I
  68. tell X that if this button is pushed then to call the function dialNumber and
  69. pass in the widget (basically a child window in MS Windows terms) named
  70. workNbr.  
  71.  
  72. The XtAddCallback function insures that dialNumber will be called in the event
  73. of a button push.  There can be many such callbacks all associated with
  74. pushing this single button.  There is no "event loop" to write.  It has been
  75. abstracted away in most causes.  My event loop is:
  76.  
  77.    XtAppMainLoop (PhoneBookApp);
  78.  
  79. If you haven't guessed by now I'm writing a phonebook application.  Work #
  80. appears on the tools face along with a single line input box called workNbr.
  81. This is not a dialog box but the face of the phonebook application.  I want it
  82. such that when I push the workButton the program dials the number through the
  83. modem that is contained in the single line edit box called workNbr.  There is 
  84. a similar set of these things for Home number.
  85.  
  86. BTW, in Motif, a form is a container class widget whose job it is to contain
  87. and layout any widgets or child windows contained there in.  In the above
  88. example, that means that my button is contrained to be attached to the left
  89. and top of the form.  Therefore, if I grab the left hand side of the window
  90. and stretch it out towards the left, this button will float along with it.
  91. This is all called geometry management in X and is what I hope to gain by
  92. using a class lib such as OWL.  Currently I have to specify the pixel relative
  93. offsets of all my child windows and I know I don't want to write code to
  94. resize and replace everything in the event of toplevel window resize event.
  95.  
  96. >>        How do I write get or set text into a child window?  My application
  97. >>        presents a form-like window that has child windows that are TEXT
  98. >>        input boxes.  I cannot figure out how to put/get text into or out of
  99. >>        these child windows.
  100.  
  101. >        You don't put or get text from the window itself, you
  102. >        work with a control in the window.  For example, you
  103. >        would put in an 'edit' control if you wanted to be
  104. >        able to enter a title or something else.  When the
  105. >        dialog box is closed, you interrogate that control
  106. >        to get the value.
  107.  
  108. Perhaps you don't understand my question.  I'm not in a dialog box.  I'm on
  109. the tools face itself.  My tool looks roughly like:
  110.  
  111.     +--------------------------------------------------+
  112.     | File  Actions                               Help |
  113.     +--------------------------------------------------+
  114.     | Name: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
  115.     | Work #: YYYYYYYYYYYYYYYYY  Home #: XXXXXXXXXXXXX |
  116.     | Address:                                         |
  117.     | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
  118.     | XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX |
  119.     +--------------------------------------------------+
  120.  
  121. And I have created the Work # field marked with "YYY"'s like so:
  122.  
  123.    workNbr = CreateWindow      
  124.     ("EDIT",                // Window Class
  125.     "",                    // Window Name
  126.     WS_CHILD | WS_VISIBLE | WS_BORDER,    // Window Style
  127.     65,                    // X Coordinate
  128.     40,                    // Y Coordinate
  129.     130,                    // Width
  130.     25,                    // Height
  131.     window,                    // Parent Window
  132.     NULL,                    // Menu
  133.     instance,                // Instance
  134.     NULL);                    // Parameters
  135.  
  136.  
  137. Given this workNbr child window, how does one write to it or get stuff out of
  138. it?
  139.  
  140. >        You can SetWindowText() and GetWindowText() to
  141. >        change the title (caption) of a window.
  142.  
  143. Again, I'm not interested in setting the title or caption of a window and I'm
  144. not in a dialog box.  I want to get to a child windows textual value itself.
  145.  
  146. >>        How does one put text into a dialog box?  I want to do a familiar "Are
  147. >>        you sure you want to delete 'thing being deleted'" type of dialog.  I
  148. >>        need to construct the message string for the dialog box but I don't
  149. >>        know how to do that.
  150. >        You can do a lot with MessageBox(), i.e.:
  151. >        if(MessageBox(hwnd,"are you sure you want to delete it ?",
  152. >                "file XXX.YYY",MB_YESNO)==IDYES){
  153. >            unlink("xxx.yyy");
  154. >        }
  155.  
  156. This is a confusing thing for me.  As you know, in Motif you build your own
  157. dialogboxes programmatically (although there are some standard canned ones
  158. that are useful).  Why would I make a dialogBox in the RW if I could simply do
  159. this?  To answer my own question: Because the RW Dialog Editor is really only
  160. for more complicated dialog boxes.  And that's probably because to allow you
  161. to build your own dialog boxes programmatically would probably require that
  162. you have some sort of geometry management which MS Windows doesn't provide.
  163.  
  164. My simple solution is the MessageBox route.  There is nothing else in the
  165. dialog but the message needs to be constructed with the persons name so I can
  166. get away with it this time.  But what if I had a more complicated dialog box
  167. and wished to put a message into it which could only be determined at run
  168. time?
  169.  
  170. >>        How can one get an icon image or a bmp into a button?
  171. >        This is something which is not part of the standard
  172. >        Windows API or SDK.  It is a Borland feature - they
  173. >        have some special controls in OWL (they are selectable
  174. >        from Resource Workshop).  Look at the collection of
  175. >        examples and DOC files in your Borland directories
  176. >        for samples on how to do this.  I recall a file
  177. >        BTBTN.C etc referring to this.  
  178.  
  179. Well I have Quicken for Windows 2.0 and it has a full color button bar across
  180. the top.  Is it a Borland application?
  181.  
  182. I cannot look up this file.  Remember I don't have AF or OWL yet.  No such
  183. file appears on my system by that name (or anthing close to it).
  184.  
  185. >>        I tried making what would be called a staticTextWidget in X but it's
  186. >>        color is wrong.  I want the color for a staticTextWiget to be the
  187. >>        application's background color, not a TEXT boxes' input color.
  188.  
  189. >        When you create a window (actually when you register
  190. >        the window class), you specify the background colour
  191. >        to be whatever you like.  You can get the user's
  192. >        preferred background colour using a colour of
  193. >        COLOR_WINDOW+1.
  194.  
  195. This staticTextWidget I speak of is the "Name" field in the above diagram.  I
  196. create my main window using a window class that has:
  197.  
  198.       windowClass.hbrBackground = COLOR_APPWORKSPACE + 1; 
  199.  
  200. However the Name label field is created as a child window to the main window.
  201. Am I to understand that I must create another windowClass structure and set
  202. it's hbrBackground again?
  203.  
  204. >>        How would I change the input editing semantics of these text input
  205. >>        areas to be as I specify.  I like emacs type editing.  I get this
  206. >>        easily in X via translation table and like to implement this in my
  207. >>        program.
  208.  
  209. >        I don't think you can do this.  The 'edit' class of
  210. >        control uses Windows CUA-type controls.  I don't
  211. >        think you can make it work any other way, other
  212. >        than writing your own 'edit' class'
  213.  
  214. Again, I have Word Perfect for Windows and it sports both the standard Windows
  215. CUA-type of editing style and Word Perfect's old editing style.  Therefore it
  216. is possible but it might, as you say, require writing my own edit class.
  217. Still EMACs editing style is fairly popular and I would hope that someone has
  218. already done this.
  219.