Thread: Stupid buttons...

  1. #1
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227

    Stupid buttons...

    Ok, I'm trying to let the user move the button while they've clicked it and hold their mouse button down, I've tested the BN_SETFOCUS message (I needed something that was sent BEFORE the user depressed the mouse button) to see if it was sent, and it is. Also, I've checked hTemp to make sure it has the button's hWnd, and it does...and I can't for the life of me see the problem with the code. Someone help me out here, I'm racking my brains to death.

    Code:
    	case WM_COMMAND:
    		switch(HIWORD(wParam))
    		{
    		case BN_SETFOCUS:
    			bdrag = true;
    			hTemp = (HWND)lParam;
    			break;
    		}
    		return 0;
    	case WM_LBUTTONUP:
    		bdrag = false;
    		return 0;
    	case WM_MOUSEMOVE:
    		if(bdrag == true)
    			MoveWindow(hTemp, mX, mY, 80, 60, TRUE);
    		return 0;
    In theory that should work (yeah, and the mX and mY variables DO contain the right mouse info)

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>In theory that should work <<

    Have to agree with you. Some alternative suggestions:

    1. Try using SetWindowPos instead of MoveWindow and see if that makes a difference.
    2. Invalidate the parent.

    As you can tell, i'm guessing wildly...

  3. #3
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    SetWindowPos() didn't make any difference (at least visibly, I guess. but that's where it all counts ), and the TRUE at the end of MoveWindow() invalidates the parent for you...

    Hmm...this is a thinker.

    Thanks for the help, though.

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Just out of sheer (sp?) curiosity, maybe you should handle the WM_MOUSEDOWN instead of the BS_SETFOCUS. I don't really understand why you don't just use mousedown. I'd work with that message and see if that works.
    1978 Silver Anniversary Corvette

  5. #5
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    Well, see for that it'd be a helluvalot more work. I'd have to keep check to see if the click was in any button on the window (there can be up to 50!) then figure out some odd way to get the handle.

    This is for a windows designer that outputs pure API code, if you're wondering why anyone would want to do these things

    ArgX! I might wind up with the MOUSEDOWN method, though...I sure hope it doesn't come to that.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Got it!

    You have to give your button the BS_NOTIFY style in order for it to send BN_SETFOCUS msg to its parent.

    I couldn't shake the damn button free from the mouse after that...
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Originally posted by Ken Fitlike
    Got it!

    You have to give your button the BS_NOTIFY style in order for it to send BN_SETFOCUS msg to its parent.

    I couldn't shake the damn button free from the mouse after that...
    Why? I didn't know that was necessary. Well, anyway, good job Ken Fitlike!
    1978 Silver Anniversary Corvette

  8. #8
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    You might find this handy.

    for any child window that you want dragged around their parent, just handle the WM_LBUTTONDOWN message and do this:

    SendMessage(childWindowHandle, 0xF012, 0, 0);

    this does the default "window dragging behaviour"

    hope this helps.
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  9. #9
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You might find this handy....SendMessage(childWindowHandle, 0xF012, 0, 0);
    Handy? Surely you jest. That's truly amazing! Where did you learn that one? Are there others?

    edit: actually, I just tried it and it didn't work.
    Last edited by Ken Fitlike; 02-18-2002 at 12:28 AM.

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Got it to work. I suspected it might have been WM_SYSCOMMAND flags and so it was. The syntax is:

    SendMessage(hChild,WM_SYSCOMMAND,0xF012,0);

    where hChild is the handle of the child wnd and 0xF012 is 'SC_MOVE + HTCAPTION=61458'. Call SendMessage in WM_LBUTTONDOWN.

    Thanks again, Uraldor, for the novel approach.

  11. #11
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    >You have to give your button the BS_NOTIFY style in order for it to send BN_SETFOCUS msg to its parent. <

    I had already done that! I told you I knew it sent the BN_SETFOCUS message ...But it still never dragged for me!


    >>You might find this handy.

    I'm gonna go try that out right now.. Sounds great, thanks a heap.

  12. #12
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    Ok, so it kinda works...I modified it to fit my purposes, and now again in theory this should work, but ti still isn't:

    Code:
    	case WM_COMMAND:
    		switch(HIWORD(wParam))
    		{
    		case BN_SETFOCUS:
    			SendMessage(hwnd, WM_LBUTTONDOWN, 0, lParam);
                                                    break;
    		}
    		return 0;
    	case WM_LBUTTONDOWN:
    		SendMessage((HWND)lParam,WM_SYSCOMMAND,0xF012,0); 
    		return 0;
    I thought it was pretty ingeneous...but it seems windows thought differently...any help HERE?
    Last edited by -KEN-; 02-18-2002 at 08:53 AM.

  13. #13
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Sub-class the cntrl and handle its WM_LBUTTONDOWN. That way the button always has the cursor attached and you don't need to bother with the focus etc.

    Sorry that the BS_NOTIFY/BN_SETFOCUS didn't work as it worked fine for me.

  14. #14
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    SendMessage(hChild,WM_SYSCOMMAND,0xF012,0);
    buggar.. i'm sorry about that... i saw the post and thought i'd pop it in quickly before heading home.... i should have checked my code first!! my apologies!!

    i hope its working for you now though.

    I'm sure there are other ones like that somewhere.. but it's just typical of microsoft not to document things like this!! I managed to find this hard coded value in the depths of a news group from late 1997 or somewhere around that time.. if i come up with more i'll be sure to let you know

    good luck!!
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  15. #15
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    >>Sub-class the cntrl

    I kinda get what you're saying, but I have no clue how to do it...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 04-09-2009, 02:31 AM
  2. Ownerdraw buttons (2)
    By maes in forum Windows Programming
    Replies: 7
    Last Post: 09-11-2003, 05:50 AM
  3. Radio Buttons in Visual C++ 6
    By Ripper1 in forum Windows Programming
    Replies: 22
    Last Post: 05-16-2003, 07:54 AM
  4. (Ken Fitlike) buttons
    By jdinger in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2002, 01:21 PM
  5. Grouping radio buttons
    By Bazz in forum Windows Programming
    Replies: 1
    Last Post: 08-28-2001, 07:15 AM