0

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..

2
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

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");

Edited by Ancient Dragon: n/a

0

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.

0

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?

0

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);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.