C++マウスの左クリックでコンソールを閉じる
5063 ワード
ここでは、マウスクリックによるコンソールの閉鎖を実現する方法を提供する.
#include "iostream"
#include"windows.h" //
using namespace std;
int main()
{
HWND handle = FindWindow("ConsoleWindowClass", NULL); //
POINT *position;
position = new POINT;
LPRECT rect; //RECT
rect = new RECT;
while (true)
{
int x = 0, y = 0;
if (GetAsyncKeyState(VK_LBUTTON)) // ( : , )
{
GetCursorPos(position); //
GetWindowRect(handle, rect); // , RECT
x = position->x-rect->left; // x
y = position->y-rect->top; // x
if (x > 0 && x < 100 && y>0 && y < 100) //
{
SendMessage(handle, WM_CLOSE, NULL, NULL); //
}}}}