Problem mit EM_SETCHARFORMAT



  • Hi,

    und zwar moechte ich eine Textstelle in einem RichEditControll einfaerben. Mit diesem Code versuch ich das zz:

    void AddText(HWND hwnd, char *szTextIn, COLORREF crTextColour, COLORREF crBackColour)
    	{
    	   char *Text = (char *)malloc(lstrlen(szTextIn) + 5);
    	   CHARFORMAT2  CharFormat;
    	   int iTotalTextLength = GetWindowTextLength(hwnd);
    	   int iStartPos = iTotalTextLength;
    	   int iEndPos;
    	   int iRet;
    
    	   strcpy(Text, szTextIn);
    
    	   SendMessage(hwnd, EM_SETSEL, (WPARAM)(int)iTotalTextLength, (LPARAM)(int)iTotalTextLength);
    	   SendMessage(hwnd, EM_REPLACESEL, (WPARAM)(BOOL)FALSE, (LPARAM)(LPCSTR)Text);
    
    	   free(Text);
    
    	   memset(&CharFormat, 0, sizeof(CharFormat));
    	   CharFormat.cbSize      = sizeof(CHARFORMAT2);
    	   CharFormat.dwMask      = CFM_COLOR | CFM_BACKCOLOR;
    	   CharFormat.crTextColor = crTextColour;
    	   CharFormat.crBackColor = crBackColour;
    
    	   iEndPos = GetWindowTextLength(hwnd);
    
    	   iRet = (int)SendMessage(hwnd, EM_SETSEL, (WPARAM)(int)iStartPos, (LPARAM)(int)iEndPos);
    	   iRet = (int)SendMessage(hwnd, EM_SETCHARFORMAT, (WPARAM)(UINT)SCF_SELECTION, (LPARAM)&CharFormat);
    	   iRet = (int)SendMessage(hwnd, EM_HIDESELECTION, (WPARAM)(BOOL)TRUE, (LPARAM)(BOOL)0);
    
    	   SendMessage(hwnd, EM_LINESCROLL, (WPARAM)(int)0, (LPARAM)(int)1);
    	}
    }
    

    leider gibt EM_SETCHARFORMAT immer 0 zurueck und das SendMessage danach auch. Aber leider kommen ich auf den Fehler ned :(.
    Nur noch nebenbei ich erstelle einen Dialog in dem das REC drin is. Muss man da vielleicht bestimme Flags angeben. Und is Version 2.0

    gute nacht noch C0de4Fun


Anmelden zum Antworten