Thread: Button coordinates in dialog. Strange ?

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    35

    Button coordinates in dialog. Strange ?

    Hi,

    Today i was working on "PtInRect" api. I worked with a simple window and a button.

    And i saw that if mouse is over button then PtInRect is not capturing this. Then

    i changed "Button" to "Static" and this is working now. Now i wonder why?

    If i was working with keyboard focus events, i was try to use subclassing the button.

    But with mouse... can anybody explain this? The code is below.

    Code:
    // Project1
    //
    
    #include <windows.h>
    
    LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
    
    HINSTANCE hInstance;
    HWND hWindow;
    
    static  HWND  Button1; 
    #define   ID_Button1   100
    
    int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
    {
       WNDCLASS wc;
       MSG msg;
    
       if (!hPrevInst)
       {
          wc.lpszClassName="Project1Class";
          wc.lpfnWndProc=MainWndProc;
          wc.style=CS_OWNDC; // | CS_VREDRAW | CS_HREDRAW;
          wc.hInstance=hInst;
          wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
          wc.hCursor=LoadCursor(NULL, IDC_ARROW);
          wc.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
          wc.cbClsExtra=0;
          wc.cbWndExtra=0;
          RegisterClass(&wc);
       }
    
       hWindow=CreateWindow("Project1Class","Application",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,500,350,NULL,NULL,hInst,NULL);
       hInstance=hInst;
    
       ShowWindow(hWindow,nCmdShow);
       UpdateWindow(hWindow);
    
       while(GetMessage(&msg,NULL,0,0))
       {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
       }
    
       return msg.wParam;
    }
    
    LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam,LPARAM lParam)
    {
        static RECT	rect;
        static POINT point;
    
       switch(msg)
       {
          case WM_MOUSEMOVE:
              point.x = LOWORD(lParam);
              point.y = HIWORD(lParam);                          
          	
              ClientToScreen(hWnd, &point);
              GetWindowRect(Button1, &rect);
              
              if(PtInRect(&rect, point))
              {
              	SetWindowText(hWnd, "over button1");
              	return 1;
              }
              SetWindowText(hWnd, "over dialog");		
              return 1;   
       	case WM_CREATE:
    		Button1 = CreateWindowEx(0, "Static", "Button1", WS_VISIBLE | WS_CHILD , 81, 250, 105, 26, hWnd, (HMENU) ID_Button1, hInstance, NULL);
    		SendMessage(Button1, (UINT) WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), (LPARAM) MAKELPARAM(FALSE, 0));			 
    	                break;			 
          case WM_COMMAND:
             switch(LOWORD(wParam))
             {
                default:
                   return DefWindowProc(hWnd, msg, wParam, lParam);
             }
             break;
          case WM_DESTROY:
             PostQuitMessage(0);
             break;
          default:
             return(DefWindowProc(hWnd, msg, wParam, lParam));
       }
       return 0;
    }
    Want to learn? Then try to teach...

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    35
    OK. Replying myself. Maybe somebody needs
    On windows, buttons and other controls are like another window. We already know
    this if ever need to subclassing a window. The same approach.
    Shortly, if mouse is over a button(or others over the dialog or window) then
    WM_MOUSEMOVE message is no more will come to CALLBACK procedure which belongs to
    main window. So, we will never catch or modify something with this message in this
    CALLBACK. So needing to subclassing again. Then we can get the WM_MOUSEMOVE in this
    control's CALLBACK routine.

    Now, anyway, if somebody explain what is the difference between the STATIC and others
    about this manner. Doesnt static is a window too?
    Want to learn? Then try to teach...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  3. Remove dialog button border
    By RedZone in forum Windows Programming
    Replies: 4
    Last Post: 08-21-2006, 01:20 PM
  4. Click button on dialog box to open window.
    By ooosawaddee3 in forum Windows Programming
    Replies: 1
    Last Post: 11-29-2002, 08:53 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM