| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 727 人关注过本帖
标题:模仿迅雷小窗口的小程序 好些年前写的 发着玩玩~~
取消只看楼主 加入收藏
指手画脚
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:1
帖 子:334
专家分:560
注 册:2009-12-28
结帖率:60%
收藏
 问题点数:0 回复次数:0 
模仿迅雷小窗口的小程序 好些年前写的 发着玩玩~~
程序代码:
#include <windows.h>

#define WS_EX_LAYERED       0x00080000
#define LWA_COLORKEY        0x00000001
#define LWA_ALPHA           0x00000002

#define WIN_START_X         100
#define WIN_START_Y         100
#define WIN_WIDTH           36
#define WIN_HEIGHT          36

POINT winPos;
tagPOINT mouPos ,Pos;
HWND hwnd;
MSG msg;
TCHAR szAppName[] = TEXT("XunLei");

typedef BOOL (FAR WINAPI *LAYERFUNC)(HWND,COLORREF,BYTE,DWORD);

int setWinClass(HINSTANCE hInstance);
int createWindow(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL SetLayeredWindowAttributes(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);

/******************************************************************************/
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)
{
    MSG msg;

    setWinClass(hInstance);
    createWindow(hInstance);

    winPos.x = WIN_START_X;
    winPos.y = WIN_START_Y;

    while (GetMessage (&msg, NULL, 0, 0))
    {
        TranslateMessage (&msg);
        DispatchMessage (&msg);
    }

    return msg.wParam;
}
/*----------------------------------------------------------------------------*/

//设置窗口的WNDCLASS
int setWinClass(HINSTANCE hInstance)
{
    WNDCLASS wndclass;

    wndclass.style        = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc  = WndProc;
    wndclass.cbClsExtra   = 0;
    wndclass.cbWndExtra   = 0;
    wndclass.hInstance    = hInstance;
    wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wndclass.hCursor      = LoadCursor (NULL, IDC_ARROW);
    wndclass.hbrBackground= (HBRUSH) GetStockObject (LTGRAY_BRUSH);
    wndclass.lpszMenuName  = NULL;
    wndclass.lpszClassName = szAppName;

    RegisterClass (&wndclass);
    return 1;
}

//创建窗口
int createWindow(HINSTANCE hInstance)
{
    hwnd = CreateWindow (szAppName, TEXT ("迅雷")
        , WS_POPUP
        , WIN_START_X, WIN_START_Y
        , WIN_WIDTH, WIN_WIDTH
        , NULL, NULL, hInstance, NULL);
    SetWindowPos(hwnd
        , HWND_TOPMOST
        , WIN_START_X, WIN_START_Y
        , WIN_WIDTH, WIN_WIDTH
        ,SWP_SHOWWINDOW); //最顶端显示

    // 设置窗口透明
    SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE)^WS_EX_LAYERED);
    SetLayeredWindowAttributes(hwnd, RGB(0, 0, 255), 200, LWA_ALPHA);

    ShowWindow(hwnd, SW_SHOWNA);
    UpdateWindow (hwnd);

    return 1;
}

//窗口消息处理过程
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    HBRUSH hBrush;

    switch (message)
    {
    case WM_CREATE:
        
        return 0;
    case WM_PAINT:
        hdc = BeginPaint (hwnd, &ps);
        Rectangle(hdc, 0, 0, 36, 36);
        hBrush = CreateSolidBrush (RGB(30, 114, 171));
        SelectObject (hdc, hBrush);
        Rectangle(hdc, 1, 1, 35, 35);
        DeleteObject (hBrush);
        EndPaint (hwnd, &ps);
        return 0;
    case WM_KEYUP:
        switch(wParam)
        {
        case 27:   //按ESC退出
            PostQuitMessage(0);
            return 0;
        }
        return 0;
    case WM_LBUTTONDOWN:
        GetCursorPos(&mouPos);
        return 0;
    case WM_MOUSEMOVE:
        while(GetAsyncKeyState(VK_LBUTTON))
        {
            GetCursorPos(&Pos);

            winPos.x += Pos.x-mouPos.x;
            winPos.y += Pos.y-mouPos.y;

            mouPos.x = Pos.x;
            mouPos.y = Pos.y;

            MoveWindow(hwnd
                , winPos.x, winPos.y
                , WIN_WIDTH, WIN_HEIGHT
                , 1);
        }
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }

    return DefWindowProc(hwnd, message, wParam, lParam);
}

//窗口透明函数
BOOL SetLayeredWindowAttributes(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags)
{
    LAYERFUNC SetLayer;
    HMODULE hmod = LoadLibrary("user32.dll");
    SetLayer = (LAYERFUNC)GetProcAddress(hmod, "SetLayeredWindowAttributes");
    BOOL bReturn = SetLayer(hwnd, crKey, bAlpha, dwFlags);
    FreeLibrary(hmod);

    return   bReturn;
}

好几年前写的东西 没写注释 大家对付看一下吧
不算是纯C 但是有C语言基础的应该就能看懂
在VC CFree下都能运行
搜索更多相关主题的帖子: 模仿 迅雷 窗口 
2009-12-31 15:29
快速回复:模仿迅雷小窗口的小程序 好些年前写的 发着玩玩~~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024835 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved