Thread: Winamp 5.55 SDK
View Single Post
Old 22nd November 2009, 15:36   #95
Ruzzz
Junior Member
 
Join Date: Nov 2009
Location: Ukraine
Posts: 24
DrO
code:
WNDPROC old_wnd_proc_A = NULL;
WNDPROC old_wnd_proc_W = NULL;

LRESULT CALLBACK WindowProcWrapperW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_SETTEXT) {

printf("WM_SETTEXT from Wide subclass as Wide: '%ws'", lParam);
printf("\n");

//wchar_t str[50];
char str[50];
WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)lParam, -1, str, 50, NULL, NULL);

printf("str from Wide subclass as Ansi: '%hs'", str);
printf("\n");

// We say that it ANSI,
// and if next window procedure wait Ansi - OS does not Unicode-to-ANSI conversion
// OS pays attention to the function CallWindowProc
return ::CallWindowProcA(old_wnd_proc_W, hwnd, uMsg, wParam, (LPARAM)&str);
} else
return ::CallWindowProcW(old_wnd_proc_W, hwnd, uMsg, wParam, lParam);
}

LRESULT CALLBACK WindowProcWrapperA(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

if (uMsg == WM_SETTEXT) {
printf("WM_SETTEXT from Ansi subclass as Ansi: '%hs'", lParam);
printf("\n");
}
// Call the last window procedure
// OS pays no attention to the function CallWindowProc!
// OS pays attention to SetWindowLongPtr for this(current) procedure
// CallWindowProcA or CallWindowProcW - No difference O_o
// It is important that correct data came in current procedure
return ::CallWindowProcA(old_wnd_proc_A, hwnd, uMsg, wParam, lParam);
}

int _tmain(int argc, _TCHAR* argv[])
{
HWND wnd = ::CreateWindowW(L"STATIC", L"foo", WS_VISIBLE|WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, NULL, NULL, NULL, 0);
//HWND wnd = ::CreateWindowA("STATIC", "foo", WS_VISIBLE|WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, NULL, NULL, NULL, 0);

//printf("IsWindowUnicode: '%d'\n", IsWindowUnicode(wnd));

old_wnd_proc_A = (WNDPROC)::GetWindowLongPtrA(wnd, GWLP_WNDPROC);
::SetWindowLongPtrA(wnd, GWLP_WNDPROC, (LONG_PTR)&WindowProcWrapperA);

old_wnd_proc_W = (WNDPROC)::GetWindowLongPtrW(wnd, GWLP_WNDPROC);
::SetWindowLongPtrW(wnd, GWLP_WNDPROC, (LONG_PTR)&WindowProcWrapperW);

::SendMessageA(wnd, WM_SETTEXT, 0, (LPARAM)"Ansi text");
::SendMessageW(wnd, WM_SETTEXT, 0, (LPARAM)L"Wide text");

MSG m;
while (::GetMessage(&m, NULL, 0, 0)) {
::TranslateMessage(&m);
::DispatchMessage(&m);
}

return 0;
}

Ruzzz is offline   Reply With Quote