what the problem with this

Started by
37 comments, last by Crypter 16 years ago
but now another prob arised

even when i click my menu bar (new) it shows button pressed

actually i tried this


switch (message) /* handle the messages */
{



case WM_COMMAND:

switch( HIWORD(wParam) )
{
case BN_CLICKED:
MessageBox(hwnd,"button pressed","As",MB_ICONEXCLAMATION | MB_YESNO);
return 0;


}
switch( wParam )
{

case IDM_FILENEW:

// my rest of the code












how to correct it
thanks
Advertisement
Quote:Original post by MJP
A button, like most of the windows controls, sends notification messages to the parent window when events occur. When a button is clicked, it sends a WM_COMMAND message where the lower-order word of the wParam is the button's id, the higher-order word of wParam is BN_CLICKED, and lParam is a handle to the button.

See the documentation for more info.


If you want the control's ID, use the LOWORD macro.


but suppose i have more than 1 button on my window then how to find which one was pressed

thanks
any suggestions?
Quote:Original post by MJP
Quote:Original post by MJP
A button, like most of the windows controls, sends notification messages to the parent window when events occur. When a button is clicked, it sends a WM_COMMAND message where the lower-order word of the wParam is the button's id, the higher-order word of wParam is BN_CLICKED, and lParam is a handle to the button.

See the documentation for more info.


If you want the control's ID, use the LOWORD macro.


Look at this:

hBtn =  CreateWindow( "BUTTON",                      "a",                      WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,                      50, 50, 100, 25,                      hWnd,                      (HMENU)103,                      hInst,                      NULL );


That "103" right there: that's the ID you've assigned the button. When you get a WM_COMMAND message from a control, such as a button, the lower-order word of the wParam is this ID you've assigned the control. This is all covered in the documentation for WM_COMMAND, as well as in the documentation for the control notification messages. If you get this ID by using the LOWORD macro, you should be able to determine which control sent it.
thanks , it is now working
i wanted to know how to make a button having a bitmap image on it

i tried this
hBtn = CreateWindow("BUTTON","and",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_BITMAP ,
0,0,50,35,
hWnd,
(HMENU)103,
// NULL,
hInstance,NULL);

but now dont know how to proceed further?
how to do it
thanks
You've already specified the bitmap style, you just need to set which bitmap the button should use. You do this by sending the button a BM_SETIMAGE message.
i ahve already seen that but cant understood
can u give a example please

thanks
HANDLE hBitmap = LoadImage( hInstance, "buttonImage.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );SendMessage( hBtn, BM_SETIMAGE, IMAGE_BITMAP, hBitmap );

This topic is closed to new replies.

Advertisement