Ejemplo n.º 1
0
LRESULT CMultiLineEditCanvasWnd::OnEditChanged(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
    if( m_pOwner == NULL ) return 0;
    // Rearrange the scrollbar
    int nLineCount = Edit_GetLineCount(m_pOwner->m_pWindow->GetHWND());
    if ((nLineCount > 0) && (m_pOwner->m_pWindow->GetVerticalScrollbar() != NULL))
    {
        SCROLLINFO si = {0};
        si.cbSize = sizeof(SCROLLINFO);
        si.fMask = SIF_ALL;
        if (GetScrollInfo(m_pOwner->m_pWindow->GetHWND(), SB_VERT, &si))
        {
            m_pOwner->m_pWindow->GetVerticalScrollbar()->SetEnabled((si.nMax >= static_cast<int>(si.nPage)));
            m_pOwner->m_pWindow->GetVerticalScrollbar()->SetScrollRange(si.nMax - si.nMin);
            m_pOwner->m_pWindow->GetVerticalScrollbar()->SetScrollPos(si.nPos);
        }
    }

    // Copy text back
    int cchLen = ::GetWindowTextLength(m_pOwner->m_pWindow->GetHWND()) + 1;
    LPTSTR pstr = static_cast<LPTSTR>(_alloca(cchLen * sizeof(TCHAR)));
    ASSERT(pstr);
    ::GetWindowText(m_pOwner->m_pWindow->GetHWND(), pstr, cchLen);
    m_pOwner->m_sText = pstr;
    m_pOwner->GetManager()->SendNotify(m_pOwner, _T("textchanged"));
    return 0;
}
Ejemplo n.º 2
0
void wlog(const char* buffer){
		char* buf;
	    int hloglen=GetWindowTextLength(hlog)+1;
	    int slen=strlen(buffer)+1;
		if(slen<30000){
		        buf= new char[2];//hloglen+slen+1];
		        buf = (char*)Mrealloc(buf,hloglen+slen+1);
				memset(buf,0,hloglen+slen+1);
				if((hloglen+slen)<30000)GetWindowText(hlog,buf,hloglen);
				else{
					char* tmpbuf=new char[2];tmpbuf = (char*)Mrealloc(tmpbuf,hloglen+1);GetWindowText(hlog,&tmpbuf[0],hloglen);
					//int oldsize;oldsize=sizeof(globallog);
					globallog = (char*)Mrealloc(globallog,hloglen+globallogsize+1);
					memcpy(&globallog[globallogsize],tmpbuf,hloglen-1);globallogsize+=hloglen;
				}
				lstrcat(buf,buffer);
				SetWindowText(hlog, buf);
				Edit_Scroll(hlog,Edit_GetLineCount(hlog),0);
				int wlen=GetWindowTextLength(hlog);
				Edit_SetSel(hlog,wlen-1,wlen);
				Edit_SetSel(hlog,wlen,wlen);
				SetFocus(hlog);
				ShowCaret(hlog);
				delete[] buf;
		}
}
Ejemplo n.º 3
0
/* Text suchen und selektieten Punkt übergeben  */
BOOL SearchText (char* pszKeyStr, POINT* pPoint) {

	register int i;
	int iEnd;
	char szLine [iMaxLineLength];
	char *pszAktPos;
	int iStart = HIWORD (Edit_GetSel (hEditWnd));
	int iLineNr = Edit_LineFromChar (hEditWnd, iStart);
	int iMaxLineNr = Edit_GetLineCount (hEditWnd);
	int iLineLength = Edit_LineLength (hEditWnd, iStart);

/*  1. (akt.) Zeile untersuchen */
	if (iLineLength) {
		for (i = 0; i < sizeof (szLine); i++)
			szLine [i] = '\0';
		GetFirstLine (szLine);
		if (pszAktPos = CompareStrings (szLine, pszKeyStr)) {
			iStart += pszAktPos - szLine;
			iEnd = iStart + strlen (pszKeyStr);
			pPoint->x = iStart; pPoint->y = iEnd;
			return (TRUE);
		}
		else
		   iStart += strlen (szLine) + 2; // einschl. 0D0A
	}
	else
		iStart += 2;

/* alle restlichen Zeilen untersuchen */
	for (++iLineNr; iLineNr < iMaxLineNr; iLineNr++) {
		if (iLineLength = Edit_LineLength (hEditWnd, iStart)) {
			for (i = 0; i < sizeof (szLine); i++)
				szLine [i] = '\0';
			Edit_GetLine (hEditWnd, iLineNr, szLine, sizeof (szLine) -1);
			if (pszAktPos = CompareStrings (szLine, pszKeyStr)) {
				iStart += pszAktPos - szLine;
				iEnd = iStart + strlen (pszKeyStr);
				pPoint->x = iStart; pPoint->y = iEnd;
				return (TRUE);
			}
			else
				iStart += iLineLength + 2;
		}
		else
			iStart += 2;
	}

/* Punkt auf ungültigen Wert setzen */
	pPoint->x = -1; pPoint->y = -1;
	return (FALSE);
}
Ejemplo n.º 4
0
LRESULT CMultiLineEditCanvasWnd::OnVScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
    int nLineCount = Edit_GetLineCount(m_pOwner->m_pWindow->GetHWND());
    if ((nLineCount > 0) && (m_pOwner != NULL) && (m_pOwner->m_pWindow->GetVerticalScrollbar() != NULL))
    {
        SCROLLINFO si = {0};
        si.cbSize = sizeof(SCROLLINFO);
        si.fMask = SIF_ALL;
        if (GetScrollInfo(m_pOwner->m_pWindow->GetHWND(), SB_VERT, &si))
        {
            m_pOwner->m_pWindow->GetVerticalScrollbar()->SetEnabled((si.nMax >= static_cast<int>(si.nPage)));
            m_pOwner->m_pWindow->GetVerticalScrollbar()->SetScrollRange(si.nMax - si.nMin);
            m_pOwner->m_pWindow->GetVerticalScrollbar()->SetScrollPos(si.nPos);
        }
    }
    return 0;
}
Ejemplo n.º 5
0
static void ResizeEditToFitText(HWND hEdit, HFONT hFont)
{
	HWND hParent = GetParent(hEdit);
	
	RECT edit_rect, dlg_rect;
	int num_lines, yincrease;
	
	if (!(GetWindowLong(hEdit, GWL_STYLE) & WS_VISIBLE))
		return;
	
	GetWindowRect(hEdit, &edit_rect);
	num_lines = Edit_GetLineCount(hEdit) + 1;
	yincrease = GetFontHeight(hFont) * num_lines - (edit_rect.bottom - edit_rect.top);
	
	GetWindowRect(hParent, &dlg_rect);
	yincrease = min(yincrease, GetSystemMetrics(SM_CYSCREEN) - dlg_rect.bottom + dlg_rect.top);
	yincrease = max(0, yincrease);
	MoveWindow(hParent, dlg_rect.left, dlg_rect.top, dlg_rect.right - dlg_rect.left, 
		dlg_rect.bottom - dlg_rect.top + yincrease, FALSE);
}
Ejemplo n.º 6
0
void CDialogManage::CTabSkins::ReadSkin()
{
	HWND item = GetDlgItem(m_Window, IDC_MANAGESKINS_FILE_TEXT);
	SetWindowText(item, m_SkinFileName.c_str());

	PathSetDlgItemPath(m_Window, IDC_MANAGESKINS_CONFIG_TEXT, m_SkinFolderPath.c_str());

	item = GetDlgItem(m_Window, IDC_MANAGESKINS_EDIT_BUTTON);
	EnableWindow(item, TRUE);

	std::wstring file = Rainmeter->GetSkinPath() + m_SkinFolderPath;
	file += L'\\';
	file += m_SkinFileName;
	m_SkinWindow = Rainmeter->GetMeterWindowByINI(file);
	if (!m_SkinWindow)
	{
		DisableControls();
	}

	SetControls();

	WCHAR* buffer = new WCHAR[MAX_LINE_LENGTH];

	item = GetDlgItem(m_Window, IDC_MANAGESKINS_AUTHOR_TEXT);
	GetPrivateProfileString(L"Rainmeter", L"Author", NULL, buffer, MAX_LINE_LENGTH, file.c_str());
	SetWindowText(item, buffer);

	item = GetDlgItem(m_Window, IDC_MANAGESKINS_ADDMETADATA_LINK);
	if (GetPrivateProfileSection(L"Metadata", buffer, 8, file.c_str()) > 0)
	{
		ShowWindow(item, SW_HIDE);

		// Set metadata
		item = GetDlgItem(m_Window, IDC_MANAGESKINS_VERSION_TEXT);
		GetPrivateProfileString(L"Metadata", L"Version", NULL, buffer, MAX_LINE_LENGTH, file.c_str());
		SetWindowText(item, buffer);

		item = GetDlgItem(m_Window, IDC_MANAGESKINS_LICENSE_TEXT);
		GetPrivateProfileString(L"Metadata", L"License", NULL, buffer, MAX_LINE_LENGTH, file.c_str());
		SetWindowText(item, buffer);

		item = GetDlgItem(m_Window, IDC_MANAGESKINS_DESCRIPTION_TEXT);
		std::wstring text;
		if (GetPrivateProfileString(L"Metadata", L"Information", NULL, buffer, MAX_LINE_LENGTH, file.c_str()) > 0)
		{
			text = buffer;
		}
		else
		{
			// For backwards compatibility
			GetPrivateProfileString(L"Metadata", L"Description", NULL, buffer, MAX_LINE_LENGTH, file.c_str());
			text = buffer;

			if (GetPrivateProfileString(L"Metadata", L"Instructions", NULL, buffer, MAX_LINE_LENGTH, file.c_str()) > 0)
			{
				text += L"\r\n\r\n";
				text += buffer;
			}
		}

		// Replace | with newline
		std::wstring::size_type pos;
		while ((pos = text.find_first_of(L'|')) != std::wstring::npos)
		{
			size_t count = (pos + 1 < text.length() && text[pos + 1] == L' ') ? 2 : 1;
			if (text[pos - 1] == L' ')
			{
				--pos;
				count += 1;
			}
			text.replace(pos, count, L"\r\n");
		}

		SetWindowText(item, text.c_str());

		int lines = Edit_GetLineCount(item);
		ShowScrollBar(item, SB_VERT, (BOOL)(lines > 6));
	}
	else
	{
		ShowWindow(item, SW_SHOWNORMAL);

		item = GetDlgItem(m_Window, IDC_MANAGESKINS_VERSION_TEXT);
		SetWindowText(item, L"");

		item = GetDlgItem(m_Window, IDC_MANAGESKINS_LICENSE_TEXT);
		SetWindowText(item, L"");

		item = GetDlgItem(m_Window, IDC_MANAGESKINS_DESCRIPTION_TEXT);
		SetWindowText(item, L"");
		ShowScrollBar(item, SB_VERT, FALSE);
	}

	delete [] buffer;
}
Ejemplo n.º 7
0
/*
 * ClientMsgBoxProc:  A substitute implementation of MessageBox's window procedure.
 *   We have 2 OK buttons and 2 Cancel buttons, to account for the case where one
 *   or the other is the default button.  We hide the buttons we don't need.
 */
