首页 > 编程语言 >今天就差不多完成了ai编码c语言程序的过程

今天就差不多完成了ai编码c语言程序的过程

时间:2023-10-08 23:44:07浏览次数:39  
标签:编码 CTRL ai hwnd 差不多 nid int window KEY

不断改进的提示语:

write a program in c and compile by gcc, create a system tray icon, when the icon is right clicked, pop up an exit menu to exit the program, listen in backgroup, when key combination Ctrl+Left Arrow is pressed, get current active window in windows, then set the window size to half the screen resolution and locate to left half screen, when Ctrl+Right Arrow is pressed, get the current active window in windows and fix into the right half of the screen, when ctrl+up arrow is pressed, fix the current active window to upper half of the screen, when ctrl+down arrow is pressed, fix the current active window into the bottom half of the screen, when ctrl+alt+enter is pressed, if the current active window is in max size, restore its size and location to normal, or else, set it to max size if its size and location is normal

 

结果:

#include <stdio.h>
#include <windows.h>
#include <shellapi.h>

#define KEY_CTRL_LEFT_ARROW 0x25
#define KEY_CTRL_RIGHT_ARROW 0x27
#define KEY_CTRL_UP_ARROW 0x26
#define KEY_CTRL_DOWN_ARROW 0x28
#define KEY_CTRL_ALT_ENTER 0x0D
#define TRAY_ICON_ID 1001
#define WM_TRAY_ICON (WM_USER + 1)

HWND hwnd;
HMENU hMenu;

void resizeAndMoveWindow(HWND hwnd, int x, int y, int width, int height)
{
    SetWindowPos(hwnd, NULL, x, y, width, height, SWP_NOZORDER);
}

void handleKeyPress()
{
    if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
    {
        if (GetAsyncKeyState(VK_LEFT) & 0x8000)
        {
            HWND hwnd = GetForegroundWindow();
            int screenWidth = GetSystemMetrics(SM_CXSCREEN);
            int screenHeight = GetSystemMetrics(SM_CYSCREEN);
            resizeAndMoveWindow(hwnd, 0, 0, screenWidth / 2, screenHeight);
        }
        else if (GetAsyncKeyState(VK_RIGHT) & 0x8000)
        {
            HWND hwnd = GetForegroundWindow();
            int screenWidth = GetSystemMetrics(SM_CXSCREEN);
            int screenHeight = GetSystemMetrics(SM_CYSCREEN);
            resizeAndMoveWindow(hwnd, screenWidth / 2, 0, screenWidth / 2, screenHeight);
        }
        else if (GetAsyncKeyState(VK_UP) & 0x8000)
        {
            HWND hwnd = GetForegroundWindow();
            int screenWidth = GetSystemMetrics(SM_CXSCREEN);
            int screenHeight = GetSystemMetrics(SM_CYSCREEN);
            resizeAndMoveWindow(hwnd, 0, 0, screenWidth, screenHeight / 2);
        }
        else if (GetAsyncKeyState(VK_DOWN) & 0x8000)
        {
            HWND hwnd = GetForegroundWindow();
            int screenWidth = GetSystemMetrics(SM_CXSCREEN);
            int screenHeight = GetSystemMetrics(SM_CYSCREEN);
            resizeAndMoveWindow(hwnd, 0, screenHeight / 2, screenWidth, screenHeight / 2);
        }
        else if (GetAsyncKeyState(VK_MENU) & 0x8000 && GetAsyncKeyState(VK_RETURN) & 0x8000)
        {
            HWND hwnd = GetForegroundWindow();
            DWORD style = GetWindowLong(hwnd, GWL_STYLE);
            WINDOWPLACEMENT placement;
            placement.length = sizeof(WINDOWPLACEMENT);
            GetWindowPlacement(hwnd, &placement);
            if (style & WS_MAXIMIZE || placement.showCmd == SW_MAXIMIZE)
            {
                ShowWindow(hwnd, SW_RESTORE);
            }
            else
            {
                ShowWindow(hwnd, SW_MAXIMIZE);
            }
        }
    }
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    POINT cursorPos;

    switch (uMsg)
    {
    case WM_CREATE:
        hMenu = CreatePopupMenu();
        AppendMenu(hMenu, MF_STRING, 1, "Exit");
        break;
    case WM_TRAY_ICON:
        switch (lParam)
        {
        case WM_RBUTTONDOWN:
            GetCursorPos(&cursorPos);
            SetForegroundWindow(hwnd);
            TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, cursorPos.x, cursorPos.y, 0, hwnd, NULL);
            break;
        }
        break;
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case 1:
            DestroyWindow(hwnd);
            break;
        }
        break;
    case WM_CLOSE:
        DestroyWindow(hwnd);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    return 0;
}

LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode == HC_ACTION && (lParam & 0x80000000) == 0)
    {
        KBDLLHOOKSTRUCT *kbStruct = (KBDLLHOOKSTRUCT *)lParam;
        if (kbStruct->vkCode == KEY_CTRL_LEFT_ARROW || kbStruct->vkCode == KEY_CTRL_RIGHT_ARROW ||
            kbStruct->vkCode == KEY_CTRL_UP_ARROW || kbStruct->vkCode == KEY_CTRL_DOWN_ARROW ||
            kbStruct->vkCode == KEY_CTRL_ALT_ENTER)
        {
            handleKeyPress();
        }
    }
    return CallNextHookEx(NULL, nCode, wParam, lParam);
}

