| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 397 人关注过本帖
标题:无法用GetOpenFileName获得文件路径。。。。
只看楼主 加入收藏
cmhjjosso
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2012-8-27
结帖率:100%
收藏
 问题点数:0 回复次数:3 
无法用GetOpenFileName获得文件路径。。。。
#include <windows.h>
#include <commdlg.h>
#include "resource.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
    static TCHAR szAppName[] = TEXT ("..") ;
    HWND hwnd ;
    MSG msg ;
    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 (WHITE_BRUSH) ;
    wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
    wndclass.lpszClassName = szAppName ;
    if (!RegisterClass (&wndclass))
    {
        MessageBox (NULL, TEXT ("This program requires Windows NT!"),
        szAppName, MB_ICONERROR) ;
        return 0 ;
    }
    hwnd = CreateWindow (szAppName, TEXT (".."),
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT,
    CW_USEDEFAULT, CW_USEDEFAULT,
    NULL, NULL, hInstance, NULL) ;
    ShowWindow (hwnd, iCmdShow) ;
    UpdateWindow (hwnd) ;
    while (GetMessage (&msg, NULL, 0, 0))
    {
        TranslateMessage (&msg) ;
        DispatchMessage (&msg) ;
    }
    return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static OPENFILENAME ofn;
    static TCHAR szFilter[] = TEXT ("Text Files (*.TXT)\0*.txt\0")\
                              TEXT ("ASCII Files (*.ASC)\0*.asc\0")\
                              TEXT ("All Files (*.*)\0*.*\0\0");
    TCHAR msg[10];
    switch (message)
    {
    case WM_CREATE:
        ofn.lStructSize = sizeof(OPENFILENAME);
        ofn.hwndOwner = hwnd;
        ofn.hInstance = NULL;
        ofn.lpstrFilter = szFilter;
        ofn.lpstrCustomFilter = NULL;
        ofn.nMaxCustFilter = 0;
        ofn.nFilterIndex = 0;
        ofn.lpstrFile = NULL;
        ofn.nMaxFile = MAX_PATH ;
        ofn.lpstrFileTitle = NULL ;
        ofn.nMaxFileTitle = MAX_PATH ;
        ofn.lpstrInitialDir = NULL ;
        ofn.lpstrTitle = NULL ;
        ofn.Flags = 0 ;
        ofn.nFileOffset = 0 ;
        ofn.nFileExtension = 0 ;
        ofn.lpstrDefExt = TEXT ("txt") ;
        ofn.lCustData = 0L ;
        ofn.lpfnHook = NULL ;
        ofn.lpTemplateName = NULL ;
        return 0;
    case WM_COMMAND:
        switch(LOWORD(wParam)){
        case IDM_OPEN:
            if(GetOpenFileName (&ofn)){
                MessageBox(hwnd, ofn.lpstrFile, "asd", MB_OK);
            }
               
            break;
        case IDM_SAVE:
            GetSaveFileName(&ofn);
            break;
        case IDM_SAVEAS:
            GetSaveFileName(&ofn);
            break;
        case IDM_EXIT:
            SendMessage(hwnd, WM_DESTROY, 0, 0);
            break;
        }
        return 0;
    case WM_DESTROY:
        PostQuitMessage (0) ;
        return 0 ;
    }
    return DefWindowProc (hwnd, message, wParam, lParam) ;
}


这一段代码
if(GetOpenFileName (&ofn)){
    MessageBox(hwnd, ofn.lpstrFile, "asd", MB_OK);
}
说好的 用了之后传回的文件路径怎么拿不到呢。。。
搜索更多相关主题的帖子: include 
2012-10-25 21:15
newdos
Rank: 9Rank: 9Rank: 9
等 级:禁止访问
威 望:6
帖 子:251
专家分:1169
注 册:2012-8-13
收藏
得分:0 
static OPENFILENAME ofn;
    static TCHAR szName[256] = {0};
    static TCHAR szFilter[] = TEXT ("Text Files (*.TXT)\0*.txt\0")\
                              TEXT ("ASCII Files (*.ASC)\0*.asc\0")\
                              TEXT ("All Files (*.*)\0*.*\0\0");


    case WM_CREATE:
        ofn.lStructSize = sizeof(OPENFILENAME);
        ofn.hwndOwner = hwnd;
        ofn.hInstance = NULL;
        ofn.lpstrFilter = szFilter;
        ofn.lpstrCustomFilter = NULL;
        ofn.nMaxCustFilter = 0;
        ofn.nFilterIndex = 0;
        ofn.lpstrFile = szName;
2012-10-26 11:17
cmhjjosso
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2012-8-27
收藏
得分:0 
回复 2楼 newdos
楼上那位 我昨天也发现了。。。 原来是一个指针的指针  我问一下 我学这东西的最终目的是做windows游戏 不过要做游戏应该先从window api的了解开始 这条路这么走没错吧
2012-10-27 21:26
cmhjjosso
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2012-8-27
收藏
得分:0 
自己顶个。。
2012-11-01 23:25
快速回复:无法用GetOpenFileName获得文件路径。。。。
数据加载中...
 
   



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

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