BOOL CALLBACK ClientMsgBoxProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
   static MsgBoxStruct *s;
   char *icon = NULL, *temp;
   int style, button_style, num_lines, yincrease;
   HICON hIcon;
   HWND hEdit, hText;
   HWND hOK, hCancel, hOK2, hCancel2;
   HFONT hFont;
   RECT dlg_rect, edit_rect;

   switch (message)
   {
   case WM_ACTIVATE:
      CenterWindow(hDlg, GetParent(hDlg));
      break;
   case WM_SETFOCUS:
   case WM_WINDOWPOSCHANGING:
      SetFocus(hDlg);
      break;
   case WM_INITDIALOG:
      s = (MsgBoxStruct *) lParam;
      button_style = s->style & MB_TYPEMASK;
      hText = GetDlgItem(hDlg, IDC_TEXT);
      hOK = GetDlgItem(hDlg, IDOK);
      hCancel = GetDlgItem(hDlg, IDCANCEL);
      hOK2 = GetDlgItem(hDlg, IDOK2);
      hCancel2 = GetDlgItem(hDlg, IDCANCEL2);

      // Display text

      // Put text in invisible edit box to see how much space it will take
      hEdit = GetDlgItem(hDlg, IDC_EDIT);

      hFont = GetWindowFont(hText);
      SetWindowFont(hEdit, hFont, TRUE);
      SetWindowFont(hOK, hFont, FALSE);
      SetWindowFont(hCancel, hFont, FALSE);
      SetWindowFont(hOK2, hFont, FALSE);
      SetWindowFont(hCancel2, hFont, FALSE);
      SetWindowText(hEdit, s->text);

      Edit_GetRect(hEdit, &edit_rect);
      num_lines = Edit_GetLineCount(hEdit);

      // Count blank lines separately, since edit box not handling them correctly
      temp = s->text;
      do
      {
         temp = strstr(temp, "\n\n");
         if (temp != NULL)
         {
            num_lines++;
            temp += 2;
         }
      } while (temp != NULL);

      yincrease = GetFontHeight(hFont) * num_lines;

      // Resize dialog and text area
      GetWindowRect(hDlg, &dlg_rect);
      MoveWindow(hDlg, dlg_rect.left, dlg_rect.top, dlg_rect.right - dlg_rect.left, 
         dlg_rect.bottom - dlg_rect.top + yincrease, FALSE);
      ResizeDialogItem(hDlg, hText, &dlg_rect, RDI_ALL, False);

      // Move buttons; center OK button if it's the only one
      if (button_style == MB_OK)
      {
         ResizeDialogItem(hDlg, hOK, &dlg_rect, RDI_BOTTOM | RDI_HCENTER, False);
         ShowWindow(hCancel, SW_HIDE);
         ShowWindow(hCancel2, SW_HIDE);
      }
      else
      {
         ResizeDialogItem(hDlg, hOK, &dlg_rect, RDI_BOTTOM, False);
         ResizeDialogItem(hDlg, hCancel, &dlg_rect, RDI_BOTTOM, False);
         ResizeDialogItem(hDlg, hOK2, &dlg_rect, RDI_BOTTOM, False);
         ResizeDialogItem(hDlg, hCancel2, &dlg_rect, RDI_BOTTOM, False);
      }

      SetWindowText(hDlg, s->title);
      SetWindowText(hText, s->text);
      ShowWindow(hEdit, SW_HIDE);

      // Set icon to appropriate system icon
      style = s->style & MB_ICONMASK;
      if (style == MB_ICONSTOP)
         icon = IDI_HAND;
      else if (style == MB_ICONINFORMATION)
         icon = IDI_ASTERISK;
      else if (style == MB_ICONEXCLAMATION)
         icon = IDI_EXCLAMATION;
      else if (style == MB_ICONQUESTION)
         icon = IDI_QUESTION;

      if (icon != NULL)
      {
         hIcon = LoadIcon(NULL, icon);
         Static_SetIcon(GetDlgItem(hDlg, IDC_MSGBOXICON), hIcon);
      }

      // Display correct button text
      switch (button_style)
      {
      case MB_YESNO:
         SetWindowText(hOK, GetString(hInst, IDS_YES));
         SetWindowText(hCancel, GetString(hInst, IDS_NO));
         SetWindowText(hOK2, GetString(hInst, IDS_YES));
         SetWindowText(hCancel2, GetString(hInst, IDS_NO));
         break;
      }

      // Show correct button as default
      style = s->style & MB_DEFMASK;
      switch (style)
      {
      case MB_DEFBUTTON1:
      default:
         SetFocus(hOK);
         ShowWindow(hOK2, SW_HIDE);
         ShowWindow(hCancel, SW_HIDE);
         break;

      case MB_DEFBUTTON2:
         SetFocus(hCancel);
         ShowWindow(hOK, SW_HIDE);
         ShowWindow(hCancel2, SW_HIDE);
         break;
      }

      CenterWindow(hDlg, GetParent(hDlg));
      return 0;

   case WM_COMMAND:
      switch(GET_WM_COMMAND_ID(wParam, lParam))
      {
      case IDOK:
      case IDOK2:
         button_style = s->style & MB_TYPEMASK;
         if (button_style == MB_YESNO)
            EndDialog(hDlg, IDYES);
         else
            EndDialog(hDlg, IDOK);
         return TRUE;
      case IDCANCEL:
      case IDCANCEL2:
         button_style = s->style & MB_TYPEMASK;
         if (button_style == MB_YESNO)
            EndDialog(hDlg, IDNO);
         else
            EndDialog(hDlg, IDCANCEL);
         return TRUE;
      }
      break;
   }

   return FALSE;
}
Ejemplo n.º 8
0
static ErrNo GetMatrix(const HWND hwndEdit,double **pMatrix,const int nRows,const int nColumns)
{
	TCHAR	szBuffer_t[MAXSIZE];
	bool	data = false;
	TCHAR	seps[] = TEXT(" \t");
	TCHAR	*ptemp,*pstr,*pnext_token = NULL,*szBuffer = NULL;
	int		iLine,iLength,iStart,iCount;
	int		iMax = nColumns*20;							//缺憾 获取数据还是有限定的 每行字符个数不能超过iMax个

	szBuffer = new TCHAR[iMax];		//存储每一行获得的字符

	iLine = Edit_GetLineCount(hwndEdit);
	if(iLine == 1)											 //判断是否没有输入数据
	{
		if(!(iLength = Edit_GetText(hwndEdit,szBuffer,iMax)))
		{
			return NO_DATA_INPUT;
		}
	}
	else if(iLine<nRows)
	{
		return WRONG_MATRIX;
	}

	data = false;
	for(int i=0;i<iLine;i++)
	{
		iLength = Edit_GetLine(hwndEdit,i,szBuffer_t,MAXSIZE);
		if(iLength)				//找出第一个有数据的行
		{
			for(int j=0;j<iLength;j++)
			{
				if((szBuffer_t[j] >= TEXT('0') && szBuffer_t[j] <= TEXT('9')) || szBuffer_t[j] == TEXT('.'))
				{
					iStart = i;
					data = true;
					break;
				}
			}
			if(data)
				break;
		}
	}

	for(int i=iStart,k=0;i<iStart+nRows;i++,k++)			//获取每行数据
	{
		iCount = 0;
		iLength = Edit_GetLine(hwndEdit,i,szBuffer,iMax-1);
		szBuffer[iLength]=TEXT('\0');
		//字符串分割
		pstr = wcstok_s(szBuffer,seps,&pnext_token);
		while(pstr!=NULL)
		{
			if(*pstr == TEXT('+'))								//判断是否有分割行							
				return WRONG_MATRIX;	
			else if(!CharacterJudgement(pstr))					//判断是否非法字符输入
				return INCORRECT_DATA;
			if(iCount >= nColumns)								//判断每行输入数据个数是否超出限定矩阵维数
				return WRONG_MATRIX;
			pMatrix[k][iCount] = wcstod(pstr,&ptemp);
			pstr = wcstok_s(NULL,seps,&pnext_token);
			iCount++;
		}
		if(iCount != nColumns)
			return WRONG_MATRIX;
	}

	delete szBuffer;
	szBuffer = NULL;
	return 0;
}
Ejemplo n.º 9
0
void CPlugin::outputToNativeWindow(LPSTR szString)
{
  if (!m_hWndStandAloneLogWindow)
    return;

  // VERSION FOR EDIT BOX

  static char text[16384];

  if (strlen(szString)) {
    int length = Edit_GetTextLength(m_hWndStandAloneLogWindow);
    if ((length + strlen(szString)) > sizeof(text))
      strcpy(text, szString);
    else {
      Edit_GetText(m_hWndStandAloneLogWindow, text, sizeof(text));
      strcat(text, szString);
    }

    Edit_SetText(m_hWndStandAloneLogWindow, text);
    int lines = Edit_GetLineCount(m_hWndStandAloneLogWindow);
    Edit_Scroll(m_hWndStandAloneLogWindow, lines, 0);
  }
  else
    Edit_SetText(m_hWndStandAloneLogWindow, ""); // clear the window

/*
  // VERSION FOR LISTBOX

  // parse the string and add lines to the listbox
  char *p = 0;
  char *newline = szString;

  for (;;) {
    // could be either \r\n or \n, we don't need them at all for the listbox
    p = strchr(newline, '\n');
    if (!p)
      break;

    if (*(p - 1) == '\r')
      *(p - 1) = '\0';
    else
      *p = '\0';

    char line[512];
    strcpy(line, newline);

    ListBox_AddString(m_hWndStandAloneLogWindow, line);
    int count = ListBox_GetCount(m_hWndStandAloneLogWindow);
    if(count == 32767)
      ListBox_ResetContent(m_hWndStandAloneLogWindow);
    ListBox_SetCaretIndex(m_hWndStandAloneLogWindow, count - 1);
    UpdateWindow(m_hWndStandAloneLogWindow);

    // restore the original
    if (*p == '\n')
      *(p - 1) = '\r';
    else
      *p = '\n';

    newline = ++p;
  }
*/
}