CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2005
    Location
    Canada Alberta
    Posts
    80

    button press recognized when window moved

    when I click on the title bar and drage my window to a new location, once it left go of the mouse buton it thinks I've hit the sutek button:
    Code:
    long FAR PASCAL WndProc (HWND myhwnd, UINT message, WPARAM wParam, LPARAM lParam)//Message Handling
    {
     switch (message)
     {
      case WM_CHAR:
       if (wParam == 27)
    	  PostQuitMessage(0);
       break;
      case WM_DESTROY: 
       PostQuitMessage(0);
       break;
     }
    
    if((LOWORD(wParam) == StopB)&&(message == BN_SETFOCUS))
     windowswitch = 0;
    
     switch (LOWORD(wParam))
      {
      case CancelB://if wParam is == button then the button associated was clicked
       PostQuitMessage(0);
       break;
      case AdverB:
       if(windowswitch!=1)
        windowswitch = 1;
       break;
      case BankB:
       if(windowswitch!=2)
        windowswitch = 2;
       break;
      case BlockB:
       if(windowswitch!=3)
        windowswitch = 3;
       break;
      case SutekB:
       if(windowswitch!=4)
        windowswitch = 4;
       break;
      case StopB:
       DestroyWindow(H);
       windowswitch = 0;
       break;
      }
     return(DefWindowProc(myhwnd,message,wParam,lParam));
    }
    In C, you merely shoot yourself in the foot.

    In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."

  2. #2
    Join Date
    May 2004
    Location
    Michigan, United States
    Posts
    457

    Re: button press recognized when window moved

    Was there a question in there somewhere? Just kidding.

    It looks like you've got two different SWITCH statements. The second one is run no matter what the message is! You are just testing a parameter of the message but you have no idea what that message even is.

    So, for every message Windows sends your WndProc, you test the low word of its WPARAM. Eventually (as you found out) you're bound to get a message with a similar parameter as your button click.

    I think you want:
    Code:
    switch (message)
    {
         case WM_COMMAND:
              switch (LOWORD(wParam))
              {
                   // Button cases here
              }
    
    ...
    }
    Better yet, combine it all under the first switch statement you're using.
    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  3. #3
    Join Date
    Mar 2005
    Location
    Canada Alberta
    Posts
    80

    Re: button press recognized when window moved

    I'll try that once I get home thanks

    oh and I created a static window that fills the main window, and when this is done the program looks to see if the main window is brought ot the foreground but for some reason clicking in the static window does not trigger this, I have to click on the title bar, do you know why?

    I'm detecting this with

    if(GetForgroundWindow() == mainwindow)
    windowswitch = 0;

    when window switch is zero it resets the menu display.
    In C, you merely shoot yourself in the foot.

    In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: button press recognized when window moved

    oh and I created a static window that fills the main window, and when this is done the program looks to see if the main window is brought ot the foreground but for some reason clicking in the static window does not trigger this, I have to click on the title bar, do you know why?
    Because you must explicity say the window subsystem that you want to be notified when user clickes into a static window. This get's enabled by passing SS_NOTIFY as a flag of the static control when using CreateWindow() or switching the proper flag in the resource editor when using resource based dialogs/windows.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  5. #5
    Join Date
    Mar 2005
    Location
    Canada Alberta
    Posts
    80

    Re: button press recognized when window moved

    lol I've seen that style too! just the name was a bit missleading, I thought it made the button flash or something.... didn't read what the SDK docs said
    In C, you merely shoot yourself in the foot.

    In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can't tell which are bitwise copies and which are just pointing at others and saying, "That's me, over there."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured