Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

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

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
huochai
Asked:
huochai
1 Solution
 
frogger1999Commented:
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
 
gotenksCommented:
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
 
teleplayrCommented:
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
 
gotenksCommented:
sorry, and thanks for the correction, Tele.

gotenks
0
 
jmcgOwnerCommented:
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

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now