| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1194 人关注过本帖
标题:用 vc 写了个对话框程序,但是运行没反应
只看楼主 加入收藏
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
结帖率:82.35%
收藏
已结贴  问题点数:10 回复次数:14 
用 vc 写了个对话框程序,但是运行没反应
之前还好好的,不知怎么回事,编译组建都没出错,哪位大神解下小弟的困惑
搜索更多相关主题的帖子: 对话框 
2014-05-19 15:35
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
重启电脑都不行,运行其他的对话框程序是可以的,不是vc的问题
2014-05-19 15:36
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
#include <commdlg.h>
#include "resource.h"
#include "MainDlg.h"
TCHAR precmd[MAX_PATH+10]="";

/*
Template designed by Please visit http://www. for more information
如鹏网(http://www.)大学生计算机学习社区,提供大量免费视频学习教程,提供个性化一对一学习指导
*/
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
        HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
        HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
    }

    return FALSE;
}

BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
    TCHAR strInitTime1[10]="00:00";
    TCHAR strInitTime2[10]="00:00";
    SetDlgItemText(hwnd,IDC_EDIT2,strInitTime1);
    SetDlgItemText(hwnd,IDC_EDIT3,strInitTime2);
    return TRUE;
}

void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
    //TCHAR precmd[MAX_PATH+10]="";
    //在同一个函数中,precmd不能在case之间传递
    //跟c语言不同
    switch(id)
    {
        case IDC_OK:
        {
            OPENFILENAME ofn;
            char szFile[MAX_PATH];
            ZeroMemory(&ofn,sizeof(ofn));
            ofn.lStructSize = sizeof(ofn);
            ofn.lpstrFile = szFile;
            ofn.lpstrFile[0] = TEXT('\0');
            ofn.nMaxFile = sizeof(szFile);
            ofn.lpstrFilter = TEXT("ALL\0*.*\0Text\0*.TXT\0");
            ofn.nFilterIndex = 1;
            ofn.lpstrFileTitle = NULL;
            ofn.nMaxFileTitle = 0;
            ofn.lpstrInitialDir = NULL;
            ofn.hwndOwner = hwnd;//自学能力、探索能力、猜测能力
            ofn.Flags = OFN_EXPLORER |OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
            if (GetOpenFileName(&ofn))
            {
                HWND hwndList=GetDlgItem(hwnd,IDC_LIST1);
                ListBox_InsertString(hwndList,-1,szFile);
               
            }

        }
        break;
        case IDC_LIST1:
            {
                switch (codeNotify)
                {
                case LBN_DBLCLK:
                    {
                        mciSendString(precmd,"",0,NULL);
                        HWND hwndList=GetDlgItem(hwnd,IDC_LIST1);
                        int a=ListBox_GetCurSel(hwndList);
                        TCHAR str[MAX_PATH];
                        ListBox_GetText(hwndList,a,str);
                        TCHAR shortpath[MAX_PATH];
                        GetShortPathName(str,shortpath,sizeof(shortpath));
                        SetDlgItemText(hwnd,IDC_EDIT1,str);
                        TCHAR playcmd[MAX_PATH+10];
                        wsprintf(playcmd,"play %s",shortpath);
                        mciSendString(playcmd,"",0,NULL);
                        
                        TCHAR statuscmd[MAX_PATH+20];
                        TCHAR buf[256];
                        wsprintf(statuscmd,"status %s length",shortpath);
                        mciSendString(statuscmd,buf,256,NULL);
                        int minute,second,iAllLength;
                        TCHAR strAllTime[256];
                        iAllLength=strtol(buf,NULL,0);
                        minute=iAllLength/60000;
                        second=(iAllLength/1000)%60;
                        wsprintf(strAllTime,"%02d:%02d",minute,second);
                        
                        SetDlgItemText(hwnd,IDC_EDIT3,strAllTime);
                    
                        wsprintf(precmd,"stop %s",shortpath);
                    }
                break;
                }
            }
        break;
        case IDC_BUTTON1:
            {
                mciSendString(precmd,"",0,NULL);
                HWND hwndList=GetDlgItem(hwnd,IDC_LIST1);
                int a=ListBox_GetCurSel(hwndList);
                TCHAR str[MAX_PATH];
                ListBox_GetText(hwndList,a,str);
                TCHAR shortpath[MAX_PATH];
                GetShortPathName(str,shortpath,sizeof(shortpath));
                SetDlgItemText(hwnd,IDC_EDIT1,str);
                TCHAR cmd[MAX_PATH+10];
                wsprintf(cmd,"play %s",shortpath);
                mciSendString(cmd,"",0,NULL);
                wsprintf(precmd,"stop %s",shortpath);
            }
        break;
        case IDC_BUTTON2:
            {
                HWND hwndList=GetDlgItem(hwnd,IDC_LIST1);
                int a=ListBox_GetCurSel(hwndList);
                TCHAR str[MAX_PATH];
                ListBox_GetText(hwndList,a,str);
                TCHAR shortpath[MAX_PATH];
                GetShortPathName(str,shortpath,sizeof(shortpath));
                SetDlgItemText(hwnd,IDC_EDIT1,str);
                TCHAR cmd[MAX_PATH+10];
                wsprintf(cmd,"pause %s",shortpath);
                mciSendString(cmd,"",0,NULL);
            }
        break;
        case IDC_BUTTON3:
            {
                HWND hwndList=GetDlgItem(hwnd,IDC_LIST1);
                int a=ListBox_GetCurSel(hwndList);
                TCHAR str[MAX_PATH];
                ListBox_GetText(hwndList,a,str);
                TCHAR shortpath[MAX_PATH];
                GetShortPathName(str,shortpath,sizeof(shortpath));
                SetDlgItemText(hwnd,IDC_EDIT1,str);
                TCHAR cmd[MAX_PATH+10];
                wsprintf(cmd,"resume %s",shortpath);
                mciSendString(cmd,"",0,NULL);
            }
        break;
        case IDC_BUTTON4:
            {
                HWND hwndList=GetDlgItem(hwnd,IDC_LIST1);
                int a=ListBox_GetCurSel(hwndList);
                TCHAR str[MAX_PATH];
                ListBox_GetText(hwndList,a,str);
                TCHAR shortpath[MAX_PATH];
                GetShortPathName(str,shortpath,sizeof(shortpath));
                SetDlgItemText(hwnd,IDC_EDIT1,str);
                TCHAR cmd[MAX_PATH+10];
                wsprintf(cmd,"stop %s",shortpath);
                mciSendString(cmd,"",0,NULL);
            }
        break;
        default:
        break;
    }
}

