类似 Rolan的快速启动工具。
启动后隐藏,当鼠标移至左上角时,窗口显示,点击项目可运行程序。
GitHub地址: MyRolan 。
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif #include <tchar.h>
#include <windows.h>
#include <string>
#include <stdio.h>
#include <shellapi.h>
#include <windowsx.h>
#include <commctrl.h>
using namespace std; /* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); /* Make the class name into a global variable */
TCHAR szClassName[ ] = _T("MyRolan"); #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) typedef struct item {
string name;
string path;
string icon_path;
string arguments;
} item;
typedef struct group {
string name;
item* items;
int item_num;
} group; int WIDTH=;
int HEIGHT=;
int GROUP_WIDTH=;
int ITEM_WIDTH=;
int ITEM_HEIGHT=;
int GROUP_HEIGHT=ITEM_HEIGHT;
#define BKCOLOR RGB(240,240,240)
#define COMMON_ITEM_BKCOLOR RGB(220,220,220)
#define ACTIVE_ITEM_BKCOLOR RGB(200,200,200) group* groups;
int group_num;
int current_group=;
int current_item=;
int current_top=;
int item_columns=; int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = ; /* No extra bytes after the window class */
wincl.cbWndExtra = ; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
//wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
wincl.hbrBackground = NULL;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return ; /* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
WS_EX_TOOLWINDOW, /* Extended possibilites for variation */
szClassName, /* Classname */
_T("MyRolan"), /* Title Text */
WS_EX_TOOLWINDOW, /* default window WS_OVERLAPPEDWINDOW*/
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
WIDTH, /* The programs width */
HEIGHT, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
DWORD dwExStyle = GetWindowLong(hwnd, GWL_STYLE);
dwExStyle &=~WS_CAPTION;
SetWindowLong(hwnd, GWL_STYLE, dwExStyle); /* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow); /* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, , ))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
} /* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
void remove_nextline(char* buf) {
int l=strlen(buf);
if(buf[l-]=='\n')
buf[l-]='\0';
}
int load_data(HWND hwnd) {
FILE* f=fopen("data.txt","r");
if(f==NULL) {
MessageBox(hwnd,"Data File Not Exist.","Error!",);
return -;
}
char buf[];
fgets(buf,,f);
sscanf(buf,"%d",&group_num);
groups=new group[group_num];
for(int i=; i<group_num; i++) {
fgets(buf,,f);
remove_nextline(buf);
groups[i].name=buf;
fgets(buf,,f);
sscanf(buf,"%d",&groups[i].item_num);
groups[i].items=new item[groups[i].item_num];
for(int j=; j<groups[i].item_num; j++) {
fgets(buf,,f);
remove_nextline(buf);
groups[i].items[j].name=buf;
fgets(buf,,f);
remove_nextline(buf);
groups[i].items[j].path=buf;
fgets(buf,,f);
remove_nextline(buf);
groups[i].items[j].icon_path=buf;
fgets(buf,,f);
remove_nextline(buf);
groups[i].items[j].arguments=buf;
}
}
fclose(f);
return ;
}
long get_rect_width(RECT rect) {
return rect.right-rect.left;
} long get_rect_height(RECT rect) {
return rect.bottom-rect.top;
}
long get_client_width(HWND hwnd) {
RECT rect;
GetClientRect (hwnd, &rect) ;
return get_rect_width(rect);
} long get_client_height(HWND hwnd) {
RECT rect;
GetClientRect (hwnd, &rect) ;
return get_rect_height(rect);
}
int xy_to_num(int num,int columns,int width,int height,int x,int y) {
int c=x/width;
if(c>=columns)return -;
int r=y/height;
int n=columns*r+c;
if(n>=num)return -;
return n;
}
POINT get_client_mouse(HWND hwnd) {
POINT mouse;
GetCursorPos(&mouse);//获取鼠标的屏幕坐标
ScreenToClient(hwnd,&mouse);//转换为界面坐标
return mouse;
}
int get_current_position(HWND hwnd,int& is_group) {
POINT mouse=get_client_mouse(hwnd);
if(mouse.x<||mouse.x>WIDTH||mouse.y<||mouse.y>HEIGHT)return -;
if(mouse.x<=GROUP_WIDTH) {
is_group=;
int n=xy_to_num(group_num,,GROUP_WIDTH,GROUP_HEIGHT,mouse.x,mouse.y);
return n;
}
is_group=;
int num=groups[current_group].item_num;
int n=xy_to_num(num,item_columns,ITEM_WIDTH,ITEM_HEIGHT,mouse.x-GROUP_WIDTH,mouse.y-current_top);
return n;
}
int update_current_group_and_item(HWND hwnd) {
int current_group_bak=current_group;
int current_item_bak=current_item;
int is_group=;
int n=get_current_position(hwnd,is_group);
if(n<)return ;
if(is_group) {
current_group=n;
current_item=;
current_top=;
}
else current_item=n;
return (current_group_bak!=current_group)||(current_item_bak!=current_item)?:;
}
void paint_rolan(HWND hwnd,HDC hdc1,HDC hdc) {
static HBRUSH bk_brush =CreateSolidBrush (BKCOLOR);
static HBRUSH common_item_brush =CreateSolidBrush (COMMON_ITEM_BKCOLOR);
static HBRUSH active_item_brush =CreateSolidBrush (ACTIVE_ITEM_BKCOLOR);
static HFONT hFont;
LOGFONT lf;
lf.lfHeight=ITEM_HEIGHT/2.6;
lf.lfWidth= ;
lf.lfEscapement= ;
lf.lfOrientation= ;
lf.lfWeight=;
lf.lfItalic= ;
lf.lfUnderline= ;
lf.lfStrikeOut= ;
lf.lfCharSet=DEFAULT_CHARSET ;
lf.lfOutPrecision= ;
lf.lfClipPrecision= ;
lf.lfQuality= ;
lf.lfPitchAndFamily= ;
lstrcpy (lf.lfFaceName, _T("Arial") );
PatBlt(hdc, , , WIDTH,HEIGHT, WHITENESS); //在绘图前调用这个函数可以把背景重画,WHITENESS可以使背景透明
hFont = CreateFontIndirect (&lf) ;
SelectFont(hdc,hFont);
SelectObject (hdc, GetStockObject (NULL_PEN)) ;
SelectObject (hdc,bk_brush);
Rectangle(hdc,,,WIDTH,HEIGHT);
for(int i=; i<group_num; i++) {
if(i==current_group) {
SelectObject (hdc,active_item_brush);
SetBkColor(hdc,ACTIVE_ITEM_BKCOLOR);//设置文字背景色
} else {
SelectObject (hdc,common_item_brush);
SetBkColor(hdc,COMMON_ITEM_BKCOLOR);//设置文字背景色
}
Rectangle(hdc,,i*GROUP_HEIGHT-,GROUP_WIDTH,(i+)*GROUP_HEIGHT);
TextOut(hdc,GROUP_WIDTH/,i*GROUP_HEIGHT+GROUP_HEIGHT/,groups[i].name.c_str(),groups[i].name.length());
}
int gitem_num=groups[current_group].item_num;
item* items=groups[current_group].items;
int item_num=((gitem_num-)/item_columns+)*item_columns;
int item_count=;
while(item_count<item_num) {
int left=GROUP_WIDTH+(item_count%item_columns)*ITEM_WIDTH;
int top=current_top+item_count/item_columns*ITEM_HEIGHT;
if(item_count==current_item) {
SelectObject (hdc,active_item_brush);
SetBkColor(hdc,ACTIVE_ITEM_BKCOLOR);//设置文字背景色
} else if(item_count<gitem_num){
SelectObject (hdc,common_item_brush);
SetBkColor(hdc,COMMON_ITEM_BKCOLOR);//设置文字背景色
}else {
SelectObject (hdc,bk_brush);
}
Rectangle(hdc,left-,top-,left+ITEM_WIDTH,top+ITEM_HEIGHT);
if(item_count<gitem_num)TextOut(hdc,left+ITEM_WIDTH/,top+ITEM_HEIGHT/,items[item_count].name.c_str(),items[item_count].name.length());
item_count++;
}
BitBlt(hdc1, , , WIDTH, HEIGHT, hdc, , , SRCCOPY); //将位图直接复制在设备上,关于该函数的使用有很多说明,在这里就不再提了
}
/* This function is called by the Windows function DispatchMessage() */ string get_directory(string path){
int last=path.find_last_of('\\');
return path.substr(,last);
} LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HDC hdc;
static PAINTSTRUCT ps ;
static bool is_hide;
static int screen_height;
static bool not_program_move;
static HDC hdcBuffer;
switch (message) { /* handle the messages */
case WM_CREATE: {
not_program_move=true;
is_hide=false;
screen_height=GetSystemMetrics(SM_CYSCREEN);
load_data(hwnd);
current_group=;
current_item=;
InvalidateRect(hwnd,NULL,true);
SetTimer(hwnd,,,NULL);
hdc = GetDC(hwnd); //获取设备
hdcBuffer = CreateCompatibleDC(hdc); //给设备分配一个内存空间
HBITMAP hBitMap = CreateCompatibleBitmap(hdc, WIDTH, HEIGHT); //创建一个cxClient, cyClient大小并且适应DC设备环境的位图
ReleaseDC(hwnd, hdc);
SelectObject(hdcBuffer, hBitMap); //将位图设置为hdcBuffer的画刷
}
break;
case WM_MOVE: {
RECT rect;
GetWindowRect(hwnd,&rect);
if(not_program_move&&rect.left<=&&rect.bottom>=screen_height) {
not_program_move=false;
MoveWindow(hwnd,-WIDTH,-HEIGHT, WIDTH, HEIGHT, FALSE);// screen_height-5
not_program_move=true;
}
is_hide=true;
}
break;
case WM_KEYDOWN: { //识别按键
}
break;
case WM_PAINT: {
hdc=BeginPaint (hwnd,&ps) ;
paint_rolan(hwnd,hdc,hdcBuffer);
EndPaint(hwnd,&ps);
}
break;
case WM_TIMER: {
RECT rect;
GetClientRect(hwnd,&rect);
SetWindowPos(hwnd, HWND_TOPMOST, , , , ,SWP_NOSIZE|SWP_NOMOVE);
}
break;
case WM_MOUSELEAVE: {
not_program_move=true;
MoveWindow(hwnd,-WIDTH,-HEIGHT, WIDTH, HEIGHT, FALSE);// screen_height-5
is_hide=true;
}
break;
case WM_MOUSEHOVER:
break;
case WM_MOUSEMOVE: {
TRACKMOUSEEVENT trmouse;
trmouse.cbSize = sizeof(TRACKMOUSEEVENT);
trmouse.dwFlags = TME_LEAVE | TME_HOVER;// | TME_NONCLIENT
trmouse.dwHoverTime = ;
trmouse.hwndTrack = hwnd;
if(!_TrackMouseEvent(&trmouse))
return FALSE;
if(is_hide) {
not_program_move=false;
MoveWindow(hwnd,, , WIDTH, HEIGHT, FALSE);
is_hide=false;
} else {
if(update_current_group_and_item(hwnd))
InvalidateRect(hwnd,NULL,true);
}
}
break;
case WM_MOUSEWHEEL: { //0x020A
int flag=;
if( (INT)wParam < ) {
int temp=current_top-ITEM_HEIGHT;
if(((groups[current_group].item_num-)/item_columns+)*ITEM_HEIGHT+temp>) {
current_top=temp;
flag=;
}
}
else {
if(current_top<) {//+ITEM_HEIGHT<get_client_height(hwnd)
current_top+=ITEM_HEIGHT;
flag=;
}
}
if(flag)
InvalidateRect( hwnd, NULL, TRUE );
}
break;
case WM_LBUTTONUP: {
int t;
if(get_current_position(hwnd,t)!=-&&t==) {
const char* path= groups[current_group].items[current_item].path.c_str();
const char* arguments= groups[current_group].items[current_item].arguments.c_str();
ShellExecute(NULL, "open",path,arguments, get_directory(path).c_str(), SW_SHOWNORMAL);
InvalidateRect(hwnd,NULL,true);
}
}
break;
case WM_DESTROY:
KillTimer(hwnd,);
PostQuitMessage (); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return ;
}
main.cpp
data.txt的格式如下
//组的个数
常用 //组名称
//组下项目的个数
Chrome //项目名称
C:\chrome\chrome.exe //程序路径
C:\chrome\chrome.exe //图标路径
www.google.com //运行参数
C:\QQ\bin\QQ.exe
C:\QQ\bin\QQ.exe Everything
C:\everything\everything.exe
C:\everything\everything.exe 网络 迅雷
C:\Thunder\thunder.exe
C:\Thunder\thunder.exe
2017年4月初写
END
MyRolan (快速启动小工具)的更多相关文章
-
Excel组合图表快速制作小功能
1. 选中数据区域,插入推荐的图表 2. 然后可以选择快速布局小工具进行布局微调 选中图表 -> 设计(菜单) -> 快速布局(左边) 个人特别喜欢带表格的那个组合图布局,清晰好看
-
[微信小程序] 通过快速启动demo分析小程序入门关键点
(1)小程序基础结构 下图是在开发者工具通过快速启动模式创建的小程序的目录结构 可以看到,小程序中主要包含有4中类型不同的文件 .json 后缀的 JSON 配置文件 .wxml 后缀的 WXML 模 ...
-
uTools电脑软件快速启动工具
uTools电脑软件快速启动工具 http://www.autoahk.com/archives/16112 https://gitee.com/weiyunw ...
-
键盘快速启动工具Launchy的简单使用技巧
打开电脑面对林林总总的图标,找到对应的程序,快速启动显得尤为重要.这样有利于提高我们的效率. 好了,直接上图: 就是这款小巧的工具,界面如上. 接下来介绍这款工具的使用技巧. 1.安装成功后:打开工具 ...
-
开源桌面快速启动工具-GeekDesk
GeekDesk 小巧.美观的桌面快速启动工具 开发框架 wpf .net 4.7.2 HandyControl 全局热键 鼠标跟随 快速启动 随时随地 支持自定义热键 支持鼠标跟随 自定义壁纸 随意 ...
-
【原】得心应手小工具开发——IE代理快速切换工具
一.引入 因为公司里上外网要经常换IE代理地址,每次切换地址都要进到Internet Options里去设置一番,经常切换的话很是麻烦,由于用了点时间作个小工具来方便自己. 二.实现思路 其实思路很简 ...
-
快速入门PaddleOCR,并试用其开发一个搜题小工具
介绍 PaddleOCR 是一个基于百度飞桨的OCR工具库,包含总模型仅8.6M的超轻量级中文OCR,单模型支持中英文数字组合识别.竖排文本识别.长文本识别.同时支持多种文本检测.文本识别的训练算法. ...
-
Windows下好用到必须开机自启的小工具
折腾过linux,黑苹果,最后还是回到了盖茨大叔的windows.得出的结论是,日常使用的话,折腾Linux还不如把精力去拿去折腾windows.分享下折腾的成果,介绍下一些很不错的小工具. ...
-
神逸之作:国产快速启动软件神品ALTRun
http://xbeta.info/altrun.htm 作者: ET民工和塞壬 日期: 2010-09-15 分类: windows 标签: quick-launch <神逸之作:国产快速启动 ...
随机推荐
-
Linux下查看进程打开的文件句柄数和如何修改
修改文件句柄数在Linux下,我们使用ulimit -n 命令可以看到单个进程能够打开的最大文件句柄数量(socket连接也算在里面).系统默认值1024. 对于一般的应用来说(象Apache.系统进 ...
-
Implicit conversion from enumeration type &#39;enum CGImageAlphaInfo&#39; to different enumeration type &#39;CGB
Implicit conversion from enumeration type 'enum CGImageAlphaInfo' to different enumeration type 'CGB ...
-
GCC内嵌汇编
http://blog.csdn.net/mydo/article/details/8279924
-
bzoj3573[Hnoi2014]米特运输
http://www.lydsy.com/JudgeOnline/problem.php?id=3573 好吧,虽然这是day1最后一题,但却是最水的一题....(前提:看懂题目) 仔细看题! 仔细看 ...
-
jquery 替换元素函数
1.replaceWith()使用括号内的内容替换所选择的内容.$("#div").replaceWith("<div id="div2"> ...
-
SQL语句函数详解__sql聚合函数
函数是一种有零个或多个参数并且有一个返回值的程序.在SQL中Oracle内建了一系列函数,这些函数都可被称为SQL或PL/SQL语句,函数主要分为两大类:单行函数.组函数 本文将讨论如何使用单行函数及 ...
-
Vue双向数据绑定原理解析
基本原理 Vue.采用数据劫持结合发布者-订阅者模式的方式,通过Object.defineProperty()来劫持各个属性的setter和getter,数据变动时发布消息给订阅者,触发相应函数的回调 ...
-
bzoj 4596 [Shoi2016]黑暗前的幻想乡 矩阵树定理+容斥
4596: [Shoi2016]黑暗前的幻想乡 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 559 Solved: 325[Submit][Sta ...
-
JavaScript根据经纬度获取距离信息
最近开发微信小程序,遇到了外卖配送半径的问题,在网上查阅了诸多资料,也大概理解了经纬度距离计算的公式原理,在此做下笔记,方便自己和大家学习使用. 若是把地球当作一个正常的球体(其实它是椭球)来说,球面 ...
-
API使用
至于什么是API我想不用累述了,百科上面有,其实就是别人写好了一大堆功能性的代码,然后你可以拿来用.一般的二次开发都是使用api来开发,包括现在的高级程序设计,很少自己写基本代码了,像.netFram ...