home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / mswindo / programm / misc / 1021 < prev    next >
Encoding:
Internet Message Format  |  1992-07-26  |  7.7 KB

  1. Path: sparky!uunet!cs.utexas.edu!ut-emx!ccwf.cc.utexas.edu!silver
  2. From: silver@ccwf.cc.utexas.edu (silver)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Questions Answered
  5. Message-ID: <76598@ut-emx.uucp>
  6. Date: 26 Jul 92 10:47:49 GMT
  7. Sender: news@ut-emx.uucp
  8. Reply-To: silver@ccwf.cc.utexas.edu (silver)
  9. Organization: The Tally Ho
  10. Lines: 190
  11. Originator: silver@dopey.cc.utexas.edu
  12.  
  13. Here are some answers to some windows questions I saw posted this last
  14. week. If you posted a question recently, look through this whole article.
  15. If you are in a position of hiring or know someone who is in any company
  16. that writes windows software, check out my swift, accurate, clean answers
  17. and consider me ;)
  18.  
  19. -------------------------
  20.  
  21. From: gmccoy@decwin.enet.dec.com
  22.  
  23. >I am using multiple scroll bar controls in a dialog box and I'm having
  24. >trouble selecting between them.
  25. >
  26. >I think the problem is in the handling or not handling of
  27. >SB_ENDSCROLL. I don't handle this message in my dialog procedure,
  28. >but I notice it is sent when I let up on the mouse button.
  29. >
  30. >The effect is to have the scroll bar continuous selected. For example,
  31. >If I have clicked the left or right scroll arrow, it stays selected
  32. >even when I let up on the button. When I move off the scrollbar arrow,
  33. >I no longer receive SB_LINEDOWN or SB_LINEUP messages, but start
  34. >receiving them again as soon as I move back onto the arrow.
  35. >
  36. >My question is how to handle SB_ENDSCROLL? Should the defWindowProc
  37. >be handling this message? Thanks for the help.
  38.  
  39. your switch/case statement should return false to make sure Windows handles
  40. your WM_ENDSCROLL message for you... um, other than that, I made a dialog
  41. box with three scroll bars and used it for a while and obsevered exactly
  42. no problems... nor even the behavior you described. Although it actually
  43. sounds like your window is behaving normally. Check your code and if it
  44. looks sound, it's probably just the way Windows is... it's not like it's
  45. causing erroneous data or anything, just a small aesthetic point.
  46.  
  47. -------------------------
  48.  
  49.  
  50. From: heathh@cco.caltech.edu (Heath Ian Hunnicutt)
  51.  
  52. >    How can I "deactivate" a check box control in a dialog
  53. >box from within the dialog procedure?  I mean turn it gray and
  54. >unresponsive, not just uncheck it.
  55. >    I know that I can define that check box to be grayed in
  56. >my dialog template, but then I don't know how to "revive" it.
  57.  
  58.  
  59. SetWindowLong (hCheckBox, GWL_STYLE,
  60.                 BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP);
  61.  
  62. revives the grayed check box, and
  63.  
  64. SetWindowLong (hCheckBox, GWL_STYLE,
  65.         BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP);
  66.  
  67. disables it...
  68. then send
  69. ShowWindow (hCheckBox, SW_SHOWNA);
  70. to insure it's redrawn in its new (active or inactive) state.
  71.  
  72. -------------------------
  73.  
  74. in a flurry of cutting and pasting I lost who asked and who answered the
  75. question, which was basically how do you change attributes about your
  76. window: such as choice of scroll bars, having a system menu, etc.
  77. Someone answered, this is a more complete (and more tested!) answer.
  78.  
  79. From: mark@sdd.hp.com (Mark Overton)
  80. > SetWindowLong (hWnd, GWL_STYLE, NewStyle);
  81.  
  82. NewStyle should be of type long, and you can form it with the cool
  83. bitwise ors of standard constants, thus:
  84.  
  85. OldStyle = GetWindowLong (hWnd, GWL_STYLE);
  86. NewStyle = OldStyle | WS_VSCROLL;
  87. (or even SetWindowLong (hWnd, GWL_STYLE, OldStyle | WS_VSCROLL) would work,
  88. or the even sicker combination involving no temporary long variables at
  89. all, ick!)
  90.  
  91. I tested it... even after sending an ShowWindow it wouldn't redraw the
  92. window with the new scroll bar and border until I fiddled with the border.
  93. So, it mostly worked, but not well.
  94.  
  95. -------------------------
  96.  
  97. Thanos Karras
  98. thanos@reef.cis.ufl.edu
  99.  
  100. >I have a modal dialog box that contains a multiline edit control and
  101. >some buttons.
  102. >The problem I am facing is that when I tab to the edit control, the text
  103. >is selected. Is there any way to set the selection off in multiline
  104. >edit controls?
  105.  
  106. capture the EN_SETFOCUS, and send an EM_SETSEL with 0,0, thus:
  107.  
  108.    switch (message) {
  109.       case WM_COMMAND:
  110.          switch (wParam) {
  111.             case IDEditBox: // the #define value of the edit box control
  112.                switch (HIWORD (lParam)) {
  113.  
  114.                   case EN_SETFOCUS:
  115.                      SendMessage (hEditBox, EM_SETSEL, NULL, MAKELONG (0,0));
  116.                         // the handle of the edit box, previously obtained
  117.                         // with hEditBox = GetDlgItem (hDlg, IDEditBox)
  118.                         // the MAKELONG is not wholly necessary, but harmless
  119.                         // and reminds you that those are cursor positions,
  120.                         // in case you want to use EM_SETSEL for something
  121.                         // different in another program
  122.                      return TRUE;
  123.  
  124. //               cases for other edit box messages
  125.                }
  126. //         cases for other buttons and controls
  127.          }
  128.  
  129.       cases for other messages
  130.       }
  131.       return FALSE;
  132.  
  133. your other question made little sense, as my program gets KEY_UP and
  134. KEY_DOWN messages for all the keys... perhaps a clearer rephrase?
  135. -------------------------
  136.  
  137.  
  138. From: 890560p@dragon.acadiau.ca (Trevor Porter)
  139. >
  140. >I'm looking for a way to obtain the index of the character next to the
  141. >cursor in an edit control.  Is there an easy way to do this ?
  142. >None of the messages that you can send to an edit control return this.
  143.  
  144. // this isn't code, just some bits and pieces...
  145.  
  146. static int sizeOfText; // length of text in the editbox
  147. static HWND hEditBox; // handle of the edit box control
  148. static char EditString[80]; // string in edit box... 80 is arbitrary
  149. static DWORD SelectRegion; // beginning and end of selected region in the
  150.                            // edit box
  151. static WORD regionBegin, regionEnd; // ditto, in a more useful form
  152.  
  153. hEditBox = GetDlgItem (hDlg, IDEditBox);
  154.    // hDlg is the parameter of the dialog function id'ing the handle of
  155.    // the dialog box, and the IDEditBox is the #defined value for the
  156.    // editbox control
  157.    // however, you probably already got this far
  158.  
  159. sizeOfText = SendMessage (hEditControl, WM_GETTEXT, 80, &EditString);
  160.    // the SendMessage function fills EditString up to the 80 characters
  161.    // and returns how many characters it copied in...
  162. SelectRegion = SendMessage (hEditControl, EM_GETSEL, NULL, NULL);
  163.    // returns the parameters of the selected region...
  164. regionBegin = LOWORD (SelectRegion);
  165. regionEnd = HIWORD (SelectRegion);
  166.  
  167. now you have a zillion bits of control... if regionBegin is equal to
  168. regionEnd, then the user just has a cursor in the window (and array selection
  169. off of EditString should retrieve the character you want), otherwise they've
  170. selected a whole region and your question is meaningless.
  171.  
  172. other interesting messages: WM_SETTEXT, EM_SETSEL, EM_REPLACESEL
  173.  
  174. -------------------------
  175.  
  176. name lost, sorry... and the other questions I'm still working on ;)
  177.  
  178. >   a) How do I prevent cb_ResetContent and cb_InsertString from clearing
  179. >      the edit control string OR how do I preserve it and restore it complete
  180. >      WITH the current cursor position.
  181.  
  182. the WM_GETTEXT, EM_GETSEL messages work for comboboxes like they do for
  183. editboxes... so get the text and cursor position(s) out before the
  184. reset... then use WM_SETTEXT and EM_SETSEL to retore the old text and
  185. cursor position(s).
  186. Sorry the answer was in C, but I imagine the TPW functions are similar
  187. enough.
  188.  
  189. -------------------------
  190.  
  191. Who says you need oodles of years of experience to be a good Windows
  192. programmer?
  193. I have a degree in Math with 22 hours of a CS, I'm a good programmer and
  194. an especially fast learner.
  195. And I'm cheap, $17,000 for an Austin job or $18,000 out of town (to cover
  196. lease breaking)... hire me, I'm yours.
  197.  
  198. --John silver Harloe--
  199. (512)/445-6087
  200. 6201 Sneed Cove #1121
  201. Austin TX 78744-3434
  202.  
  203.