Hello
I wish to know how to write a string array in a Win32 Application, not a console application.
In a console app, I would use the following code:
This would first show "hi" on one line, and "bye" on the other.Code:#include <iostream> #include <string> using namespace std; int main() { std::string conversation[2] = {"hi","bye"}; cout<< conversation[0] <<endl; cout<< conversation[1] <<endl; }
0 would point to "hi", 1 would point to "bye".
In the Win32 app, however, I have trouble using this method.
Looking at the menu portion of WndProc :
Focusing on the About section of the menu,Code:switch (message) { case WM_COMMAND: { wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); switch (wmId) { case IDM_ABOUT: ::MessageBox(hWnd , _T("Message") , _T("Title") , MB_OK); break; case IDM_EXIT: DestroyWindow(hWnd); break; }
if I do it this way, using the _T("") macro, it does work.
When I try using the same string array & pointer method as I do in console programming, I get errors.
My goal is to have something along the lines of:
I've tried using the wchar_t datatype instead. It works when I use it alone, such as in:Code:switch (message) { case WM_COMMAND: { wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); std::string conversation[2] = {"hi" , "bye"}; switch (wmId) { case IDM_ABOUT: ::MessageBox(hWnd , conversation[0] , conversation[1] , MB_OK); break; case IDM_EXIT: DestroyWindow(hWnd); break; }
However, I don't know how to make wchar_t arrays.Code:switch (message) { case WM_COMMAND: { wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); wchar_t conversation[] = L"Hi"; switch (wmId) { case IDM_ABOUT: ::MessageBox(hWnd , conversation , _T("Title") , MB_OK); break; case IDM_EXIT: DestroyWindow(hWnd); break; }
When I try to make something along the lines of an array:
I get the following error message:Code:switch (message) { case WM_COMMAND: { wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); wchar_t conversation[] = {L"Hi",L"Bye"}; switch (wmId) { case IDM_ABOUT: ::MessageBox(hWnd , conversation[0] , _T("Title") , MB_OK); break; case IDM_EXIT: DestroyWindow(hWnd); break; }
error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'wchar_t' to 'LPCWSTR'
Does anyone know how to use strings as one would in a console application?
Compiler is Visual C++ 2008 Express Edition
Thanks in advance![]()



LinkBack URL
About LinkBacks





