Thread: Word Wrap

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    96

    Word Wrap

    Ok I need some help getting word wrap to work. I saw a thread on this board where to get word wrap to work, you delete the edit control, and then recreate it based on if word wrap is on or off. I'm basically trying to do word wrap how notepad does it. Anyways here is my code:

    Code:
    #include <windows.h>
    #include "editcontrol.h"
    #include "wordwrap.h"
    
    CWordWrap::CWordWrap()
    {
    	
    }
    
    CWordWrap::~CWordWrap()
    {
    	
    }
    
    bool CWordWrap::DoWordWrap(HWND hParentWindow, int iWordWrapMenuID, CEditControl EditControl, DWORD dwStyleEx, DWORD dwStyle, int iX, int iY, 
                               int iWidth, int iHeight, HINSTANCE hInstance)
    {	
    	m_hMenu = GetMenu(hParentWindow);
    				
    	if(GetMenuState(m_hMenu, iWordWrapMenuID, MF_BYCOMMAND) == MF_CHECKED)
    	{		
    		m_bWordWrap = false;
    	}
    	
    	else
    	{		
    		m_bWordWrap = true;
    	}
    	
    	LockWindowUpdate(hParentWindow);	
    	
    	m_dwTextLength = GetWindowTextLength(EditControl.g_hEdit);
    	
    	m_pszFileText = new char[m_dwTextLength];
    	
    	if(!m_pszFileText)
    	{
    		MessageBox(hParentWindow, "Can't allocate memory!", "Error!",
    		           MB_ICONEXCLAMATION | MB_OK);
    		return false;
    	}
    	
    	GetWindowText(EditControl.g_hEdit, m_pszFileText, m_dwTextLength);
    		
    	DestroyWindow(EditControl.g_hEdit);
    	
    	EditControl.Create(dwStyleEx,
    		               dwStyle | (m_bWordWrap ? WS_HSCROLL | ES_AUTOHSCROLL : 0),
    		               iX,
                           iY,
    	                   iWidth,
    	                   iHeight, 
    		     	       hParentWindow,		     		                   
    		     	       hInstance);
    	
    	LockWindowUpdate(NULL);	
    	
    	SetFocus(EditControl.g_hEdit);
    	
    	SetWindowText(EditControl.g_hEdit, m_pszFileText);
    	
    	delete[] m_pszFileText;
    		
    	CheckMenuItem(m_hMenu, iWordWrapMenuID, (m_bWordWrap ? MF_CHECKED : MF_UNCHECKED));	
    		
    	return true;
    }
    Here is my edit control code:
    Code:
    #include <windows.h>
    #include "editcontrol.h"
    
    CEditControl::CEditControl()
    {
    	
    }
    
    CEditControl::~CEditControl()
    {
    	
    }
    
    bool CEditControl::Create(DWORD dwStyleEx, DWORD dwStyle, int iX, int iY, 
                              int iWidth, int iHeight, HWND hParentWindow, 
                              HINSTANCE hInstance)
    {	    
    	g_hEdit = CreateWindowEx(
    	          dwStyleEx,
    	          "EDIT",
    	          NULL,
    	          dwStyle,
    	          iX,
    	          iY,
    	          iWidth,
    	          iHeight,
    	          hParentWindow,
    	          (HMENU)g_iEditControlID,
    	          hInstance,
    	          NULL
    	          );
    
         if(!g_hEdit)
         {
         	MessageBox(hParentWindow, "Can't create edit control!", "Error!",
         	           MB_ICONEXCLAMATION | MB_OK);
         	return false;
         }    
    	          
    	SendMessage(g_hEdit, WM_SETFONT, 
    	            (WPARAM)GetStockObject(DEFAULT_GUI_FONT),
    	            MAKELPARAM(TRUE, 0));
    	            
    	return true && g_hEdit && g_iEditControlID;                    
    }
    In my message loop here is the call:
    Code:
    g_WordWrap.DoWordWrap(hwnd, IDM_FORMAT_WORDWRAP, g_EditControl, WS_EX_CLIENTEDGE,
    		     	                           WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN,
    		                                   CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
    	                                       CW_USEDEFAULT,  g_Window.g_hThisInstance);
    The function succuessfully completes it's job because EditContol.g_hEdit does not return 0. Unfortunately the edit control does not reappear on the screen.
    Last edited by sethjackson; 09-19-2005 at 04:10 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing to a file with word wrap?
    By Djanvk in forum C++ Programming
    Replies: 1
    Last Post: 08-17-2008, 05:09 AM
  2. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 06:44 PM
  5. Word Wrap
    By osal in forum Windows Programming
    Replies: 4
    Last Post: 07-02-2004, 11:16 AM