Button click out of WM_COMMAND

This is a discussion on Button click out of WM_COMMAND within the Windows Programming forums, part of the Platform Specific Boards category; Am having quite an issue with monitoring buttons click. I had to change a button's caption once it has been ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    37

    Button click out of WM_COMMAND

    Am having quite an issue with monitoring buttons click. I had to change a button's caption once it has been clicked..Thats fine.
    On button click a function is accessed and processing is done
    What I need to do is to use the same button to stop processing.....I need to use something like keydown but I have not been able to get to know what it should be..

    In fact the processing is in a 'while loop' so I wanted to place an if condition in there to detect the button's click and set a check state to 0 or 1 so that the loops stops...can anyone plz guide my search about monitoring button click out ot the WM_COMMAND messsage?

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    37
    I used this code, had no effect...any help?

    Code:
     
    
     lResult = SendMessage( IDC_ME,  
                                                       BM_GETSTATE,   
                                                       0,                                  
                                                       0 );       
         
            if(lResult==BST_PUSHED)
            check=1;

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Quote Originally Posted by Sober View Post
    What I need to do is to use the same button to stop processing.....I need to use something like keydown but I have not been able to get to know what it should be..
    I've used what's below before to use the same button to toggle different actions based on odd/even.

    Code:
    	case IDC_SCRIPT:
                {
                buttoncheck++;
    
                if(buttoncheck %2==0)
                {
                //Do something
                }
    
                    if(buttoncheck %2==1)
                     {
                     //Do something else
                     }
                }
                break;
    I'm certain there's more eloquent (or proper) methods of doing it, but it works. Although, I don't know what precisely it is that you're doing, so maybe it won't be of use to you.

    *Btw, I would've stuck to your earlier topic if I had seen it first. The Mods get somewhat annoyed when you start duplicate threads.
    Last edited by Oldman47; 05-01-2007 at 07:35 PM. Reason: oversight of thread content

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    37
    hmmm thx.. I dont in my case it can help.

    What I did is that I accessed a function to do some animations on the screen, like in a loop to keep on changing a BMP. its a while loop so I need to place an if condition in there, which verify for a button click in the message qeue, to alter the condition of the while loop so that this one changes and then other processing is done. I meant can we monitor button click outside the WM_COMMAND? , just like for virtual keys, you can monitor keydown at any point in your program.

    btw the function I used to do the animation is itself accessed from another function and other functions are accessed from there, else if I accessed only one function I guess I could do the animation and stop it at will..

    Any clue?

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Well, my knowledge is rather limited in scope. I still don't quite get your function within a function within a function call, but I don't think you can retrieve your button up/down status using BM_GETSTATE as I thought that was only useful for radio buttons.

  6. #6
    Registered User
    Join Date
    Apr 2007
    Posts
    37
    Actually I guessed the best way out in this case is multi threading.. I tried out ' _beginthread'
    and successfully managed to "unfreeze" the application and be able to click on the button again even though processing was undergo...

    But now the problem is about the point at which the button click changes a flag to stopthe processing done in a do-while loop...it seems to me that the loop is break through at any point ...and so I cannot use a vital information which has to be at updated level...suppose it is an operation progress for instance, well a\on the button click to cancel the progress, a messagebox has to be displayed to the user, indidcating the curent process an opitons....But when I retrieve the value from the respective variables, irrelevant data is obtained( if actual progress is 50%, 20% may be obtained ).

    I have ben trying for hours to access the functions involved in several ways so as to make sure that I get the last updated data but it has been no help...am so titred...can anyone plz help..if you did come accros such a problem before feel free to give me a guidance plz.

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    if threading look at 'critical sections', they allow only one thread to access your processing flag at a time.

    Normally I do this by modifing the message pump. Using PeekMessage() instead of GetMessage(). MFC may be able to use OnIdle().
    WaitMessage() may be helpful.

    GetMessage waits until your app has a msg and will not return until your app has a msg.
    PeekMessage just looks and returns with or without a msg.
    WaitMessage will suspend a thread until a msg arrives for it.

    If there is no msg for the app and enough time has passed since last screen update then redraw screen.

    Code:
    if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)>0)
    {
           //check for WM_QUIT
           //Translate and Dispatch
    }
    else update the screen ect
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    37
    So thats what you mean I think:


    Code:
       while( TRUE )
        {
            MSG msg;
    
            if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
            {
                // Check for a quit message
                if( msg.message == WM_QUIT )
                    break;
    
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }
            else
            {
                UpdateWindow(hwnd);
            }
        }
    I have tried it thinking it may solve yet another problem of mine...
    Actually in my applacaiton, I paint a BMP from a void function...
    and some others in the WM_PAINT case from the switch (Message)...

    When minimized and restored, only those BMP painted in the WM_PAINT are visible
    but not those from the void function....

    So I thought this message loop above would solve the problem
    but I guess am wrong at understanding something here....
    I mean which is related to the window's instance and the way the window is created...
    Can anyone bring me light?
    Last edited by Sober; 05-03-2007 at 09:35 AM.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Quote Originally Posted by Sober View Post

    Code:
             else
            {
                UpdateWindow(hwnd); I meant call your drawing method (which should redraw the screen and then call for a paint with InvalidateRect() / UpdateWindow()
            }
        }
    When minimized and restored, only those BMP painted in the WM_PAINT are visible
    but not those from the void function....
    You are drawing to the screen DC. any changes are not remembered.

    I have a screen buffer DC created with CreateCompatibleDC() / CreateCompatibleBitmap() ect.

    I draw everything this buffer DC.
    I then call for a paint (InvalidateRect() and UpdateWindow() )
    In the WM_PAINT I BitBlt() from the buffer DC to the DC in the PAINTSTRUCT (or returned from BeginPaint() ), using the RECT in the PAINTSTRUCT.

    Look for double buffering. Should be plenty of code posted here.....
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a function pointer from a button click event?
    By dxfoo in forum Windows Programming
    Replies: 20
    Last Post: 01-29-2008, 02:35 AM
  2. Updating window after button click?
    By ac251404 in forum Windows Programming
    Replies: 0
    Last Post: 07-18-2006, 10:20 AM
  3. Click button on dialog box to open window.
    By ooosawaddee3 in forum Windows Programming
    Replies: 1
    Last Post: 11-29-2002, 07:53 AM
  4. Replies: 6
    Last Post: 04-20-2002, 06:35 PM
  5. How To Change Caption's On A Button When It Is Click ?
    By SonicWave in forum Windows Programming
    Replies: 1
    Last Post: 09-19-2001, 02:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21