clock: Convert to Unicode.

This commit is contained in:
Alexandre Julliard 2009-12-09 18:53:35 +01:00
parent 305fcef612
commit 58b007b0b7
5 changed files with 56 additions and 55 deletions

View File

@ -5,6 +5,7 @@ VPATH = @srcdir@
MODULE = clock.exe MODULE = clock.exe
APPMODE = -mwindows APPMODE = -mwindows
IMPORTS = comdlg32 shell32 user32 gdi32 kernel32 IMPORTS = comdlg32 shell32 user32 gdi32 kernel32
EXTRADEFS = -DWINE_NO_UNICODE_MACROS
C_SRCS = \ C_SRCS = \
main.c \ main.c \

View File

@ -38,18 +38,18 @@ CLOCK_GLOBALS Globals;
static VOID WineLicense(HWND Wnd) static VOID WineLicense(HWND Wnd)
{ {
char cap[20], text[1024]; WCHAR cap[20], text[1024];
LoadString(Globals.hInstance, IDS_LICENSE, text, sizeof text); LoadStringW(Globals.hInstance, IDS_LICENSE, text, sizeof(text)/sizeof(WCHAR));
LoadString(Globals.hInstance, IDS_LICENSE_CAPTION, cap, sizeof cap); LoadStringW(Globals.hInstance, IDS_LICENSE_CAPTION, cap, sizeof(cap)/sizeof(WCHAR));
MessageBox(Wnd, text, cap, MB_ICONINFORMATION | MB_OK); MessageBoxW(Wnd, text, cap, MB_ICONINFORMATION | MB_OK);
} }
static VOID WineWarranty(HWND Wnd) static VOID WineWarranty(HWND Wnd)
{ {
char cap[20], text[1024]; WCHAR cap[20], text[1024];
LoadString(Globals.hInstance, IDS_WARRANTY, text, sizeof text); LoadStringW(Globals.hInstance, IDS_WARRANTY, text, sizeof(text)/sizeof(WCHAR));
LoadString(Globals.hInstance, IDS_WARRANTY_CAPTION, cap, sizeof cap); LoadStringW(Globals.hInstance, IDS_WARRANTY_CAPTION, cap, sizeof(cap)/sizeof(WCHAR));
MessageBox(Wnd, text, cap, MB_ICONEXCLAMATION | MB_OK); MessageBoxW(Wnd, text, cap, MB_ICONEXCLAMATION | MB_OK);
} }
static VOID CLOCK_UpdateMenuCheckmarks(VOID) static VOID CLOCK_UpdateMenuCheckmarks(VOID)
@ -81,13 +81,13 @@ static VOID CLOCK_UpdateMenuCheckmarks(VOID)
static VOID CLOCK_UpdateWindowCaption(VOID) static VOID CLOCK_UpdateWindowCaption(VOID)
{ {
CHAR szCaption[MAX_STRING_LEN]; WCHAR szCaption[MAX_STRING_LEN];
int chars = 0; int chars = 0;
/* Set frame caption */ /* Set frame caption */
if (Globals.bDate) { if (Globals.bDate) {
chars = GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, NULL, NULL, chars = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, NULL, NULL,
szCaption, sizeof(szCaption)); szCaption, sizeof(szCaption)/sizeof(WCHAR));
if (chars) { if (chars) {
--chars; --chars;
szCaption[chars++] = ' '; szCaption[chars++] = ' ';
@ -96,8 +96,8 @@ static VOID CLOCK_UpdateWindowCaption(VOID)
szCaption[chars] = '\0'; szCaption[chars] = '\0';
} }
} }
LoadString(0, IDS_CLOCK, szCaption + chars, sizeof(szCaption) - chars); LoadStringW(0, IDS_CLOCK, szCaption + chars, MAX_STRING_LEN - chars);
SetWindowText(Globals.hMainWnd, szCaption); SetWindowTextW(Globals.hMainWnd, szCaption);
} }
/*********************************************************************** /***********************************************************************
@ -119,9 +119,10 @@ static BOOL CLOCK_ResetTimer(void)
period = 1000; period = 1000;
if (!SetTimer (Globals.hMainWnd, TIMER_ID, period, NULL)) { if (!SetTimer (Globals.hMainWnd, TIMER_ID, period, NULL)) {
CHAR szApp[MAX_STRING_LEN]; static const WCHAR notimersW[] = {'N','o',' ','a','v','a','i','l','a','b','l','e',' ','t','i','m','e','r','s',0};
LoadString(Globals.hInstance, IDS_CLOCK, szApp, sizeof(szApp)); WCHAR szApp[MAX_STRING_LEN];
MessageBox(0, "No available timers", szApp, MB_ICONEXCLAMATION | MB_OK); LoadStringW(Globals.hInstance, IDS_CLOCK, szApp, MAX_STRING_LEN);
MessageBoxW(0, notimersW, szApp, MB_ICONEXCLAMATION | MB_OK);
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
@ -151,15 +152,15 @@ static VOID CLOCK_ResetFont(VOID)
*/ */
static VOID CLOCK_ChooseFont(VOID) static VOID CLOCK_ChooseFont(VOID)
{ {
LOGFONT lf; LOGFONTW lf;
CHOOSEFONT cf; CHOOSEFONTW cf;
memset(&cf, 0, sizeof(cf)); memset(&cf, 0, sizeof(cf));
lf = Globals.logfont; lf = Globals.logfont;
cf.lStructSize = sizeof(cf); cf.lStructSize = sizeof(cf);
cf.hwndOwner = Globals.hMainWnd; cf.hwndOwner = Globals.hMainWnd;
cf.lpLogFont = &lf; cf.lpLogFont = &lf;
cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT; cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
if (ChooseFont(&cf)) { if (ChooseFontW(&cf)) {
Globals.logfont = lf; Globals.logfont = lf;
CLOCK_ResetFont(); CLOCK_ResetFont();
} }
@ -172,7 +173,7 @@ static VOID CLOCK_ChooseFont(VOID)
static VOID CLOCK_ToggleTitle(VOID) static VOID CLOCK_ToggleTitle(VOID)
{ {
/* Also shows/hides the menu */ /* Also shows/hides the menu */
LONG style = GetWindowLong(Globals.hMainWnd, GWL_STYLE); LONG style = GetWindowLongW(Globals.hMainWnd, GWL_STYLE);
if ((Globals.bWithoutTitle = !Globals.bWithoutTitle)) { if ((Globals.bWithoutTitle = !Globals.bWithoutTitle)) {
style = (style & ~WS_OVERLAPPEDWINDOW) | WS_POPUP|WS_THICKFRAME; style = (style & ~WS_OVERLAPPEDWINDOW) | WS_POPUP|WS_THICKFRAME;
SetMenu(Globals.hMainWnd, 0); SetMenu(Globals.hMainWnd, 0);
@ -182,7 +183,7 @@ static VOID CLOCK_ToggleTitle(VOID)
SetMenu(Globals.hMainWnd, Globals.hMainMenu); SetMenu(Globals.hMainWnd, Globals.hMainMenu);
SetWindowRgn(Globals.hMainWnd, 0, TRUE); SetWindowRgn(Globals.hMainWnd, 0, TRUE);
} }
SetWindowLong(Globals.hMainWnd, GWL_STYLE, style); SetWindowLongW(Globals.hMainWnd, GWL_STYLE, style);
SetWindowPos(Globals.hMainWnd, 0,0,0,0,0, SetWindowPos(Globals.hMainWnd, 0,0,0,0,0,
SWP_DRAWFRAME|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER); SWP_DRAWFRAME|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER);
@ -215,8 +216,8 @@ static VOID CLOCK_ToggleOnTop(VOID)
static int CLOCK_MenuCommand (WPARAM wParam) static int CLOCK_MenuCommand (WPARAM wParam)
{ {
CHAR szApp[MAX_STRING_LEN]; WCHAR szApp[MAX_STRING_LEN];
CHAR szAppRelease[MAX_STRING_LEN]; WCHAR szAppRelease[MAX_STRING_LEN];
switch (wParam) { switch (wParam) {
/* switch to analog */ /* switch to analog */
case IDM_ANALOG: { case IDM_ANALOG: {
@ -279,9 +280,9 @@ static int CLOCK_MenuCommand (WPARAM wParam)
} }
/* show "about" box */ /* show "about" box */
case IDM_ABOUT: { case IDM_ABOUT: {
LoadString(Globals.hInstance, IDS_CLOCK, szApp, sizeof(szApp)); LoadStringW(Globals.hInstance, IDS_CLOCK, szApp, sizeof(szApp)/sizeof(WCHAR));
lstrcpy(szAppRelease,szApp); lstrcpyW(szAppRelease,szApp);
ShellAbout(Globals.hMainWnd, szApp, szAppRelease, 0); ShellAboutW(Globals.hMainWnd, szApp, szAppRelease, 0);
break; break;
} }
} }
@ -341,7 +342,7 @@ static LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM
switch (msg) { switch (msg) {
/* L button drag moves the window */ /* L button drag moves the window */
case WM_NCHITTEST: { case WM_NCHITTEST: {
LRESULT ret = DefWindowProc (hWnd, msg, wParam, lParam); LRESULT ret = DefWindowProcW(hWnd, msg, wParam, lParam);
if (ret == HTCLIENT) if (ret == HTCLIENT)
ret = HTCAPTION; ret = HTCAPTION;
return ret; return ret;
@ -398,7 +399,7 @@ static LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM
} }
default: default:
return DefWindowProc (hWnd, msg, wParam, lParam); return DefWindowProcW(hWnd, msg, wParam, lParam);
} }
return 0; return 0;
} }
@ -412,10 +413,10 @@ static LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show) int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
{ {
MSG msg; MSG msg;
WNDCLASS class; WNDCLASSW class;
static const char szClassName[] = "CLClass"; /* To make sure className >= 0x10000 */ static const WCHAR szClassName[] = {'C','L','C','l','a','s','s',0};
static const char szWinName[] = "Clock"; static const WCHAR szWinName[] = {'C','l','o','c','k',0};
/* Setup Globals */ /* Setup Globals */
memset(&Globals.hFont, 0, sizeof (Globals.hFont)); memset(&Globals.hFont, 0, sizeof (Globals.hFont));
@ -428,17 +429,17 @@ int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show
class.cbClsExtra = 0; class.cbClsExtra = 0;
class.cbWndExtra = 0; class.cbWndExtra = 0;
class.hInstance = hInstance; class.hInstance = hInstance;
class.hIcon = LoadIcon (0, IDI_APPLICATION); class.hIcon = LoadIconW(0, (LPCWSTR)IDI_APPLICATION);
class.hCursor = LoadCursor (0, IDC_ARROW); class.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
class.hbrBackground = 0; class.hbrBackground = 0;
class.lpszMenuName = 0; class.lpszMenuName = 0;
class.lpszClassName = szClassName; class.lpszClassName = szClassName;
} }
if (!RegisterClass (&class)) return FALSE; if (!RegisterClassW(&class)) return FALSE;
Globals.MaxX = Globals.MaxY = INITIAL_WINDOW_SIZE; Globals.MaxX = Globals.MaxY = INITIAL_WINDOW_SIZE;
Globals.hMainWnd = CreateWindow (szClassName, szWinName, WS_OVERLAPPEDWINDOW, Globals.hMainWnd = CreateWindowW(szClassName, szWinName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
Globals.MaxX, Globals.MaxY, 0, Globals.MaxX, Globals.MaxY, 0,
0, hInstance, 0); 0, hInstance, 0);
@ -446,7 +447,7 @@ int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show
if (!CLOCK_ResetTimer()) if (!CLOCK_ResetTimer())
return FALSE; return FALSE;
Globals.hMainMenu = LoadMenu(0, MAKEINTRESOURCE(MAIN_MENU)); Globals.hMainMenu = LoadMenuW(0, MAKEINTRESOURCEW(MAIN_MENU));
SetMenu(Globals.hMainWnd, Globals.hMainMenu); SetMenu(Globals.hMainWnd, Globals.hMainMenu);
CLOCK_UpdateMenuCheckmarks(); CLOCK_UpdateMenuCheckmarks();
CLOCK_UpdateWindowCaption(); CLOCK_UpdateWindowCaption();
@ -454,9 +455,9 @@ int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show
ShowWindow (Globals.hMainWnd, show); ShowWindow (Globals.hMainWnd, show);
UpdateWindow (Globals.hMainWnd); UpdateWindow (Globals.hMainWnd);
while (GetMessage(&msg, 0, 0, 0)) { while (GetMessageW(&msg, 0, 0, 0)) {
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessageW(&msg);
} }
KillTimer(Globals.hMainWnd, TIMER_ID); KillTimer(Globals.hMainWnd, TIMER_ID);

View File

@ -25,7 +25,7 @@
typedef struct typedef struct
{ {
LOGFONT logfont; LOGFONTW logfont;
HFONT hFont; HFONT hFont;
HANDLE hInstance; HANDLE hInstance;
HWND hMainWnd; HWND hMainWnd;

View File

@ -177,17 +177,17 @@ void AnalogClock(HDC dc, int x, int y, BOOL bSeconds, BOOL border)
} }
HFONT SizeFont(HDC dc, int x, int y, BOOL bSeconds, const LOGFONT* font) HFONT SizeFont(HDC dc, int x, int y, BOOL bSeconds, const LOGFONTW* font)
{ {
SIZE extent; SIZE extent;
LOGFONT lf; LOGFONTW lf;
double xscale, yscale; double xscale, yscale;
HFONT oldFont, newFont; HFONT oldFont, newFont;
CHAR szTime[255]; WCHAR szTime[255];
int chars; int chars;
chars = GetTimeFormat(LOCALE_USER_DEFAULT, bSeconds ? 0 : TIME_NOSECONDS, NULL, chars = GetTimeFormatW(LOCALE_USER_DEFAULT, bSeconds ? 0 : TIME_NOSECONDS, NULL,
NULL, szTime, sizeof (szTime)); NULL, szTime, sizeof(szTime)/sizeof(WCHAR));
if (!chars) if (!chars)
return 0; return 0;
@ -199,14 +199,14 @@ HFONT SizeFont(HDC dc, int x, int y, BOOL bSeconds, const LOGFONT* font)
x -= 2 * SHADOW_DEPTH; x -= 2 * SHADOW_DEPTH;
y -= 2 * SHADOW_DEPTH; y -= 2 * SHADOW_DEPTH;
oldFont = SelectObject(dc, CreateFontIndirect(&lf)); oldFont = SelectObject(dc, CreateFontIndirectW(&lf));
GetTextExtentPoint(dc, szTime, chars, &extent); GetTextExtentPointW(dc, szTime, chars, &extent);
DeleteObject(SelectObject(dc, oldFont)); DeleteObject(SelectObject(dc, oldFont));
xscale = (double)x/extent.cx; xscale = (double)x/extent.cx;
yscale = (double)y/extent.cy; yscale = (double)y/extent.cy;
lf.lfHeight *= min(xscale, yscale); lf.lfHeight *= min(xscale, yscale);
newFont = CreateFontIndirect(&lf); newFont = CreateFontIndirectW(&lf);
return newFont; return newFont;
} }
@ -215,26 +215,25 @@ void DigitalClock(HDC dc, int x, int y, BOOL bSeconds, HFONT font)
{ {
SIZE extent; SIZE extent;
HFONT oldFont; HFONT oldFont;
CHAR szTime[255]; WCHAR szTime[255];
int chars; int chars;
chars = GetTimeFormat(LOCALE_USER_DEFAULT, bSeconds ? 0 : TIME_NOSECONDS, NULL, chars = GetTimeFormatW(LOCALE_USER_DEFAULT, bSeconds ? 0 : TIME_NOSECONDS, NULL,
NULL, szTime, sizeof (szTime)); NULL, szTime, sizeof(szTime)/sizeof(WCHAR));
if (!chars) if (!chars)
return; return;
--chars; --chars;
oldFont = SelectObject(dc, font); oldFont = SelectObject(dc, font);
GetTextExtentPoint(dc, szTime, chars, &extent); GetTextExtentPointW(dc, szTime, chars, &extent);
SetBkColor(dc, BackgroundColor); SetBkColor(dc, BackgroundColor);
SetTextColor(dc, ShadowColor); SetTextColor(dc, ShadowColor);
TextOut(dc, (x - extent.cx)/2 + SHADOW_DEPTH, (y - extent.cy)/2 + SHADOW_DEPTH, TextOutW(dc, (x - extent.cx)/2 + SHADOW_DEPTH, (y - extent.cy)/2 + SHADOW_DEPTH, szTime, chars);
szTime, chars);
SetBkMode(dc, TRANSPARENT); SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, HandColor); SetTextColor(dc, HandColor);
TextOut(dc, (x - extent.cx)/2, (y - extent.cy)/2, szTime, chars); TextOutW(dc, (x - extent.cx)/2, (y - extent.cy)/2, szTime, chars);
SelectObject(dc, oldFont); SelectObject(dc, oldFont);
} }

View File

@ -22,5 +22,5 @@
*/ */
void AnalogClock(HDC dc, int X, int Y, BOOL bSeconds, BOOL border); void AnalogClock(HDC dc, int X, int Y, BOOL bSeconds, BOOL border);
HFONT SizeFont(HDC dc, int x, int y, BOOL bSeconds, const LOGFONT* font); HFONT SizeFont(HDC dc, int x, int y, BOOL bSeconds, const LOGFONTW* font);
void DigitalClock(HDC dc, int X, int Y, BOOL bSeconds, HFONT font); void DigitalClock(HDC dc, int X, int Y, BOOL bSeconds, HFONT font);