Visual c++ 在桌面上呈现形状和文本(单击浏览)

Visual c++ 在桌面上呈现形状和文本(单击浏览),visual-c++,rendering,desktop-application,transparent,click-through,Visual C++,Rendering,Desktop Application,Transparent,Click Through,对于Windows 7,将任意形状和文本直接渲染到桌面上的最简单方法是什么 它必须具有以下属性: 1) 可见且始终位于顶部 3) 半透明的 2) 单击并键入,就像对象不在那里一样 一些值得注意的例子包括从简单的FRAP(渲染帧率)到复杂的雨量计(具有大量功能) EDIT0:我看过雨表的源代码,但我仍然不知道它是如何渲染对象的 EDIT1:(像这样的解决方案似乎非常有限制,必须有一种方法来渲染像Rainmeter一样自由的东西?我仍在努力,但这里是其中的一部分: #include <algo

对于Windows 7,将任意形状和文本直接渲染到桌面上的最简单方法是什么

它必须具有以下属性:

1) 可见且始终位于顶部
3) 半透明的
2) 单击并键入,就像对象不在那里一样

一些值得注意的例子包括从简单的FRAP(渲染帧率)到复杂的雨量计(具有大量功能)

EDIT0:我看过雨表的源代码,但我仍然不知道它是如何渲染对象的


