2013-05-17 42 views
0

這是我的嘗試,我不知道爲什麼EM_STREAMOUT遇到非ascii字符時會返回問號。如何從richedit控件中輸出廣泛的字符串?

此代碼從窗口中複製文本並將其重新放回,但這次僅作爲問號。

#include <windows.h> 
#include <iostream> 
#include <richedit.h> 
#include <string> 

static DWORD CALLBACK EditStreamOutCallback(unsigned long dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb) 
{ 
    using namespace std; 
    wstring* ps = (wstring*) dwCookie; 
    *pcb = cb; 
    for (long i = 0; i < cb; i++) { 
    ps->append(1,pbBuff[i]); 
    } 
    return 0; 
} 

int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE, LPTSTR, int /* nCmdShow*/) { 
    using namespace std; 

    LoadLibraryW(L"Msftedit.dll"); 
    HWND richeditWindow = CreateWindowExW (
    WS_EX_TOPMOST, 
    L"RICHEDIT50W", 
    L"施氏食獅史", 
    WS_SYSMENU | WS_VSCROLL | ES_MULTILINE | ES_NOHIDESEL | WS_VISIBLE, 
    50, 50, 500, 500, 
    NULL, NULL, NULL, NULL 
); 

    wstring s; 
    EDITSTREAM eds; 
    eds.dwCookie = (unsigned long) &s; 
    eds.dwError = 0; 
    eds.pfnCallback = EditStreamOutCallback; 
    SendMessageW(richeditWindow, EM_STREAMOUT, (WPARAM) SF_TEXTIZED, (LPARAM) &eds); 
    SendMessageW(richeditWindow, EM_REPLACESEL, FALSE, (LPARAM) s.c_str()); 

    MSG msg; 
    while(GetMessageW(&msg, 0, 0, 0)) { 
    TranslateMessage(&msg); 
    DispatchMessageW(&msg); 
    } 
    return 0; 
} 

回答

0

SendMessageW(SF_TEXTIZED richeditWindow,EM_STREAMOUT,(WPARAM)| SF_UNICODE,(LPARAM)&編);

相關問題