| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1194 人关注过本帖
标题:用 vc 写了个对话框程序,但是运行没反应
取消只看楼主 加入收藏
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
结帖率:82.35%
收藏
已结贴  问题点数:10 回复次数:7 
用 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
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
有一个对话框和菜单
2014-05-19 15:54
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
是啊,代码也是没问题,我复制了代码,重新做了个工程就可以运行了,不知道运行没反应是什么原因
2014-05-19 16:05
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
回复 10 楼 砖家的谎言
向导的哪个工程是什么意思
2014-05-19 19:13
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
回复 9 楼 top398
void Main_OnHScroll(HWND hwnd, HWND hwndCtl, UINT code, int pos)
{        
    switch(GetDlgCtrlID(hwndCtl)) //得到控件ID
    {
        //控制音量滑块
    case IDC_SLIDERVOLUME:
        {        
            int voice = SendMessage(GetDlgItem(hwnd, IDC_SLIDERVOLUME), TBM_GETPOS, 0, 0); //得到当前滑块的音量值
                //TBM_GETPOS:返回当前滑块位置所代表的值(逻辑位置)
            TCHAR szVoice[256];
            wsprintf(szVoice, "setaudio %s volume to %d", shortName, voice); //将音量设置到滑块的值
            mciSendString(szVoice, (LPTSTR)NULL, 0, 0);   
        }
        break;
    case IDC_SLIDER: //歌曲的进度条
        {
            if(SB_ENDSCROLL == code)
            {
                long lPosition = SendMessage(GetDlgItem(hwnd, IDC_SLIDER), TBM_GETPOS, 0, 0); //得到当前的进度值
                //itoa(lPosition, curTime, 10);
                TCHAR strPos[256];
                wsprintf(strPos, "play %s from %ld", shortName, lPosition);

                mciSendString(strPos, (LPTSTR)NULL, 0, 0);                                                   //
                mciSendString(strPos, (LPTSTR)NULL, 0, 0);
               
            }
        }
        break;

这句代码是什么意思if(SB_ENDSCROLL == code)
2014-05-19 19:15
surface
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2013-8-8
收藏
得分:0 
回复 13 楼 top398
你讲的这个我懂,这个SB_ENDSCROLL是什么意思啊,还有code只是个形参,也没用实参来代入啊
2014-05-20 19:52
快速回复:用 vc 写了个对话框程序,但是运行没反应
数据加载中...
 
   



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

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