int main()
{
    HINSTANCE hInstance = GetModuleHandle(NULL);

    // Create the window class
    WNDCLASS wc = {0};
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.lpszClassName = "MyWindowClass";
    RegisterClass(&wc);

    // Create the window
    hwnd = CreateWindowEx(0, "MyWindowClass", "Window Resizer", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);

    // Create the system tray icon
    NOTIFYICONDATA nid = {0};
    nid.cbSize = sizeof(NOTIFYICONDATA);
    nid.hWnd = hwnd;
    nid.uID = TRAY_ICON_ID;
    nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
    nid.uCallbackMessage = WM_TRAY_ICON;
    nid.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    strcpy(nid.szTip, "Window Resizer");
    Shell_NotifyIcon(NIM_ADD, &nid);

    // Set the keyboard hook
    HHOOK hook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, hInstance, 0);
    if (hook == NULL)
    {
        printf("Failed to set keyboard hook.\n");
        return 1;
    }

    // Message loop
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    // Clean up
    UnhookWindowsHookEx(hook);
    Shell_NotifyIcon(NIM_DELETE, &nid);
    return 0;
}

程序已经可以正常运行,

注意, 编译的时候要加上-mwindows这个选项,不然会多出来一个黑空控制台窗口: gcc window_resizer.c -o window_resizer -mwindows,

然后 直接执行程序就可以看到托盘图标可以退出,正常使用了, 太开心了。

标签:编码,CTRL,ai,hwnd,差不多,nid,int,window,KEY
From: https://www.cnblogs.com/hualiu0/p/17750494.html

相关文章

  • 哈夫曼编码效率问题
    例题给出问题解决......
  • The build restored NuGet packages. Build the project again to include these pack
    ThebuildrestoredNuGetpackages.Buildtheprojectagaintoincludethesepackagesinthebuild 在VisualStudio2022中构建代码时出现此错误。严重性代码说明项目文件行禁止显示状态错误ThebuildrestoredNuGetpackages.Buildtheprojectagainto......
  • 记一次从自动发卡平台渗透到挖掘chatgptai SQL注入 0day漏洞的过程
    引言本文介绍了一次从自动发卡平台渗透到挖掘chatgptaiSQL注入0day漏洞的记录,全程并未对任何资产进行任何破坏、数据窃取和获利获益等行为,只用于学习研究目的。因内容信息敏感,部门内容不放置截图,均以文字记录。漏洞挖掘访问发卡店铺,尝试输入/admin,发现管理平台,根据管理平台......
  • Vue工程中 main.js 的作用、npm run serve的执行流程
    1.内容:importVuefrom'vue'   //导入Vue核心包importAppfrom'./App.vue'  //导入App.vue根组件Vue.config.productionTip=false  //提示当前处于什么环境(生产环境/开发环境),fasle是什么提示都没有,改为true才提示,但通常写falsenewVue({   ......
  • 新移科技发布基于联发科MT8390(Genio 700)平台的物联网AI核心板
    新移科技研发的XY8390物联网AI核心板是一款高度集成、功能强大的平台,该核心板专为各种人工智能(AI)和物联网(IoT)用例而设计。处理器采用了Arm®DynamIQ™技术,结合了高性能Cortex-A78内核和高能效Cortex-A55内核,并配备了ArmNeon™引擎。拥有AI加速器(AIA)的单核AI处......
  • 视频汇聚\视频融合平台EasyCVRAI智能算法平台电动车入梯检测解决方案
    随着大众对出行的要求不断提高,交通拥堵也越来越常见。为了解决这个问题,越来越多的人选择骑乘电动车出行。然而,随着电动车数量的激增,很多用户为了方便起见,将电动车停放或充电在室内,有的甚至停放在公共区域如走道、楼梯间等。由于电动车车身多数采用易燃可燃材料,一旦起火,燃烧速度快,......
  • golang 使用gomail.v2发送电子邮件
    1packageemail23import(4"errors"5"gopkg.in/gomail.v2"6)78vardialer*gomail.Dialer910funcReset(hoststring,portint,username,passwordstring){11dialer=gomail.NewDialer(host,port,usern......
  • click() 方法无法生效时 使用ActionChains
    背景知识1ActionChains库它的缩写来自于以下单词:Action(动作)和Chains(链)背景知识2ActionChains提供了更多灵活的鼠标和键盘操作选项,可以用于处理更复杂的场景,如果click()方法无法生效,可以尝试使用ActionChains来模拟点击事件。在使用Selenium时,存在一种情况是click()......
  • 如何巧用AI智能技术,让文物不再“无人问津”?
    文物是文化与传统的象征,而博物馆则是展现文物的载体。传统的博物馆监控体系只是利用摄像头进行监控,无法将人工智能融入其中,使其更加智能化、信息化。那么,如何将AI技术与传统视频监控相融合呢?TSINGSEE青犀智能分析网关与视频监控系统EasyCVR平台相结合的智能监控系统就给出了答案。......
  • 异步爬虫实战:实际应用asyncio和aiohttp库构建异步爬虫
    在网络爬虫的开发中,异步爬虫已经成为一种非常流行的技术。它能够充分利用计算机的资源,提高爬虫效率,并且能够处理大量的运算请求。Python中的asyncio和aiohttp库提供了强大的异步爬虫支持,使得开发者能够轻松构建高效的异步爬虫。什么是异动爬虫?为什么要使用自动爬虫?异步爬虫是一......