gpt4 book ai didi

c - Win32 C/C++ 向桌面添加按钮

转载 作者:行者123 更新时间:2023-12-04 05:53:01 27 4
gpt4 key购买 nike

嗨,很久以前我看到一个用 C++ 制作的程序,它创建了一个按钮并停靠在桌面的左上角,以便重新调整桌面本身的大小以适应新控件。但是我忘记了那个人使用的是哪个 API。

有人知道我在说什么,或者有在桌面上绘制控件的经验吗?

谢谢。

PS:我只需要 API

#include <windows.h>

#include <stdio.h>

#pragma comment(lib,"user32.lib")

#include <shellapi.h>

void pumpMsg(MSG * msg){


while(GetMessage(msg,0,0,0) != 0)
{
TranslateMessage(msg);
DispatchMessage(msg);
}

}


WNDPROC oldProc = 0;

HWND hWnd = 0;

APPBARDATA abd = {0};

BOOL CALLBACK dlgProc(HWND hwnd, UINT msg, WPARAM wpar, LPARAM lpar)
{
if(msg==WM_COMMAND)
{
if(wpar==100)
{
puts("Called");
SendMessage(hwnd,WM_CLOSE,0,0);
}

}

if(msg==WM_CLOSE || msg==WM_QUIT)
{
SHAppBarMessage(ABM_REMOVE, &abd);
EndDialog(hwnd,1);
}

CallWindowProc(oldProc,hwnd,msg,wpar,lpar);
}

int main(int argc, char *argv[])
{
MSG msg = {0};

DWORD style = WS_VISIBLE|WS_SYSMENU;
hWnd = CreateWindowEx(0,WC_DIALOG,"",style,2,2,400,400,0,0,GetModuleHandle(0),0);
__asm mov ebx, eax



abd.cbSize = sizeof(APPBARDATA);
abd.hWnd = hWnd;
SHAppBarMessage(ABM_NEW, &abd);
abd.rc.top = 0;
abd.rc.left = 0;
abd.rc.right = GetSystemMetrics(SM_CXSCREEN);
abd.rc.bottom = abd.rc.top + 60;

abd.uEdge = ABE_TOP;

SHAppBarMessage(ABM_QUERYPOS, &abd);
SHAppBarMessage(ABM_SETPOS, &abd);
abd.lParam = TRUE;
SHAppBarMessage(ABM_ACTIVATE, &abd);

MoveWindow(hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, TRUE);

CreateWindowEx(0,"button","button",WS_BORDER|WS_CHILD|WS_VISIBLE,2,10,40,40,hWnd,(HMENU)100,GetModuleHandle(0),0);

__asm{

push dlgProc
push GWL_WNDPROC
push ebx
call [SetWindowLong]

mov [oldProc], eax
}

DWORD tid = 0;

// CreateThread(0,0,&Timer,0,0,&tid);

pumpMsg(&msg);


return 0;
}

最佳答案

那是 Application Desktop Toolbar .神奇的功能是SHAppBarMessage .

关于c - Win32 C/C++ 向桌面添加按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9846502/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com