From: silver@ccwf.cc.utexas.edu (silver)
Newsgroups: comp.os.ms-windows.programmer.misc
Subject: Questions Answered
Date: 26 Jul 92 10:47:49 GMT
Reply-To: silver@ccwf.cc.utexas.edu (silver)
Organization: The Tally Ho
Originator: silver@dopey.cc.utexas.edu

Here are some answers to some windows questions I saw posted this last
week. If you posted a question recently, look through this whole article.
If you are in a position of hiring or know someone who is in any company
that writes windows software, check out my swift, accurate, clean answers
and consider me ;)
 
-------------------------
 
From: gmccoy@decwin.enet.dec.com
 
>I am using multiple scroll bar controls in a dialog box and I'm having
>trouble selecting between them.
>
>I think the problem is in the handling or not handling of
>SB_ENDSCROLL. I don't handle this message in my dialog procedure,
>but I notice it is sent when I let up on the mouse button.
>
>The effect is to have the scroll bar continuous selected. For example,
>If I have clicked the left or right scroll arrow, it stays selected
>even when I let up on the button. When I move off the scrollbar arrow,
>I no longer receive SB_LINEDOWN or SB_LINEUP messages, but start
>receiving them again as soon as I move back onto the arrow.
>
>My question is how to handle SB_ENDSCROLL? Should the defWindowProc
>be handling this message? Thanks for the help.
 
your switch/case statement should return false to make sure Windows handles
your WM_ENDSCROLL message for you... um, other than that, I made a dialog
box with three scroll bars and used it for a while and obsevered exactly
no problems... nor even the behavior you described. Although it actually
sounds like your window is behaving normally. Check your code and if it
looks sound, it's probably just the way Windows is... it's not like it's
causing erroneous data or anything, just a small aesthetic point.
 
-------------------------
 
 
From: heathh@cco.caltech.edu (Heath Ian Hunnicutt)
 
>	How can I "deactivate" a check box control in a dialog
>box from within the dialog procedure?  I mean turn it gray and
>unresponsive, not just uncheck it.
>	I know that I can define that check box to be grayed in
>my dialog template, but then I don't know how to "revive" it.
 
 
SetWindowLong (hCheckBox, GWL_STYLE,
                BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP);
 
revives the grayed check box, and
 
SetWindowLong (hCheckBox, GWL_STYLE,
        BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_TABSTOP);
 
disables it...
then send
ShowWindow (hCheckBox, SW_SHOWNA);
to insure it's redrawn in its new (active or inactive) state.
 
-------------------------
 
in a flurry of cutting and pasting I lost who asked and who answered the
question, which was basically how do you change attributes about your
window: such as choice of scroll bars, having a system menu, etc.
Someone answered, this is a more complete (and more tested!) answer.
 
From: mark@sdd.hp.com (Mark Overton)
> SetWindowLong (hWnd, GWL_STYLE, NewStyle);
 
NewStyle should be of type long, and you can form it with the cool
bitwise ors of standard constants, thus:
 
OldStyle = GetWindowLong (hWnd, GWL_STYLE);
NewStyle = OldStyle | WS_VSCROLL;
(or even SetWindowLong (hWnd, GWL_STYLE, OldStyle | WS_VSCROLL) would work,
or the even sicker combination involving no temporary long variables at
all, ick!)
 
I tested it... even after sending an ShowWindow it wouldn't redraw the
window with the new scroll bar and border until I fiddled with the border.
So, it mostly worked, but not well.
 
-------------------------
 
Thanos Karras
thanos@reef.cis.ufl.edu
 
>I have a modal dialog box that contains a multiline edit control and
>some buttons.
>The problem I am facing is that when I tab to the edit control, the text
>is selected. Is there any way to set the selection off in multiline
>edit controls?
 
capture the EN_SETFOCUS, and send an EM_SETSEL with 0,0, thus:
 
   switch (message) {
      case WM_COMMAND:
         switch (wParam) {
            case IDEditBox: // the #define value of the edit box control
               switch (HIWORD (lParam)) {
 
                  case EN_SETFOCUS:
                     SendMessage (hEditBox, EM_SETSEL, NULL, MAKELONG (0,0));
                        // the handle of the edit box, previously obtained
                        // with hEditBox = GetDlgItem (hDlg, IDEditBox)
                        // the MAKELONG is not wholly necessary, but harmless
                        // and reminds you that those are cursor positions,
                        // in case you want to use EM_SETSEL for something
                        // different in another program
                     return TRUE;
 
//               cases for other edit box messages
               }
//         cases for other buttons and controls
         }
 
      cases for other messages
      }
      return FALSE;
 
your other question made little sense, as my program gets KEY_UP and
KEY_DOWN messages for all the keys... perhaps a clearer rephrase?
-------------------------
 
 
From: 890560p@dragon.acadiau.ca (Trevor Porter)
>
>I'm looking for a way to obtain the index of the character next to the
>cursor in an edit control.  Is there an easy way to do this ?
>None of the messages that you can send to an edit control return this.
 
// this isn't code, just some bits and pieces...
 
static int sizeOfText; // length of text in the editbox
static HWND hEditBox; // handle of the edit box control
static char EditString[80]; // string in edit box... 80 is arbitrary
static DWORD SelectRegion; // beginning and end of selected region in the
                           // edit box
static WORD regionBegin, regionEnd; // ditto, in a more useful form
 
hEditBox = GetDlgItem (hDlg, IDEditBox);
   // hDlg is the parameter of the dialog function id'ing the handle of
   // the dialog box, and the IDEditBox is the #defined value for the
   // editbox control
   // however, you probably already got this far
 
sizeOfText = SendMessage (hEditControl, WM_GETTEXT, 80, &EditString);
   // the SendMessage function fills EditString up to the 80 characters
   // and returns how many characters it copied in...
SelectRegion = SendMessage (hEditControl, EM_GETSEL, NULL, NULL);
   // returns the parameters of the selected region...
regionBegin = LOWORD (SelectRegion);
regionEnd = HIWORD (SelectRegion);
 
now you have a zillion bits of control... if regionBegin is equal to
regionEnd, then the user just has a cursor in the window (and array selection
off of EditString should retrieve the character you want), otherwise they've
selected a whole region and your question is meaningless.
 
other interesting messages: WM_SETTEXT, EM_SETSEL, EM_REPLACESEL
 
-------------------------
 
name lost, sorry... and the other questions I'm still working on ;)
 
>   a) How do I prevent cb_ResetContent and cb_InsertString from clearing
>      the edit control string OR how do I preserve it and restore it complete
>      WITH the current cursor position.
 
the WM_GETTEXT, EM_GETSEL messages work for comboboxes like they do for
editboxes... so get the text and cursor position(s) out before the
reset... then use WM_SETTEXT and EM_SETSEL to retore the old text and
cursor position(s).
Sorry the answer was in C, but I imagine the TPW functions are similar
enough.
 
-------------------------
 
Who says you need oodles of years of experience to be a good Windows
programmer?
I have a degree in Math with 22 hours of a CS, I'm a good programmer and
an especially fast learner.
And I'm cheap, $17,000 for an Austin job or $18,000 out of town (to cover
lease breaking)... hire me, I'm yours.
 
--John silver Harloe--
(512)/445-6087
6201 Sneed Cove #1121
Austin TX 78744-3434
 
Newsgroups: comp.os.ms-windows.programmer.misc