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:
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
std::string conversation[2] = {"hi","bye"};
cout<< conversation[0] <<endl;
cout<< conversation[1] <<endl;
}
This would first show "hi" on one line, and "bye" on the other.
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 :
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;
}
Focusing on the About section of the menu,
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:
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;
}
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);
wchar_t conversation[] = L"Hi";
switch (wmId)
{
case IDM_ABOUT:
::MessageBox(hWnd , conversation , _T("Title") , MB_OK);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
}
However, I don't know how to make wchar_t arrays.
When I try to make something along the lines of an array:
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;
}
I get the following error message:
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