filter for dialog window

Posted on 1998-12-28
Last Modified: 2013-12-26
I am trying to filter out the 'return' key and 'esc' key in a dialog window. I know how to pass a UniversalProcPtr to ModalDialog( gMyModalProc, &itemHit); and filter out the keys. When I use DialogSelect(&gMainEventRecord, &hitWindow, &itemHit); and try to filter out the keys the keys get passed anyway.  I have a dialog window with three edit text fields, I would like to limit two edit fields to 4 chars each and the other to 31 chars. How can I get around this?

     if(DialogSelect(&gMainEventRecord, &hitWindow, &itemHit))
                    HandleFileInfoDialog(itemHit, &gMainEventRecord);

Boolean HandleFileInfoDialog (short itemHit, EventRecord *theEvent)

      if(theEvent->what  == keyDown)
            switch((theEvent->message) & charCodeMask)
                  case 0x0d:
                  case 0x03:
                  case 0x1b:
                        itemHit = 1;
                  case 1:

   case  2:

Question by:dwp090598

Accepted Solution

boonstra earned 50 total points
ID: 1291683
The problem is that DialogSelect is processing your keyDown events.  It is probably also processing 0x0D and 0x03 as keyboard equivalents for the default button in your dialog.

Unfortunately the filterProcs you refer to in your question apploy only to modal dialogs.  Yours is probably nonModal.  You need to intercept the keyDown events before they get to DialogSelect.  Something like:

    if (IsDialogEvent(&ev)) {
      if (FrontWindow()==gDialog) {
        notHandled = true;
        dlgP = (DialogPeek)gDialog;
        if (ev.what==keyDown) {
          ch = ev.message & charCodeMask;
          if ((ch==0x0D) || (ch==0x03)) {
            notHandled = false;
          if (dlgP->editField == kItemOfInterest1-1) {
            /* count and filter characters for item kItemOfInterest1 */
            if (++gCharCount1>4) notHandled = false;
          } else if (dlgP->editField == kItemOfInterest2-1) {
            /* count and filter characters for item kItemOfInterest2 */
            if (++gCharCount2>4) notHandled = false;
        if (notHandled && DialogSelect(&ev, &wind, &itemHit)) {
          /* need to update gCharCounts here */
      if (gDialog==wind) switch (itemHit) {
        case ok:
        case cancel:

Author Comment

ID: 1291684
yes, my dialog is non modal. I was trying to do the filtering after calling DialogSelect().

Thanks Again...

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
how to monitor remote shell execution on linux 9 100
modThree challenge 4 91
Modbus - whats the maximum I can store in one register? 4 80
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question