Buttons Question in Window

This is a discussion on Buttons Question in Window within the Windows Programming forums, part of the Platform Specific Boards category; In Windows, how does the window/os know when a button has been clicked, or released? Does it just check the ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    220

    Buttons Question in Window

    In Windows, how does the window/os know when a button has been clicked, or released? Does it just check the position of the WM_LBUTTON when it checks for that?

    Also, how does a window know it's in focus/how does it know the tab order, and how can you modify both of these focuses?
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Windows is a message based OS. Everything communicates via messages. So yes, a control receives mouse messages.

    Kuphryn

  3. #3
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    You can use SetFocus() to move the focus around and SetWindowPos() to adjust the windows Z order.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Quote Originally Posted by kuphryn
    Windows is a message based OS. Everything communicates via messages. So yes, a control receives mouse messages.

    Kuphryn
    What I mean is, how does the window and the os know that a BUTTON (meaning like, an Ok button, a Cancel button, etc) has been pressed? I get the message basics of windows, but I don't get what messages (if any) are sent / dealt with when a button is pressed. That's what I'm wondering ^_^

    Btw thanks adrianx
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  5. #5
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    You have to make a whole new proc message for those. Like the WndProc one you defined for the window you have to make a similar one for the button and it will send the button press message(s) to that proc.

    EDIT: Or you could define something like IDN_PUSHBTN. This is if you are making a separate button in your window not in a dialog box. Then you call the CreateWindow function for the button. Here is an example of what a button's CreateWindow function looks like:
    Code:
    hwnd2=CreateWindowEx(WS_EX_CLIENTEDGE,"BUTTON","Click me!",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,x/2,y/2,75,25,hwnd,
    ID_PUSHBTN,hInstance,NULL);
    . The x and y variables are just my window's size so the button will be in the middle. To get the messages for the button, like if it is clicked, then call this in your window's message function. Example:
    Code:
    case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    case ID_PUSHBTN:
    MessageBox (NULL, "You clicked?" , "Clicked!", MB_ICONQUESTION);
    break;
    }
    return 0;
    Hope that helps!
    Last edited by jmd15; 03-09-2005 at 08:51 AM.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    So, lets say I wanted to emulate a button press, how would I get the value of that button? For instance, if I'm running a game and I want to auto login, and I want to click the 'login' button, lets say it was named ID_BTN_LOGIN or something.

    Are buttons child windows of the parent window? Meaning, could I just use FindWindowEx() and SendMessageEx() to simulate a key/mouse button press for that button (which in this case would be a child window) ?
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  7. #7
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Yes buttons are child windows.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    What about text box's? Is there any ehm...easy way to fill those?
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  9. #9
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Quote Originally Posted by Tronic
    What about text box's? Is there any ehm...easy way to fill those?
    SetWindowText() is pretty easy.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 09:23 AM
  2. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  3. Newbie question about creating a window
    By gozu in forum Windows Programming
    Replies: 1
    Last Post: 01-18-2007, 05:17 PM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 03:33 PM
  5. How to change window style at runtime?
    By Mr. Bitmap in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2002, 05:49 PM

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