Reputation: 33
I wish to display the characters from a character array onto a window using win32. The second parameter type is wrong. How can i solve this? Thanks
char data[5]="hello";
CreateWindow(TEXT("STATIC"), TEXT(data), WS_VISIBLE | WS_CHILD |
WS_BORDER|ES_AUTOVSCROLL,
10, 50,300,300,hWnd, (HMENU) none, NULL, NULL);
Upvotes: 1
Views: 2124
Reputation: 43331
const TCHAR* data = TEXT("hello"); // LPCTSTR
CreateWindow(TEXT("STATIC"), data, WS_VISIBLE | WS_CHILD |
WS_BORDER|ES_AUTOVSCROLL,
10, 50,300,300,hWnd, (HMENU) none, NULL, NULL);
Your code is not compiled in Unicode configuration. Using generic TCHAR type should solve the problem.
Another way, if data is char*
, using ATL conversion macros (http://msdn.microsoft.com/en-us/library/87zae4a3.aspx):
#include <atlstr.h>
const char* data = "hello";
CreateWindow(TEXT("STATIC"), CA2T(data), WS_VISIBLE | WS_CHILD |
WS_BORDER|ES_AUTOVSCROLL,
10, 50,300,300,hWnd, (HMENU) none, NULL, NULL);
And finally, for completeness, you can call ANSI API version explicitly:
const char* data = "hello";
CreateWindowA("STATIC", data, WS_VISIBLE | WS_CHILD |
WS_BORDER|ES_AUTOVSCROLL,
10, 50,300,300,hWnd, (HMENU) none, NULL, NULL);
Upvotes: 5