• Tooltips2


    #include<windows.h>
    #include<Commctrl.h>
    #include"resource.h"
    
    #pragma comment(lib,"comctl32.lib")
    
    HWND CreateToolTips(HWND hWnd1,HINSTANCE hInst,HWND DlgItem,WCHAR *szName,int n=1);
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
        HWND hWnd=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)WndProc);
            ShowWindow(hWnd,nCmdShow);
            MSG msg;
            while (GetMessage(&msg,NULL,NULL,NULL))
            {
                if (msg.message==WM_KEYDOWN)
                {
                    SendMessage(hWnd,msg.message,msg.wParam,msg.lParam);
                }else
                {
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
            }
    
        return 0;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
        switch (message)
        {
        case WM_INITDIALOG:
            {
                CreateToolTips(hWnd,GetModuleHandle(NULL),GetDlgItem(hWnd,IDC_BUTTON1),L"yo yo, check it out.");
            }
            break;
        case WM_CLOSE:
            PostQuitMessage(0);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default:
            return false;
        }
        return true;
    }
    /*窗口句柄 模块句柄 控件句柄 说明文字*/
    HWND CreateToolTips(HWND hWnd1,HINSTANCE hInst,HWND DlgItem,WCHAR *szName,int n)
    {
        INITCOMMONCONTROLSEX icex;
        icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
        icex.dwICC = ICC_TAB_CLASSES;// tab, tooltips
        //InitCommonControlsEx可以指定初始化什么控件
        InitCommonControlsEx(&icex);
        //Tooltips是当鼠标停止在某一个工具元件时,界面对用户的提示
         HWND hwndTip =CreateWindowEx(WS_EX_TOPMOST,TOOLTIPS_CLASS,0,WS_POPUP|TTS_NOPREFIX|TTS_BALLOON,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,hWnd1,0,hInst,0);
        //HWND hwndTip =CreateWindowEx(WS_EX_TOPMOST,TOOLTIPS_CLASS,0,TTS_ALWAYSTIP|TTS_NOPREFIX,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,hWnd1,0,hInst,0);
        TOOLINFO ti={0};
        ti.cbSize = sizeof(TOOLINFO)-4;
        //TTF_IDISHWND说明不填充ti.rect
        //   ti.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
        ti.uFlags=TTF_SUBCLASS|TTF_IDISHWND|TTF_TRANSPARENT|TTF_CENTERTIP;
        //ti.uFlags = TTF_SUBCLAS
        //ti.rect.bottom=200;
        //ti.rect.left=100;
        //ti.rect.right=400;
        //ti.rect.top=100;
        ti.hwnd   = hWnd1;
        ti.hinst=hInst;
        ti.uId =(UINT_PTR)DlgItem;
        ti.lpszText =szName;
        SendMessage(hwndTip,TTM_SETMAXTIPWIDTH,0,n);
        SendMessage(hwndTip,TTM_ADDTOOL,0,(LPARAM)&ti);
        //设置背景颜色
        SendMessage(hwndTip,TTM_SETTIPBKCOLOR,RGB(0,0,0),0);
        //设置字体颜色
        SendMessage(hwndTip,TTM_SETTIPTEXTCOLOR,RGB(0,255,0),0);
        return hwndTip;
    }

  • 相关阅读:
    弹出的iframe 表单无法获取焦点
    记录IE的两则BUG
    manifest 在移动端的应用实验
    [hover 状态图片变小] 淘宝的一个小用户体验
    使用 JSONP 的几点注意
    Apple在线商店iphone5, ipad mini到货提醒 邮件
    关于弹窗中的事件多次执行
    zen coding 插件使用实践
    hadoop系列整理Spark
    hadoop系列整理HBase
  • 原文地址:https://www.cnblogs.com/qiangua/p/3462829.html
Copyright © 2020-2023  润新知