zoukankan      html  css  js  c++  java
  • 自定义“浏览文件夹”对话框

    介绍 我当时使用的是WIN32 api,我认为当我们使用浏览文件夹对话框时,当时没有显示完整路径,所以我写了这个程序。 它是如何工作的? 这段代码完全基于win32 api。我用基本函数给出了这个功能;让我们逐一讨论…… 逻辑 这个程序使用简单的win32 api函数调用,如FindWindowEx, CreateWindow等。使用这些函数,我们可以创建编辑框和静态控件。CreateWindowEx函数用于创建一个编辑框和一个静态控件的子控件。然后将其添加到浏览文件夹对话框中。 代码 首先向BorwseCallbackProc过程声明lpofn。然后,无论何时浏览文件夹对话框初始化该时间,它将发送消息到过程,即“BFFM_INITIALIZED”。创建编辑和静态控件,如下…隐藏,复制Code

    //Create the edit and static control on the dialog box
    edit=CreateWindowEx(0,"EDIT","Yogesh M Joshi.",WS_CHILD|WS_VISIBLE|WS_BORDER|
       ES_AUTOHSCROLL,0,100,100,50,hwnd,0,ghInstance,NULL);
    HWND caption=CreateWindowEx(0,"STATIC","You have selected the folder :",
       WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN,0,100,100,50,hwnd,0,ghInstance,NULL);

    这里的ghInstance是对话框的实例。“EDIT”和“STATIC”是类的名称。标志设置了contols的风格。然后,我们将不得不调整列表视图contol的大小,但首先,我们将在“浏览文件夹”对话框中找到它,这很容易,只需使用FindWindowEx函数。隐藏,复制Code

    HWND ListView=FindWindowEx(hwnd,NULL,"SysTreeView32",NULL);

    通过这种方式,我们找到了列表视图的句柄,然后调整它的大小。使用GetWindowRect函数获得“浏览文件夹”对话框的矩形。这将以以下方式发生……隐藏,复制Code

    //Gets the dimentions of the windows
    GetWindowRect(hwnd,&Dialog);
    GetWindowRect(ListView,&ListViewRect);
    
    //Sets the listview controls dimentions
    SetWindowPos(ListView,0,(ListViewRect.left-Dialog.left),
                (ListViewRect.top-Dialog.top )-20,290,170,0);
    //Sets the window positions of edit and dialog controls
    SetWindowPos(edit,HWND_BOTTOM,(ListViewRect.left-Dialog.left),
                (ListViewRect.top-Dialog.top )+170,290,20,SWP_SHOWWINDOW);
    SetWindowPos(caption,HWND_BOTTOM,(ListViewRect.left-Dialog.left),
                (ListViewRect.top-Dialog.top )+152,290,16,SWP_SHOWWINDOW);

    然后我使用了SetFont函数来设置静态和编辑控件的字体。隐藏,复制Code

    //This will set the font of the controls
    void SetFont(HWND hwnd,LPTSTR FontName,int FontSize)
    {
        
        HFONT hf;
        LOGFONT lf={0};
        HDC hdc=GetDC(hwnd);
        
        GetObject(GetWindowFont(hwnd),sizeof(lf),&lf);
        lf.lfWeight = FW_REGULAR;
        lf.lfHeight = (LONG)FontSize;
        lstrcpy( lf.lfFaceName, FontName );
        hf=CreateFontIndirect(&lf);
        SetBkMode(hdc,OPAQUE);
        SendMessage(hwnd,WM_SETFONT,(WPARAM)hf,TRUE);
        ReleaseDC(hwnd,hdc);
       
    }

    这样我们就调整了contols的大小。但主要的事情是,如果我们选择任何文件夹,然后编辑contol必须显示它。为此,回调消息“BFFM_SELCHANGED”并使用SetWindowText api设置编辑控制器的文本。 隐藏,复制Code

    //Selection change message
    if(uMsg==BFFM_SELCHANGED)
    {
        t = SHGetPathFromIDList((ITEMIDLIST*)lParam, c);
    
        //Sets the text of the edit control to the current folder
        SetWindowText(edit,c);
            
    }

    这样我们就可以自定义“浏览文件夹”对话框了。 结论 此代码仅用于教学目的。请将你的评论发送到:yogmj@hotmail.com,并在我的主页http://www.stechome.netfirms.com/上挑选一些很酷的windows实用程序。 本文转载于:http://www.diyabc.com/frontweb/news435.html

  • 相关阅读:
    C语言-if语句
    C语言-表达式
    C语言-基础
    Java for LeetCode 187 Repeated DNA Sequences
    Java for LeetCode 179 Largest Number
    Java for LeetCode 174 Dungeon Game
    Java for LeetCode 173 Binary Search Tree Iterator
    Java for LeetCode 172 Factorial Trailing Zeroes
    Java for LeetCode 171 Excel Sheet Column Number
    Java for LeetCode 169 Majority Element
  • 原文地址:https://www.cnblogs.com/Dincat/p/13450015.html
Copyright © 2011-2022 走看看