Solved

filter for dialog window

Posted on 1998-12-28
2
228 Views
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(IsDialogEvent(&gMainEventRecord))
     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:
                        SysBeep(1);
                        return;
                  case 0x1b:
                        itemHit = 1;
            }
            
      Check_For_Changes();
      
      switch(itemHit)
      {
                  case 1:
     doWhatever();
                  break;

   case  2:
     doWhatever();
   break

      }
}
0
Comment
Question by:dwp090598
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
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)) {
            SysBeep(1);
            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:
          gQuit=true;
      }
    }
    ...
0
 

Author Comment

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

Thanks Again...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Shell script to login to remote m/c and execute commands 10 80
Best tools for Backup and restore of Wordpress site 6 58
string initialization in java 11 122
haveThree challenge 22 127
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

732 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