EDIT1:(像这样的解决方案似乎非常有限制,必须有一种方法来渲染像Rainmeter一样自由的东西?

我仍在努力,但这里是其中的一部分:

#include <algorithm>
#include <Windows.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <conio.h>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <memory>
#include <cstdio>            
#include <glut.h>
#include <io.h>

#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace std;

#pragma comment(lib, "wininet.lib")
#pragma comment (lib, "Urlmon.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")

HINSTANCE hInstance;
POINT Mouse;
HWND hwnd;
RECT rect;
HDC dc;

float Size = 100;
float angle = 0;
bool Dirty = false;
char TEX;
int posX = 0;
int posY = 0;
int storedDC;

void GetDesktopResolution(int& w, int& h){
    RECT desktop;
    const HWND hDesktop = GetDesktopWindow();
    GetWindowRect(hDesktop, &desktop);
    w = desktop.right;
    h = desktop.bottom;
}

void EX(){
    delete hInstance;
    delete hwnd;
    exit(0);
}

void Keys(){
    if (GetAsyncKeyState(VK_ESCAPE)){
        exit(0);
    }

    if (GetAsyncKeyState(VK_LBUTTON) && GetAsyncKeyState(VK_CONTROL)){

    }
}

void Draw(){
    int h;
    int w;

    //Declair Desktop Size
    GetDesktopResolution(w, h);

    angle += 0.1f;

    if (angle >= 2 * 3.141592f){
        angle -= 2 * 3.141592f;
    }

    GetCursorPos(&Mouse);
    if (Dirty == true){
        rect = { 0, 0, w, h };
        RedrawWindow(hwnd, &rect, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);

        posX = Mouse.x;
        posY = Mouse.y;

        RedrawWindow(hwnd, &rect, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);
        Dirty = false;
    }

    dc = GetDC(hwnd);
    storedDC = SaveDC(dc);

    //DEFAULT_CHARSET - ANSI_CHARSET
    HFONT FMain = CreateFont(36, 20, -300, 0, FW_DONTCARE, FALSE, TRUE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
        CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Times New Roman"));
    SetTextColor(dc, RGB(255, 255, 255));
    SetBkColor(dc, RGB(0, 255, 0));
    SelectObject(dc, FMain);
    TextOut(dc, 15, 15, L"This is what the program does!", 30);

    RedrawWindow(hwnd, &rect, NULL, RDW_NOERASE | RDW_INVALIDATE | RDW_UPDATENOW);

    RestoreDC(dc, storedDC);
    ReleaseDC(hwnd, dc);
}

int main(int argc, char **argv){
    int h;
    int w;

    //Declair Desktop Size
    GetDesktopResolution(w, h);

    // find Program Manager
    hwnd = FindWindowEx(GetDesktopWindow(), 0, L"Progman", L"Program Manager");
    // find SHELLDLL_DefView
    hwnd = FindWindowEx(hwnd, 0, L"SHELLDLL_DefView", 0);
    // find Desktop Folder
    hwnd = FindWindowEx(hwnd, 0, L"SysListView32", L"FolderView");

    if (hwnd == NULL){
        MessageBox(NULL, L"Could not initiate window!", L"ERROR!", MB_OK);
        EX();
    }

    while (1){
        Keys();
        Draw();
    }

    //Remove the drawing
    rect = { Mouse.x - 50, Mouse.y - 50, Mouse.x + 50, Mouse.y + 50 };
    InvalidateRect(hwnd, &rect, true);

    delete hInstance;
    delete hwnd;

    return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#使用
#使用
使用名称空间系统;
使用名称空间std;
#pragma注释(lib,“wininet.lib”)
#pragma注释(lib,“Urlmon.lib”)
#pragma注释(链接器,“/subsystem:windows/ENTRY:mainCRTStartup”)
HINSTANCE HINSTANCE;
点鼠标;
HWND-HWND;
RECT-RECT;
HDC-dc;
浮子尺寸=100;
浮动角度=0;
bool Dirty=false;
焦特;
int posX=0;
int-posY=0;
int storedDC;
无效GetDesktopResolution(整数和整数、整数和整数){
矩形桌面;
const HWND hDesktop=GetDesktopWindow();
GetWindowRect(hDesktop和桌面);
w=桌面。右;
h=桌面。底部;
}
void EX(){
删除立场;
删除hwnd;
出口(0);
}
无效键(){
if(GetAsyncKeyState(VK_ESCAPE)){
出口(0);
}
if(GetAsyncKeyState(VK_-LBUTTON)和&GetAsyncKeyState(VK_-CONTROL)){
}
}
作废提款(){
int-h;
int w;
//声明桌面大小
GetDesktopResolution(w,h);
角度+=0.1f;
如果(角度>=2*3.141592f){
角度-=2*3.141592f;
}
GetCursorPos(鼠标和鼠标);
如果(脏==真){
rect={0,0,w,h};
重画窗口(hwnd,&rect,NULL,RDW_无效| RDW_擦除| RDW_更新);
posX=鼠标.x;
posY=Mouse.y;
重画窗口(hwnd,&rect,NULL,RDW_无效| RDW_擦除| RDW_更新);
脏=假;
}
dc=GetDC(hwnd);
storedDC=SaveDC(dc);
//默认字符集-ANSI字符集
HFONT FMain=CreateFont(36,20,-300,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
剪辑(默认精确、清晰类型(质量)、可变音高、文本(“Times New Roman”);
SetTextColor(dc、RGB(255、255、255));
SetBkColor(dc,RGB(0,255,0));
选择对象(dc、FMain);
TextOut(dc,15,15,L“这就是程序的功能!”,30);
重画窗口(hwnd,&rect,NULL,RDW_NOERASE | RDW_INVALIDATE | RDW_UPDATENOW);
恢复的dc(dc、storedDC);
释放dc(hwnd,dc);
}
int main(int argc,字符**argv){
int-h;
int w;
//声明桌面大小
GetDesktopResolution(w,h);
//查找程序管理器
hwnd=FindWindowEx(GetDesktopWindow(),0,L“Progman”,L“programmar”);
//查找SHELLDLL_DefView
hwnd=FindWindowEx(hwnd,0,L“SHELLDLL_devview”,0);
//查找桌面文件夹
hwnd=FindWindowEx(hwnd,0,L“SysListView32”,L“FolderView”);
if(hwnd==NULL){
MessageBox(NULL,L“无法启动窗口!”,L“错误!”,MB_OK);
EX();
}
而(1){
键();
Draw();
}
//删除图形
rect={Mouse.x-50,Mouse.y-50,Mouse.x+50,Mouse.y+50};
无效竖立(hwnd,&rect,true);
删除立场;
删除hwnd;
返回0;
}

我仍在努力,但这里是其中的一部分:

#include <algorithm>
#include <Windows.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <conio.h>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <memory>
#include <cstdio>            
#include <glut.h>
#include <io.h>

#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace std;

#pragma comment(lib, "wininet.lib")
#pragma comment (lib, "Urlmon.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")

HINSTANCE hInstance;
POINT Mouse;
HWND hwnd;
RECT rect;
HDC dc;

float Size = 100;
float angle = 0;
bool Dirty = false;
char TEX;
int posX = 0;
int posY = 0;
int storedDC;

void GetDesktopResolution(int& w, int& h){
    RECT desktop;
    const HWND hDesktop = GetDesktopWindow();
    GetWindowRect(hDesktop, &desktop);
    w = desktop.right;
    h = desktop.bottom;
}

void EX(){
    delete hInstance;
    delete hwnd;
    exit(0);
}

void Keys(){
    if (GetAsyncKeyState(VK_ESCAPE)){
        exit(0);
    }

    if (GetAsyncKeyState(VK_LBUTTON) && GetAsyncKeyState(VK_CONTROL)){

    }
}

void Draw(){
    int h;
    int w;

    //Declair Desktop Size
    GetDesktopResolution(w, h);

    angle += 0.1f;

    if (angle >= 2 * 3.141592f){
        angle -= 2 * 3.141592f;
    }

    GetCursorPos(&Mouse);
    if (Dirty == true){
        rect = { 0, 0, w, h };
        RedrawWindow(hwnd, &rect, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);

        posX = Mouse.x;
        posY = Mouse.y;

        RedrawWindow(hwnd, &rect, NULL, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);
        Dirty = false;
    }

    dc = GetDC(hwnd);
    storedDC = SaveDC(dc);

    //DEFAULT_CHARSET - ANSI_CHARSET
    HFONT FMain = CreateFont(36, 20, -300, 0, FW_DONTCARE, FALSE, TRUE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
        CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Times New Roman"));
    SetTextColor(dc, RGB(255, 255, 255));
    SetBkColor(dc, RGB(0, 255, 0));
    SelectObject(dc, FMain);
    TextOut(dc, 15, 15, L"This is what the program does!", 30);

    RedrawWindow(hwnd, &rect, NULL, RDW_NOERASE | RDW_INVALIDATE | RDW_UPDATENOW);

    RestoreDC(dc, storedDC);
    ReleaseDC(hwnd, dc);
}

int main(int argc, char **argv){
    int h;
    int w;

    //Declair Desktop Size
    GetDesktopResolution(w, h);

    // find Program Manager
    hwnd = FindWindowEx(GetDesktopWindow(), 0, L"Progman", L"Program Manager");
    // find SHELLDLL_DefView
    hwnd = FindWindowEx(hwnd, 0, L"SHELLDLL_DefView", 0);
    // find Desktop Folder
    hwnd = FindWindowEx(hwnd, 0, L"SysListView32", L"FolderView");

    if (hwnd == NULL){
        MessageBox(NULL, L"Could not initiate window!", L"ERROR!", MB_OK);
        EX();
    }

    while (1){
        Keys();
        Draw();
    }

    //Remove the drawing
    rect = { Mouse.x - 50, Mouse.y - 50, Mouse.x + 50, Mouse.y + 50 };
    InvalidateRect(hwnd, &rect, true);

    delete hInstance;
    delete hwnd;

    return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#使用
#使用
使用名称空间系统;
使用名称空间std;
#pragma注释(lib,“wininet.lib”)
#pragma注释(lib,“Urlmon.lib”)
#pragma注释(链接器,“/subsystem:windows/ENTRY:mainCRTStartup”)
HINSTANCE HINSTANCE;
点鼠标;
HWND-HWND;
RECT-RECT;
HDC-dc;
浮子尺寸=100;
浮动角度=0;
bool Dirty=false;
焦特;
int posX=0;
int-posY=0;
int storedDC;
无效GetDesktopResolution(整数和整数、整数和整数){
矩形桌面;
const HWND hDesktop=GetDesktopWindow();
GetWindowRect(hDesktop和桌面);
w=桌面。右;
h=桌面。底部;
}
void EX(){
删除立场;
删除hwnd;
出口(0);
}
无效键(){
if(GetAsyncKeyState(VK_ESCAPE)){
出口(0);
}
if(GetAsyncKeyState(VK_-LBUTTON)和&GetAsyncKeyState(VK_-CONTROL)){
}
}
作废提款(){
int-h;
int w;
//声明桌面大小
GetDesktopResolution(w,h);
角度+=0.1f;
如果(角度>=2*3.141592f){
角度-=2*3.141592f;
}
GetCursorPos(鼠标和鼠标);
如果(脏==真){
rect={0,0,w,h};
重画窗口(hwnd,&rect,NULL,RDW_无效| RDW_擦除| RDW_更新);
posX=鼠标.x;
posY=Mouse.y;
重画窗口(hwnd,&rect,NULL,RDW_无效| RDW_擦除| RDW_更新);
脏=假;
}
dc=GetDC(hwnd);
storedDC=SaveDC(dc);
//默认字符集-ANSI字符集
HFONT FMain=CreateFont(36,20,-300,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
剪辑(默认精确、清晰类型(质量)、可变音高、文本(“Times New Roman”);
SetTextColor(dc、RGB(255、255、255));
SetBkColor(dc,RGB(0,255,0));
选择对象(dc、FMain);
TextOut(dc,15,15,L“这就是程序的功能!”,30);
重画窗口(hwnd,&rect,NULL,RDW_NOERASE | RDW_INVALIDATE | RDW_UPDATENOW);
恢复的dc(dc、storedDC);
释放dc(hwnd,dc);
}
int main(int argc,字符**argv){
int-h;
int w;
//声明桌面大小
GetDesktopResolution(w,h);
//查找程序管理器
hwnd=FindWindowEx(GetDesktopWindow(),0,L“Progman”,L“programmar”);
//找到S