Solved

filter for dialog window

Posted on 1998-12-28
2
221 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
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now