[BUG_FIXED] (Author: Jocelyn Legault) Fix a heap corruption of ColourPicker.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@681 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2010-10-16 13:31:33 +00:00
parent 7107532531
commit c8f5903ce5
5 changed files with 30 additions and 36 deletions

View File

@ -348,7 +348,7 @@ void RegExtDlg::writeNppPath()
TCHAR nppPath[MAX_PATH];
::GetModuleFileName(_hInst, nppPath, MAX_PATH);
TCHAR nppPathParam[256] = TEXT("\"");
TCHAR nppPathParam[MAX_PATH] = TEXT("\"");
lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\" \"%1\""));
::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR));
@ -377,7 +377,7 @@ void RegExtDlg::writeNppPath()
TCHAR nppPath[MAX_PATH];
::GetModuleFileName(_hInst, nppPath, MAX_PATH);
TCHAR nppPathParam[256] = TEXT("\"");
TCHAR nppPathParam[MAX_PATH] = TEXT("\"");
lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\",0"));
::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR));

View File

@ -1232,7 +1232,7 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, const FindOption *op
int flags = Searching::buildSearchFlags(pOptions);
(*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags);
//::SendMessageA(_hParent, WM_SETTEXT, 0, (LPARAM)pText);
int posFind = (*_ppEditView)->searchInTarget(pText, stringSizeFind, startPosition, endPosition);
if (posFind == -1) //no match found in target, check if a new target should be used
{

View File

@ -45,6 +45,16 @@ void ColourPicker::init(HINSTANCE hInst, HWND parent)
}
void ColourPicker::destroy()
{
if (_pColourPopup)
{
delete _pColourPopup;
_pColourPopup = NULL;
}
::DestroyWindow(_hSelf);
}
void ColourPicker::drawBackground(HDC hDC)
{
RECT rc;
@ -94,21 +104,25 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
case WM_LBUTTONDBLCLK :
case WM_LBUTTONDOWN :
{
RECT rc;
POINT p;
Window::getClientRect(rc);
::InflateRect(&rc, -2, -2);
p.x = rc.left;
p.y = rc.top + rc.bottom;
::ClientToScreen(_hSelf, &p);
if (!_pColourPopup)
{
RECT rc;
POINT p;
Window::getClientRect(rc);
::InflateRect(&rc, -2, -2);
p.x = rc.left;
p.y = rc.top + rc.bottom;
::ClientToScreen(_hSelf, &p);
_pColourPopup = new ColourPopup(_currentColour);
_pColourPopup->init(_hInst, _hSelf);
_pColourPopup->doDialog(p);
}
else
{
_pColourPopup->doDialog(p);
_pColourPopup->display(true);
}
return TRUE;
}
case WM_RBUTTONDOWN:
@ -141,9 +155,7 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
_currentColour = (COLORREF)wParam;
redraw();
_pColourPopup->destroy();
delete _pColourPopup;
_pColourPopup = NULL;
_pColourPopup->display(false);
::SendMessage(_hParent, WM_COMMAND, MAKELONG(0, CPN_COLOURPICKED), (LPARAM)_hSelf);
return TRUE;
}
@ -159,18 +171,8 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
}
case WM_PICKUP_CANCEL :
case WM_DESTROY :
{
if (_pColourPopup)
{
_pColourPopup->destroy();
delete _pColourPopup;
_pColourPopup = NULL;
return TRUE;
}
break;
}
_pColourPopup->display(false);
return TRUE;
default :
return ::CallWindowProc(_buttonDefaultProc, _hSelf, Message, wParam, lParam);

View File

@ -22,7 +22,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
class ColourPopup;
//#define CP_CLASS_NAME "colourPickerButton"
#define CPN_COLOURPICKED (BN_CLICKED)
class ColourPicker : public Window
@ -31,16 +30,12 @@ public :
ColourPicker() : Window(), _currentColour(RGB(0xFF, 0x00, 0x00)), _pColourPopup(NULL), _isEnabled(true) {};
~ColourPicker(){};
virtual void init(HINSTANCE hInst, HWND parent);
virtual void destroy() {
DestroyWindow(_hSelf);
};
virtual void destroy();
void setColour(COLORREF c) {
_currentColour = c;
//drawSelf();
};
COLORREF getColour() const {return _currentColour;};
bool isEnabled() {return _isEnabled;};
void setEnabled(bool enabled) {_isEnabled = enabled;};

View File

@ -87,10 +87,7 @@ BOOL CALLBACK ColourPopup::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara
{
::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_ADDSTRING, nColor, (LPARAM) "");
::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_SETITEMDATA , nColor, (LPARAM) colourItems[nColor]);
//if (g_bgColor == colourItems[nColor])
//::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_SETCURSEL, nColor, 0);
}
//::SetCapture(_hSelf);
return TRUE;
}