Hi..I want to create a message box that displays the string from an array. Is it possible using MesasgeBox()?? I have tried passing the name of the array to the function but I looked around and found youd could pass only string to the function. So waht is the solution???
Secondly, I am using a switch case to respond to my messagebox but its not working. the code is:

#include<stdio.h>
#include<windows.h>
#pragma comment(lib,"user32.lib");
#include<string.h>

char abc[10] = "hello";
int msg_id;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{
    msg_id = MessageBox(NULL, *abc , L"MMI MESSAGE", MB_OKCANCEL);

	switch( msg_id )
	{
		case IDOK:
			return 1;
			break;
		case IDCANCEL:
			printf("%d",msg_id);
			return 0;
			break;
		default:
			return 2;
	}
	getchar();
}

I think the msg_id should get printed but its not. What am I doing wrong? Any advice would be appreciated.thanks..

You can not use printf() in a MS-Windows gui program. Why? because there is no console.

>>have tried passing the name of the array to the function but I looked around and found youd could pass only string to the function
MessageBox parameters are character arrays, not c++ strings. There are two versions of MessageBox() -- one that takes char* and the other for UNICODE that takes wchar_t*. If you are compiling for UNICODE then you will have to surround string literals with _T( or _TEXT( macro. For example: _TEXT("Hello");

Thanks for the reply..I believe I am using the unicode version..anyway..am trying to work it out including the changes you've mentioned...will post the result once I try it out. Thanks again.

ok..I have managed to pass a string and create a message box in win32..but since I cannot call that function from a dos C main..I was wondering..is there anyway to create a messagebox from your regular main?? I ahve looked around but it seems that it is not possible. You have to write your program in winmain if you want to do that. Is that correct?

There are many win32 api functions that can be called from plain C

#include <windows.h>

int main()
{
    MessageBox(NULL,"Hello World","Hello",MB_OK);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.