problem with editctl

This is a discussion on problem with editctl within the Windows Programming forums, part of the Platform Specific Boards category; Hello every1; im just playing with this code(calculator).its not a calculator yet (its a test thing) .for now i have ...

  1. #1
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218

    problem with editctl

    Hello every1;

    im just playing with this code(calculator).its not a calculator
    yet (its a test thing) .for now i have a dlg and on it a editbox to display numbers.and 3 buttons:
    + = and ok to end it;

    when i input the number and push (+) button , to clear
    the editbox ,i use EM_UNDO(i could have used WM_CLEAR) . so i can input the other number.
    after the 2nd input when i push (=) button the answer
    is correct and it will show on edit.

    my problem is , i cant use EM_UNDO in (=)button ID"12"
    to clear .because of the obvious reason that it will
    clear the edit before the answer is shown.

    what i need is a way to tell the edit to clear the window
    after (answer is displayed && first char is punched)

    i subclassed edit proc to modify the WM_CHAR , but that
    seems to give me errors at times.

    what can i do?

    Code:
    BOOL CALLBACK AboutDlg2Proc (HWND hDlg, UINT message, 
                                WPARAM wParam, LPARAM lParam)
    {
    
    static   HWND hedit;       
    
    static HDC  hdc;
    static int  m, p;
    static int n[3];
    
    
         switch (message)
         {
       case WM_INITDIALOG :
    
    hedit = GetDlgItem(hDlg, 9);    //get a handle on id "9" the editctl
    
    
              
            SetFocus(hedit);
    
       return FALSE ;
      
     
        
                                                   
    	
              
       case WM_COMMAND :	
    		
    		 
            switch (LOWORD (wParam))
              {
    	
      case IDOK:
             EndDialog (hDlg, 0) ;
    		  break;
    
      case 10:   //plus sign on dlg
              
    		 
             n[0] = GetDlgItemInt(hDlg, 9, NULL, FALSE);         
              
    	     SendMessage(hedit,EM_UNDO, 0, 0);
    
             SetFocus(hedit);
    
    		 break;
    
    	
      
                 
    
    
      case 12: //equal sign on dlg
    			
           
               n[1] = GetDlgItemInt(hDlg, 9, NULL, FALSE);         
               p = n[1] + n[0];
    	 
    		   
    	       SetDlgItemInt(hDlg,9, p,  FALSE);
    			 
     
               SetFocus(hedit);
    	
        
             break;
    		}
    			
               
    		  
              break;
    	 }
    	  
    		  
         return FALSE ;
    }

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Not being able to see your calc dlg I can't be 100% sure but,

    I would 'collect' the first number from the user (until they use an non digit button).

    Save the operator they want used.

    Collect the second number (until they use an non digit button). At this point I would perform the first operation, display the result.

    If the last button was not '=' then save the result as the first number, remember the operator to use and repeat.

    there are two cases if a digit button was pressed;

    If the last button pressed was a digit;
    read the contents of the edit to a string,
    sprintf() the digit to the end of the string
    and SetDlgItemText() to display it.

    If the last button pressed was not a digit then this is hte first in a new number so clear the edit and display the digit.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    --
    | --------------------------
    | editbox |
    |-------------------------
    |
    | | |
    |
    |

    |------------------------------------------------ | | | |
    | + | - | = |


    iykes
    thx novacain.
    please dont call it a calculator. its embarrasing .
    right now its a addculator . i just

    want to get pass the edit problem first .then i will initialize the logic later.

    now since my problem is what happens after we push (=)
    button (to tell edit , to clear the content upon the first
    entry of a character after (=)). i came up with this solution

    i will put a boolian value in case#12(= button) as bool12.
    set it as TRUE within case 12 every time = button is chosen.
    and wont clear the edit content from within case 12(to be
    able to display the result).

    then i will subclass edit procedure and in its WM_CHAR
    part i will use this code:

    WM_CHAR:
    if(bool12 == TRUE){
    SendMessage(hedit, EM_GETSEL, 0, 0);
    SendMessage(hedit, WM_CLEAR, 0, 0);
    or
    SendMessage(hedit, EM_UNDO, 0, 0);
    bool12 = FALSE;
    }

    break;

    i am at work , i thought about it .i dont know if it works.
    i try it when i get home.

    cheers!
    Last edited by SAMSAM; 03-10-2003 at 01:22 PM.

  4. #4
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    It works fine, so i guess sub was the answer.

    nova;

    now im gone add more feature to it in my (test workspace)
    and then add it to my main program as an extra feature
    (this prog has 140 menu items(i know its dumb) and its
    all in one program ,that i have added features to it leisurleythrough the last few months,)like simple word process
    , opengl graphic window(its nested in 2 menu item), musical keyboard notes, simple games & cartoons, clip& bm viewer,
    sys info, syscolor change , font &&&ollaaalaaa,,).

    now here is the added code with basecode added for
    my unfinished cal. i dont know. should i use keyboard
    buttons or dlg buttons for digital input .i guess the norm
    is dlg,

    Code:
    /*------------------------------------------------------------
       
                     Sia k
      ------------------------------------------------------------*/
    
    #include <windows.h>
    #include <math.h>
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #include <stdlib.h>
    
    static BOOL bbutton = FALSE; 
    WNDPROC ep;
    BOOL CALLBACK AboutDlg2Proc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
    LRESULT CALLBACK editProc (HWND, UINT, WPARAM, LPARAM) ;
                              
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         static CHAR szAppName[] = TEXT ("Hello Lovely Sara") ;
    	 
         HWND         hwnd ;
         MSG          msg ;
         WNDCLASSEX     wndclass ;
         wndclass.cbSize        = sizeof(wndclass); 
         wndclass.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;
         wndclass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
         RegisterClassEx(&wndclass);
         
           
                        
           
         
         
         hwnd = CreateWindow (szAppName,                  // window class name
                              TEXT ("The, Hello Lovely Sara"), // window caption
                              WS_OVERLAPPEDWINDOW,        // window style
                              CW_USEDEFAULT,              // initial x position
                              CW_USEDEFAULT,              // initial y position
                              CW_USEDEFAULT,              // initial x size
                              CW_USEDEFAULT,              // initial y size
                              NULL,                       // parent window handle
                              NULL,                       // window menu handle
                              hInstance,                  // program instance handle
                              NULL) ;                     // creation parameters
         
         ShowWindow (hwnd, iCmdShow) ;
         UpdateWindow (hwnd) ;
         
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    { 
    	
    static	   HBRUSH hbrush;
    static     HDC  hdc;
               PAINTSTRUCT ps ;
        
    static int cxchar, cychar, cxclient, cyclient;
    	
    	      TEXTMETRIC tm;
    static	  HINSTANCE hInstance;
    
    	
    	 
    	 
    	
    	 
      
         switch (message)
         {
         case WM_CREATE:
              
    		  hdc = GetDC(hwnd);
    		
    		  GetTextMetrics(hdc, &tm);
              
    		  cxchar = tm.tmAveCharWidth;
    		  cychar = tm.tmHeight + tm.tmExternalLeading;
              ReleaseDC(hwnd, hdc);
    		 
    		  hInstance = ((LPCREATESTRUCT) lParam) -> hInstance;
    		  DialogBox (hInstance, TEXT("cal"), hwnd, AboutDlg2Proc) ; 
    	
    		  return 0;
          case WM_SIZE:
    			   
    		 cxclient = LOWORD(lParam);
                 cyclient = HIWORD(lParam);
    		 return 0;
    	 case WM_PAINT:
    	    hdc =  BeginPaint (hwnd, &ps) ;
    
    	
    	    EndPaint (hwnd, &ps) ;
    	     return 0 ;   
    	
    
              
         case WM_DESTROY:
    		
              PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    
    BOOL CALLBACK AboutDlg2Proc (HWND hDlg, UINT message, 
                                WPARAM wParam, LPARAM lParam)
    {
    
    static   HWND hedit;       
    
    static int  m, p;
    static int n[3];
    static HDC  hdc;
         PAINTSTRUCT ps ;
    
         switch (message)
         {
       case WM_INITDIALOG :
    
    		hedit = GetDlgItem(hDlg, 9);       //get a handle on id "9" the editctl
            ep = (WNDPROC)SetWindowLong(hedit, GWL_WNDPROC, (LONG)editProc);
    
              
            SetFocus(hedit);
    
       return FALSE ;
      
     
        
                                                   
    	
              
       case WM_COMMAND :	
    		
    		 
    
    		  
            switch (LOWORD (wParam))
              {
    	
      case IDOK:
             EndDialog (hDlg, 0) ;
    		  break;
    
      case 10:              //plus sign on dlg
              
    		 
             n[0] = GetDlgItemInt(hDlg, 9, NULL, FALSE);         
              SendMessage(hedit, EM_SETSEL, (WPARAM)0, (LPARAM) 11);
    	   SendMessage(hedit, WM_CLEAR, 0, 0);
    	     
    
             SetFocus(hedit);
    
    		 break;
    
    	
      
                 
    
    
      case 12: //equal sign on dlg
    			
              bbutton = TRUE;
              n[1] = GetDlgItemInt(hDlg, 9, NULL, FALSE);         
              p = n[1] + n[0];
    	 
    		   
    	      SetDlgItemInt(hDlg,9, p,  FALSE);
    			 
             
              SetFocus(hedit);
    	
        
             break;
    		}
    			
             
              break;
    
      
    
    	 }
    	  
       return FALSE ;
    }
    
    
    LRESULT CALLBACK editProc (HWND hwedit, UINT message, WPARAM wParam, LPARAM lParam)
                                                        
    {
    HDC hdc;     
                PAINTSTRUCT ps ;
    static char pass2[50]; 
    
             
         switch (message)
         {
        
                   
         case WM_PAINT:
    		hdc = BeginPaint(hwedit, &ps);
    
    		EndPaint(hwedit, &ps);
    
         
    
           break;
           
    	 case WM_CHAR:
    	  if(bbutton == TRUE){
    
    	   SendMessage(hwedit, EM_SETSEL, (WPARAM)0, (LPARAM) 11);
    	   SendMessage(hwedit, WM_CLEAR, 0, 0);
           bbutton = FALSE;
          break; 
    		 }
         }
         return CallWindowProc (ep, hwedit, message, wParam, lParam) ;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21