Solved

filter for dialog window

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 80
bigDiff challenge 17 126
Modbus - whats the maximum I can store in one register? 4 80
Problem to App 4 97
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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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