我写的一个黑白棋子,用vc++写的,编译环境是s2010旗舰版,其中电脑下棋时需要向棋盘中指定坐标发送鼠标单击事件,用来模拟人单击鼠标放棋子,请问我如何实现?网上说貌似可以用Sendmessage(),可是我对里面的参数不是很理解,用的时候程序崩溃。谁能指教一下我应该怎么实现。刚刚学mfc,希望大家说的详细点,最好给点例子,小弟坐等

解决方案 »

  1.   

    WM_LBUTTONDOWN
    The WM_LBUTTONDOWN message is posted when the user presses the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse. A window receives this message through its WindowProc function. LRESULT CALLBACK WindowProc(
      HWND hwnd,       // handle to window
      UINT uMsg,       // WM_LBUTTONDOWN
      WPARAM wParam,   // key indicator
      LPARAM lParam    // horizontal and vertical position
    );
    Parameters
    wParam 
    Indicates whether various virtual keys are down. This parameter can be one or more of the following values. Value Description 
    MK_CONTROL The CTRL key is down. 
    MK_LBUTTON The left mouse button is down. 
    MK_MBUTTON The middle mouse button is down. 
    MK_RBUTTON The right mouse button is down. 
    MK_SHIFT The SHIFT key is down. 
    MK_XBUTTON1 Windows 2000/XP: The first X button is down. 
    MK_XBUTTON2 Windows 2000/XP: The second X button is down. 
    lParam 
    The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. 
    The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. Return Values
    If an application processes this message, it should return zero. Res
    Use the following code to obtain the horizontal and vertical position:xPos = GET_X_LPARAM(lParam); 
    yPos = GET_Y_LPARAM(lParam); 
    You can also use the MAKEPOINTS macro to convert the lParam parameter to a POINTS structure. To detect that the ALT key was pressed, check whether GetKeyState(VK_MENU) < 0. Note, this must not be GetAsyncKeyState.
      

  2.   

    重点是这
    lParam 
    The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area. 
    The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.You can also use the MAKEPOINTS macro to convert the lParam parameter to a POINTS structure. 
      

  3.   

    lParam这个参数是用来表示鼠标点击位置,低两字节是x坐标,高两字节是y坐标......