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.