From 58b007b0b7731f4b8ec6182a34e06205a8b09111 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 9 Dec 2009 18:53:35 +0100 Subject: [PATCH] clock: Convert to Unicode. --- programs/clock/Makefile.in | 1 + programs/clock/main.c | 77 +++++++++++++++++++------------------- programs/clock/main.h | 2 +- programs/clock/winclock.c | 29 +++++++------- programs/clock/winclock.h | 2 +- 5 files changed, 56 insertions(+), 55 deletions(-) diff --git a/programs/clock/Makefile.in b/programs/clock/Makefile.in index 1667416d1e0..1a239a555a6 100644 --- a/programs/clock/Makefile.in +++ b/programs/clock/Makefile.in @@ -5,6 +5,7 @@ VPATH = @srcdir@ MODULE = clock.exe APPMODE = -mwindows IMPORTS = comdlg32 shell32 user32 gdi32 kernel32 +EXTRADEFS = -DWINE_NO_UNICODE_MACROS C_SRCS = \ main.c \ diff --git a/programs/clock/main.c b/programs/clock/main.c index 55a9676d25f..752c93bf14b 100644 --- a/programs/clock/main.c +++ b/programs/clock/main.c @@ -38,18 +38,18 @@ CLOCK_GLOBALS Globals; static VOID WineLicense(HWND Wnd) { - char cap[20], text[1024]; - LoadString(Globals.hInstance, IDS_LICENSE, text, sizeof text); - LoadString(Globals.hInstance, IDS_LICENSE_CAPTION, cap, sizeof cap); - MessageBox(Wnd, text, cap, MB_ICONINFORMATION | MB_OK); + WCHAR cap[20], text[1024]; + LoadStringW(Globals.hInstance, IDS_LICENSE, text, sizeof(text)/sizeof(WCHAR)); + LoadStringW(Globals.hInstance, IDS_LICENSE_CAPTION, cap, sizeof(cap)/sizeof(WCHAR)); + MessageBoxW(Wnd, text, cap, MB_ICONINFORMATION | MB_OK); } static VOID WineWarranty(HWND Wnd) { - char cap[20], text[1024]; - LoadString(Globals.hInstance, IDS_WARRANTY, text, sizeof text); - LoadString(Globals.hInstance, IDS_WARRANTY_CAPTION, cap, sizeof cap); - MessageBox(Wnd, text, cap, MB_ICONEXCLAMATION | MB_OK); + WCHAR cap[20], text[1024]; + LoadStringW(Globals.hInstance, IDS_WARRANTY, text, sizeof(text)/sizeof(WCHAR)); + LoadStringW(Globals.hInstance, IDS_WARRANTY_CAPTION, cap, sizeof(cap)/sizeof(WCHAR)); + MessageBoxW(Wnd, text, cap, MB_ICONEXCLAMATION | MB_OK); } static VOID CLOCK_UpdateMenuCheckmarks(VOID) @@ -81,13 +81,13 @@ static VOID CLOCK_UpdateMenuCheckmarks(VOID) static VOID CLOCK_UpdateWindowCaption(VOID) { - CHAR szCaption[MAX_STRING_LEN]; + WCHAR szCaption[MAX_STRING_LEN]; int chars = 0; /* Set frame caption */ if (Globals.bDate) { - chars = GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, NULL, NULL, - szCaption, sizeof(szCaption)); + chars = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, NULL, NULL, + szCaption, sizeof(szCaption)/sizeof(WCHAR)); if (chars) { --chars; szCaption[chars++] = ' '; @@ -96,8 +96,8 @@ static VOID CLOCK_UpdateWindowCaption(VOID) szCaption[chars] = '\0'; } } - LoadString(0, IDS_CLOCK, szCaption + chars, sizeof(szCaption) - chars); - SetWindowText(Globals.hMainWnd, szCaption); + LoadStringW(0, IDS_CLOCK, szCaption + chars, MAX_STRING_LEN - chars); + SetWindowTextW(Globals.hMainWnd, szCaption); } /*********************************************************************** @@ -119,9 +119,10 @@ static BOOL CLOCK_ResetTimer(void) period = 1000; if (!SetTimer (Globals.hMainWnd, TIMER_ID, period, NULL)) { - CHAR szApp[MAX_STRING_LEN]; - LoadString(Globals.hInstance, IDS_CLOCK, szApp, sizeof(szApp)); - MessageBox(0, "No available timers", szApp, MB_ICONEXCLAMATION | MB_OK); + static const WCHAR notimersW[] = {'N','o',' ','a','v','a','i','l','a','b','l','e',' ','t','i','m','e','r','s',0}; + WCHAR szApp[MAX_STRING_LEN]; + LoadStringW(Globals.hInstance, IDS_CLOCK, szApp, MAX_STRING_LEN); + MessageBoxW(0, notimersW, szApp, MB_ICONEXCLAMATION | MB_OK); return FALSE; } return TRUE; @@ -151,15 +152,15 @@ static VOID CLOCK_ResetFont(VOID) */ static VOID CLOCK_ChooseFont(VOID) { - LOGFONT lf; - CHOOSEFONT cf; + LOGFONTW lf; + CHOOSEFONTW cf; memset(&cf, 0, sizeof(cf)); lf = Globals.logfont; cf.lStructSize = sizeof(cf); cf.hwndOwner = Globals.hMainWnd; cf.lpLogFont = &lf; cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT; - if (ChooseFont(&cf)) { + if (ChooseFontW(&cf)) { Globals.logfont = lf; CLOCK_ResetFont(); } @@ -172,7 +173,7 @@ static VOID CLOCK_ChooseFont(VOID) static VOID CLOCK_ToggleTitle(VOID) { /* Also shows/hides the menu */ - LONG style = GetWindowLong(Globals.hMainWnd, GWL_STYLE); + LONG style = GetWindowLongW(Globals.hMainWnd, GWL_STYLE); if ((Globals.bWithoutTitle = !Globals.bWithoutTitle)) { style = (style & ~WS_OVERLAPPEDWINDOW) | WS_POPUP|WS_THICKFRAME; SetMenu(Globals.hMainWnd, 0); @@ -182,7 +183,7 @@ static VOID CLOCK_ToggleTitle(VOID) SetMenu(Globals.hMainWnd, Globals.hMainMenu); 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, SWP_DRAWFRAME|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER); @@ -215,8 +216,8 @@ static VOID CLOCK_ToggleOnTop(VOID) static int CLOCK_MenuCommand (WPARAM wParam) { - CHAR szApp[MAX_STRING_LEN]; - CHAR szAppRelease[MAX_STRING_LEN]; + WCHAR szApp[MAX_STRING_LEN]; + WCHAR szAppRelease[MAX_STRING_LEN]; switch (wParam) { /* switch to analog */ case IDM_ANALOG: { @@ -279,9 +280,9 @@ static int CLOCK_MenuCommand (WPARAM wParam) } /* show "about" box */ case IDM_ABOUT: { - LoadString(Globals.hInstance, IDS_CLOCK, szApp, sizeof(szApp)); - lstrcpy(szAppRelease,szApp); - ShellAbout(Globals.hMainWnd, szApp, szAppRelease, 0); + LoadStringW(Globals.hInstance, IDS_CLOCK, szApp, sizeof(szApp)/sizeof(WCHAR)); + lstrcpyW(szAppRelease,szApp); + ShellAboutW(Globals.hMainWnd, szApp, szAppRelease, 0); break; } } @@ -341,7 +342,7 @@ static LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM switch (msg) { /* L button drag moves the window */ case WM_NCHITTEST: { - LRESULT ret = DefWindowProc (hWnd, msg, wParam, lParam); + LRESULT ret = DefWindowProcW(hWnd, msg, wParam, lParam); if (ret == HTCLIENT) ret = HTCAPTION; return ret; @@ -398,7 +399,7 @@ static LRESULT WINAPI CLOCK_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM } default: - return DefWindowProc (hWnd, msg, wParam, lParam); + return DefWindowProcW(hWnd, msg, wParam, lParam); } 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) { MSG msg; - WNDCLASS class; + WNDCLASSW class; - static const char szClassName[] = "CLClass"; /* To make sure className >= 0x10000 */ - static const char szWinName[] = "Clock"; + static const WCHAR szClassName[] = {'C','L','C','l','a','s','s',0}; + static const WCHAR szWinName[] = {'C','l','o','c','k',0}; /* Setup Globals */ 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.cbWndExtra = 0; class.hInstance = hInstance; - class.hIcon = LoadIcon (0, IDI_APPLICATION); - class.hCursor = LoadCursor (0, IDC_ARROW); + class.hIcon = LoadIconW(0, (LPCWSTR)IDI_APPLICATION); + class.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW); class.hbrBackground = 0; class.lpszMenuName = 0; class.lpszClassName = szClassName; } - if (!RegisterClass (&class)) return FALSE; + if (!RegisterClassW(&class)) return FALSE; 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, Globals.MaxX, Globals.MaxY, 0, 0, hInstance, 0); @@ -446,7 +447,7 @@ int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show if (!CLOCK_ResetTimer()) return FALSE; - Globals.hMainMenu = LoadMenu(0, MAKEINTRESOURCE(MAIN_MENU)); + Globals.hMainMenu = LoadMenuW(0, MAKEINTRESOURCEW(MAIN_MENU)); SetMenu(Globals.hMainWnd, Globals.hMainMenu); CLOCK_UpdateMenuCheckmarks(); CLOCK_UpdateWindowCaption(); @@ -454,9 +455,9 @@ int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show ShowWindow (Globals.hMainWnd, show); UpdateWindow (Globals.hMainWnd); - while (GetMessage(&msg, 0, 0, 0)) { + while (GetMessageW(&msg, 0, 0, 0)) { TranslateMessage(&msg); - DispatchMessage(&msg); + DispatchMessageW(&msg); } KillTimer(Globals.hMainWnd, TIMER_ID); diff --git a/programs/clock/main.h b/programs/clock/main.h index 98a8be33b3e..ce4dc33fb02 100644 --- a/programs/clock/main.h +++ b/programs/clock/main.h @@ -25,7 +25,7 @@ typedef struct { - LOGFONT logfont; + LOGFONTW logfont; HFONT hFont; HANDLE hInstance; HWND hMainWnd; diff --git a/programs/clock/winclock.c b/programs/clock/winclock.c index 5b534577fb8..34d18ddac22 100644 --- a/programs/clock/winclock.c +++ b/programs/clock/winclock.c @@ -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; - LOGFONT lf; + LOGFONTW lf; double xscale, yscale; HFONT oldFont, newFont; - CHAR szTime[255]; + WCHAR szTime[255]; int chars; - chars = GetTimeFormat(LOCALE_USER_DEFAULT, bSeconds ? 0 : TIME_NOSECONDS, NULL, - NULL, szTime, sizeof (szTime)); + chars = GetTimeFormatW(LOCALE_USER_DEFAULT, bSeconds ? 0 : TIME_NOSECONDS, NULL, + NULL, szTime, sizeof(szTime)/sizeof(WCHAR)); if (!chars) return 0; @@ -199,14 +199,14 @@ HFONT SizeFont(HDC dc, int x, int y, BOOL bSeconds, const LOGFONT* font) x -= 2 * SHADOW_DEPTH; y -= 2 * SHADOW_DEPTH; - oldFont = SelectObject(dc, CreateFontIndirect(&lf)); - GetTextExtentPoint(dc, szTime, chars, &extent); + oldFont = SelectObject(dc, CreateFontIndirectW(&lf)); + GetTextExtentPointW(dc, szTime, chars, &extent); DeleteObject(SelectObject(dc, oldFont)); xscale = (double)x/extent.cx; yscale = (double)y/extent.cy; lf.lfHeight *= min(xscale, yscale); - newFont = CreateFontIndirect(&lf); + newFont = CreateFontIndirectW(&lf); return newFont; } @@ -215,26 +215,25 @@ void DigitalClock(HDC dc, int x, int y, BOOL bSeconds, HFONT font) { SIZE extent; HFONT oldFont; - CHAR szTime[255]; + WCHAR szTime[255]; int chars; - chars = GetTimeFormat(LOCALE_USER_DEFAULT, bSeconds ? 0 : TIME_NOSECONDS, NULL, - NULL, szTime, sizeof (szTime)); + chars = GetTimeFormatW(LOCALE_USER_DEFAULT, bSeconds ? 0 : TIME_NOSECONDS, NULL, + NULL, szTime, sizeof(szTime)/sizeof(WCHAR)); if (!chars) return; --chars; oldFont = SelectObject(dc, font); - GetTextExtentPoint(dc, szTime, chars, &extent); + GetTextExtentPointW(dc, szTime, chars, &extent); SetBkColor(dc, BackgroundColor); SetTextColor(dc, ShadowColor); - TextOut(dc, (x - extent.cx)/2 + SHADOW_DEPTH, (y - extent.cy)/2 + SHADOW_DEPTH, - szTime, chars); + TextOutW(dc, (x - extent.cx)/2 + SHADOW_DEPTH, (y - extent.cy)/2 + SHADOW_DEPTH, szTime, chars); SetBkMode(dc, TRANSPARENT); 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); } diff --git a/programs/clock/winclock.h b/programs/clock/winclock.h index bcd26374f8e..b5fd715f0a7 100644 --- a/programs/clock/winclock.h +++ b/programs/clock/winclock.h @@ -22,5 +22,5 @@ */ 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);