网站建设资讯

NEWS

网站建设资讯

WIN32一些文件及窗口操作-创新互联

0,获取指定的系统路径:WIN32一些文件及窗口操作

    #include
    #pragma comment(lib, "shell32.lib")

创新互联公司是一家集网站建设,新泰企业网站建设,新泰品牌网站建设,网站定制,新泰网站建设报价,网络营销,网络优化,新泰网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

    TCHAR szPath[MAX_PATH];
  ::SHGetSpecialFolderPath(NULL, szPath, CSIDL_PERSONAL, FALSE);

1,打开文件或选中文件:

BOOL OpenDownFile(const TCHAR* pFilePath, BOOL bOpenCatalogue)
{
    std::wstring wstrPath;
    if (bOpenCatalogue)
    {
        wstrPath.append(L"/n,/select,");
        //打开文件所在目录,选中指定文件
    }

    wstrPath.append(pFilePath);//没有/n,/select,参数的话是直接打开指定文件或目录
  ShellExecute(NULL, L"open", L"Explorer.exe", wstrPath.c_str(), NULL, SW_SHOWDEFAULT);

    return TRUE;
}

2,文件另存为:
BOOL SaveFileAs(const HWND hWnd, const TCHAR* pDefaultFileName)
{
    std::wstring FileSavePath;
    std::wstring fileNameAll;
    std::wstring wstrPostfix;

    fileNameAll = pDefaultFileName;
    size_t ipoint = fileNameAll.rfind(L".");
    if(ipoint == fileNameAll.npos)//无后缀名
    {
        wstrPostfix.clear();
    }
    else
    {
        wstrPostfix = fileNameAll.substr(ipoint+1);
    }

    TCHAR filename[MAX_PATH] = {0};
  TCHAR pstrFilter[MAX_PATH] = {0};
  wsprintf(pstrFilter,L"%s Files(*.%s)|*.%s|All Files(*.*)|*.*||",wstrPostfix.c_str(),wstrPostfix.c_str(),wstrPostfix.c_str());

    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));
  wcscpy_s(filename,_countof(filename),fileNameAll.c_str());
  ofn.lpstrFile        = filename;
    ofn.nMaxFile        = MAX_PATH;
    ofn.lpstrFilter        = L"*.*";
    ofn.lpstrDefExt        = wstrPostfix.c_str();
    ofn.lpstrTitle        = L"另存为";
    ofn.Flags        = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
    ofn.FlagsEx     = OFN_EX_NOPLACESBAR;
    ofn.lStructSize        = sizeof(OPENFILENAME);
    ofn.hwndOwner        = hWnd;
    ofn.hInstance        = NULL;

    if (::GetSaveFileName(&ofn))
    {
        FileSavePath = filename;
    }
    else
    {
        return FALSE;
    }

    return TRUE;
}

3,选择文件
#include
BOOL SelectFile(std::wstring& strSelectFile )
{
    OPENFILENAME opfn;
    TCHAR strFilename[MAX_PATH];
    ZeroMemory(&opfn, sizeof(OPENFILENAME));
    opfn.lStructSize = sizeof(OPENFILENAME);
    opfn.lpstrFilter = L"pdf Files(*.pdf) *.pdf";//设置过滤
    opfn.nFilterIndex = 1;
   opfn.lpstrFile = strFilename;
    opfn.lpstrFile[0] = '';
    opfn.nMaxFile = sizeof(strFilename);
    opfn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
    if (::GetOpenFileName(&opfn))
    {
        strSelectFile = strFilename;
    }
    return TRUE;
}

4,文件拖拽

DragAcceptFiles(hWnd, TRUE);

case WM_DROPFILES:
{
  HDROP hDrop = (HDROP)wParam;
  TCHAR szFileName[MAX_PATH];
  int count = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
  if(count)
  {
    for(int i=0; i        {
      int pathLen = DragQueryFile(hDrop, i, szFileName,MAX_PATH);
      //Do(szFileName); 

    }
   }
}

 break;

5,透明窗口

SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(m_hwnd, GWL_EXSTYLE) ^ 0x80000);
HINSTANCE hInst = LoadLibrary(L"User32.DLL"); 
if (hInst)
{
    typedef BOOL(WINAPI *MYFUNC)(HWND, COLORREF, BYTE, DWORD);
    MYFUNC fun = NULL;
    fun = (MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
    if (fun)
        fun(hWnd, 0, 255 / 2, LWA_ALPHA); //半透明
    FreeLibrary(hInst);
}


本文题目:WIN32一些文件及窗口操作-创新互联
链接地址:http://cdweb.net/article/dcpohc.html