char * en LPCWSTR
Le
psykzix
Bonjour
Je m'exerce avec les applications win32 et j'ai un souci.
J'ai un affichage en caractères chinois avec le code suivant.
Il me semble que je ne parviens pas à convertir correctement le char *
en LPCWSTR. Je ne trouve pas de solution claire avec internet.
J'ai peut-être un problème avec les propriétés de mon projet. Je suis
sous visual C++ et XP.
Merci de votre aide!
le code :
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
HDC hDC;
PAINTSTRUCT paintst;
RECT rcClient;
LPCWSTR txt = L"Fenêtre";
LPCWSTR police = _T("Comic Sans MS");
switch (message)
{
case WM_TIMER:
rcClient.top=0;
rcClient.left=0;
rcClient.right0;
rcClient.bottomP;
RedrawWindow(hWnd,&rcClient,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_ERASENOW|RDW_NOCHILDREN);
return 0;
case WM_PAINT:
char buf[256];
SYSTEMTIME CurrentTime;
HFONT hFont;
hFont=CreateFont(36, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
police);
hDC¾ginPaint(hWnd,&paintst);
SelectObject(hDC,hFont);
GetLocalTime(&CurrentTime);
// Problème ici pour convertir char * en LPCWSTR
sprintf(buf,"%d : %d :
%d",CurrentTime.wHour,CurrentTime.wMinute,CurrentTime.wSecond);
TextOut(hDC,0,0,(LPCWSTR)buf,strlen(buf));
EndPaint(hWnd,&paintst);
DeleteObject(hFont);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
Je m'exerce avec les applications win32 et j'ai un souci.
J'ai un affichage en caractères chinois avec le code suivant.
Il me semble que je ne parviens pas à convertir correctement le char *
en LPCWSTR. Je ne trouve pas de solution claire avec internet.
J'ai peut-être un problème avec les propriétés de mon projet. Je suis
sous visual C++ et XP.
Merci de votre aide!
le code :
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
HDC hDC;
PAINTSTRUCT paintst;
RECT rcClient;
LPCWSTR txt = L"Fenêtre";
LPCWSTR police = _T("Comic Sans MS");
switch (message)
{
case WM_TIMER:
rcClient.top=0;
rcClient.left=0;
rcClient.right0;
rcClient.bottomP;
RedrawWindow(hWnd,&rcClient,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_ERASENOW|RDW_NOCHILDREN);
return 0;
case WM_PAINT:
char buf[256];
SYSTEMTIME CurrentTime;
HFONT hFont;
hFont=CreateFont(36, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
police);
hDC¾ginPaint(hWnd,&paintst);
SelectObject(hDC,hFont);
GetLocalTime(&CurrentTime);
// Problème ici pour convertir char * en LPCWSTR
sprintf(buf,"%d : %d :
%d",CurrentTime.wHour,CurrentTime.wMinute,CurrentTime.wSecond);
TextOut(hDC,0,0,(LPCWSTR)buf,strlen(buf));
EndPaint(hWnd,&paintst);
DeleteObject(hFont);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}

Poser une question


Tu te mélanges un peu les pinceaux avec Unicode/Ansi (comme tout le
monde...)
Tu peux faire, par exemple :
WCHAR buf[256];
puis
wsprintf(buf, _T("%d : %d :
%d"),CurrentTime.wHour,CurrentTime.wMinute,CurrentTime.wSecond);
TextOut(hDC,0,0,buf,lstrlen(buf));
(il manque aussi SetTimer() (ds WM_CREATE ) et le rcClient est trop
petit...)
Cela fonctionne maintenant mais je vais devoir revoir les différences
d'utilisation entre ANSI et UNICODE effectivement.
Je te remercie vivement!