void Main_OnClose(HWND hwnd)
{
    EndDialog(hwnd, 0);
}
2014-05-19 15:37
top398
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:427
专家分:857
注 册:2014-5-2
收藏
得分:0 
1、这是全部程序么?
2、工程里有资源文件么?
2014-05-19 15:53
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
有一个对话框和菜单
2014-05-19 15:54
top398
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:427
专家分:857
注 册:2014-5-2
收藏
得分:0 
所谓的“没反应”,是运行程序后什么也不显示,也不报错,也没有进程驻留?
2014-05-19 16:01
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
是啊,代码也是没问题,我复制了代码,重新做了个工程就可以运行了,不知道运行没反应是什么原因
2014-05-19 16:05
solar728
Rank: 1
等 级:新手上路
帖 子:3
专家分:3
注 册:2014-3-8
收藏
得分:0 
这个代码有点长,默默的走过。。。。

凡事预则立,不预则废!
2014-05-19 16:23
top398
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:2
帖 子:427
专家分:857
注 册:2014-5-2
收藏
得分:5 
以下是引用surface在2014-5-19 16:05:44的发言:

是啊,代码也是没问题,我复制了代码,重新做了个工程就可以运行了,不知道运行没反应是什么原因
代码本身应该没啥问题,比较怀疑是你没把资源编译进去。
2014-05-19 16:36
砖家的谎言
Rank: 12Rank: 12Rank: 12
等 级:禁止访问
威 望:30
帖 子:693
专家分:3898
注 册:2013-12-6
收藏
得分:5 
你这个用的是一个向导,直接在里面写的代码吧,注意现在工程的时候应该是向导的哪个工程

我不是砖家,要努力成为砖家。
2014-05-19 16:40
快速回复:用 vc 写了个对话框程序,但是运行没反应
数据加载中...
 
   



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

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