?
Solved

How to display a message once the buttom is pressed>>??

Posted on 2003-03-19
6
Medium Priority
?
218 Views
Last Modified: 2010-04-15
Hi all,
       How to display message once a button is pressed>>?/
       Let says i want to display the message "hello" once the button "Click Me" is pressed>> ??
       Hope someone can help me..
       I not using MFC...
Thanks in advance
huochai
0
Comment
Question by:huochai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:frogger1999
ID: 8171287
Assuming that you know when the button is clicked you could just do this:

int MessageBox(
  NULL,          // handle of owner window
  "Hello",     // address of text in message box
  "Hello box",  // address of title of message box
  MB_OK          // style of message box
);


there are lots of other settings you can use like changing the window style to modal, putting in a standard system icon etc.

Just look up MessageBox on MSDN
0
 

Accepted Solution

by:
gotenks earned 80 total points
ID: 8171392
inside the window procedure

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
   switch (msg) {
      case WM_CREATE:
         ...
         break;
      case WM_COMMAND:
         switch (LOWORD(wParam)) {
            case BN_CLICKED:
               MessageBox(hwnd, "Hello", "Hello Message", MB_OK);
               break;
            // or you can do it here, assuming you know
            // your button id
            case UR_BTN_ID:
               MessageBox(hwnd, "Hello", "Click Me Button", MB_OK);
               break;
            ...
         }
         break;
   }

   return 0;
}

hope this will help.
0
 
LVL 1

Expert Comment

by:teleplayr
ID: 8173297
A slight corrections to gotenks' code.  BN_CLICKED will show up in the HIWORD of wParam, not the loword.  So if all you care about is clicks, you'd do:

case WM_COMMAND:
        if (HIWORD(wParam) == BN_CLICKED)
        {
              MessageBox(hwnd, "Hello", "Hello Message", MB_OK);
        }


To make sure the correct button was clicked:
case WM_COMMAND:
     switch(HIWORD(wParam))
     {
          case BN_CLICKED:
               switch(LOWORD(wParam))
               {
                    case IDC_MYBUTTON:
                         DoStuff();
                         break;
               }
               break;
     }

and so forth...

-Tele
0
 

Expert Comment

by:gotenks
ID: 8192034
sorry, and thanks for the correction, Tele.

gotenks
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10184807
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by gotenks.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question