Thread: Unwanted space inbetween characters

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

    Unwanted space inbetween characters

    Hi;

    i am having problem with this simple line of code.
    im getting char value at WM_CHAR and inputing it in array

    ptext[300] and use textout to output on the screen but i get this

    random unwanted spaces in between characters at times on the output screen what am i doing wrong


    Code:
    ptext[300]
    
    static int  cxchar, cychar, i = 0, x = 0, cxclient, cyclient, j = 0;
    
    WM_CREATE:
    ////////////////////
    
    GetTextMetric(,,,,,,,,,,,,,,,,,,,,,,)
    cxchar = ,,,,,,,,,,
    cychar = ,,,,,,,,,,
    
    ///////////////////
    
    WM_CHAR:
    
    ptext[x] = (char)wParam;
    x++;
    TextOut(hdc, i * cxchar, j, ptext + x, 1);
    i++;
    if((char)wParam == '\r'){
    j++;
    i = 0;
    }
    the characters as i type them appear as follow;


    ffffj kn o sssssl e

    i can do it another way by simply using

    TextOut(hdc, 0, j, ptext, x);
    and getting read of i .

    and it works but i need i somewhere down the code and i want to use the first case .

    thx

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Post full code.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

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

    Smile

    Ok here is the code

    except that now i changed the ptext to a pointer ptextbuff
    but its still the same story
    u need to check the WM_CHAR section only.thx

    by the way the in the code in WM_COMMAND
    by using menue id 51 i wanted to show editbox but it doesnt initializes the window.


    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <commdlg.h>
    #define ID_EDIT 100
     
    BOOL siachcolor(HWND hwnd);                 // header for choosecolor common dlg
    BOOL ChooseFont(HWND  hwnd);          //choose font
    void  releasef(void);
    void Initialize(HWND hwnd);
    HFONT  SetFont(HWND hwnd);
    
    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, Experimental all in one Programm") ;
    	  
         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, Experimental all in one programm"), // 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;
              
               PAINTSTRUCT ps ;
               HDC  hdc;
    static int cxchar, cychar, cxcaps,  cxclient, cyclient, i = 0,j = 0,  y = 0, x = 0,x1 = 0, cxbuffer, cybuffer;
    	       
    	       TEXTMETRIC tm;
    	       HMENU hmenu;
    static    HWND hwndedit;
    
    	       HINSTANCE hInstance;
               HFONT hfont;
    static char *ptextbuff = NULL; 
    static char ptext[300];	
    static char achar;	 
      
         switch (message)
         {
         case WM_CREATE:
    		 
    		 hwndedit = CreateWindow (TEXT ("edit Box Sara Writes Here"), NULL,
                             WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
                                       WS_BORDER | ES_LEFT | ES_MULTILINE |
                                       ES_AUTOHSCROLL | ES_AUTOVSCROLL,
                             0, 0, 0, 0, hwnd, (HMENU) ID_EDIT,
                             ((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
    		  
    		  hInstance = ((LPCREATESTRUCT )lParam)->hInstance;
              hmenu = LoadMenu(hInstance, TEXT ("sia0016"));
              SetMenu(hwnd, hmenu);
               
    		  Initialize(hwnd);
    		  
    		  hdc = GetDC(hwnd);
                 GetTextMetrics(hdc, &tm);
    		  cxchar = tm.tmAveCharWidth;
    		  cychar = tm.tmHeight + tm.tmExternalLeading;
    		  cxcaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxchar / 2;
              
    		 ptextbuff = (char *)malloc(200 * sizeof(char));
              ReleaseDC(hwnd, hdc);
    		
    	
    		  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_SETFOCUS:
    		 SetFocus(hwndedit);
    		 return 0;
    		 
         case WM_KILLFOCUS:
    
    		 SetFocus(hwndedit);
    		 return 0;
    
    	 case WM_COMMAND:
           
    			 
            // if (LOWORD (wParam) == ID_EDIT)
              
                   //if (HIWORD (wParam) == EN_ERRSPACE || 
                            // HIWORD (wParam) == EN_MAXTEXT)              // code about edit box
    
                 //MessageBox (hwnd, TEXT ("Edit control out of space."),
                                   //"memory shortage", MB_OK | MB_ICONSTOP) ;*/
    
    		 switch(LOWORD (wParam))
    		 {
    		 case 31:
    
           hbrush = CreateSolidBrush(siachcolor(hwnd));
    	   SetClassLong(hwnd, GCL_HBRBACKGROUND, (LONG)hbrush);     // code about choosecolor
    	   InvalidateRect(hwnd, NULL, TRUE);
           return 0;
    		 
    		 case 41:
    			 
    			 hdc = GetDC(hwnd);
    	   if(ChooseFont(hwnd))
    	   SelectObject(hdc, tSetFont(hwnd));    //code about choosefont
    	   ReleaseDC(hwnd, hdc);
    	     return 0;
    		 
    		 case 51:         //menue id
    
           
    	MoveWindow(hwndedit, 0, 0, 200, 500, FALSE);
    		SetFocus(hwndedit);
           
    	  
    	   return 0;
    		
    
    		 }
    		 break;
    
             
    		 case WM_CHAR:
    	   hdc = GetDC(hwnd);
          
    	  *(pbuffer + x) = (char) wParam;
    	  *(pbuffer + x + 1) = '\0';
          
    	   
    	     
    	  TextOut(hdc,  i * cxchar, j * cychar , pbuffer + x, 1);
    	  
          i++;
    	  x++;
    		
    	  if((char) wParam == '\r'){
    	  j++;		  
    	  i = 0;
    		
              
    	  }
    		
    	 
        
    		
    		 ReleaseDC(hwnd, hdc);
    		
    		  return 0;
         case WM_DESTROY:
    		 hdc = GetDC(hwnd);
    		 DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));
             ReleaseDC(hwnd, hdc);
    		// DeleteObject(hfont);
    		 
    	 if(ptextbuff)
    		 free(ptextbuffer);
    		 DeleteObject(hbrush);
    		 releasef();
             PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    Last edited by SAMSAM; 01-25-2003 at 09:59 AM.

  4. #4
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    Forget about that. but can anyone tell me why is my editbox not
    initializing(visible) i cant find no reason for it ?

    i checked hwndedit and it returns NULL , Baffled.

  5. #5
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    I got it , i fooled around with class name"edit"
    but the first question still stands.

    sunny days all.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input from file no white space characters
    By Dan17 in forum C++ Programming
    Replies: 5
    Last Post: 05-09-2006, 08:28 AM
  2. Unwanted characters keep appearing
    By sundeeptuteja in forum C++ Programming
    Replies: 10
    Last Post: 03-01-2003, 12:58 AM
  3. Characters in a txt file.
    By tay_highfield in forum C Programming
    Replies: 3
    Last Post: 01-31-2003, 09:19 AM
  4. printing non-ASCII characters (in unicode)
    By dbaryl in forum C Programming
    Replies: 1
    Last Post: 10-25-2002, 01:00 PM