应用程序隐藏后重新执行调出问题,各位高手来看下错出在哪里
参考了很多代码去写。但是一直有问题。我写的如下。请各位高手帮我修改一下。实在是找不到问题所在了。
实现目标就是按按钮隐藏以后,再次执行EXE把隐藏的程序重新调出来而不是又打开一个。
很老的问题了。但是一直没解决。。。。
0.参考一个开源的播放器代码设计。
1.程序基于MFC对话框下实现。EVC4.0环境。
2.具体实现部分如下:
2.0 变量定义部分
2.1 初始化部分
2.2隐藏调用部分
谢谢指点,期待回复!
如果需要完整代码请发邮件给我,谢谢了
mercury002@gmail.com
实现目标就是按按钮隐藏以后,再次执行EXE把隐藏的程序重新调出来而不是又打开一个。
很老的问题了。但是一直没解决。。。。
0.参考一个开源的播放器代码设计。
1.程序基于MFC对话框下实现。EVC4.0环境。
2.具体实现部分如下:
2.0 变量定义部分
/////////////////////////////////////////////////////////////////////////////
// CPlayerIIIApp:
// See playerIII.cpp for the implementation of this class
//playerIII.h文件中定义的
#define SHOWLIST (WM_USER+140)
#define HIDEMP3 (WM_USER + 141)
#define HIDEOPENMP3 (WM_USER + 142)
#define SHOWMP3WINDOW (WM_USER + 143)
#define VOLMUTE (WM_USER + 144)
2.1 初始化部分
BOOL CPlayerIIIApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
HWND hWnd;
hWnd = ::FindWindow(TEXT("PLAYER"),NULL);
if(hWnd != NULL)
{
//显示窗口。
::SendMessage (hWnd,ShowWindow(hWnd,SW_SHOW),0,0);//显示窗口
::SendMessage(hWnd,SHOWMP3WINDOW,0,0);//向MP3窗口发消息,让歌曲名,歌曲时控件显示。
::SetWindowPos(hWnd, HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);//顶层
::SendMessage(hWnd,VOLMUTE,0,0);//发送静音控制,得到当前声音
return true;
}
HWND hWnd1;
hWnd1 = ::FindWindow(TEXT("OPENPLAYER"),NULL);
if(hWnd1 != NULL)
{
//显示窗口。
::SendMessage (hWnd1,ShowWindow(hWnd1,SW_SHOW),0,0);//显示窗口
::SetWindowPos(hWnd1, HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);//顶层
return true;
}
CPlayerIIIDlg dlg;
m_pMainWnd = &dlg;
WNDCLASS wc = {0}; //注册类名为PLAY
::GetClassInfo(AfxGetInstanceHandle(),L"Dialog",&wc);
wc.lpszClassName=L"PLAYER";
AfxRegisterClass(&wc);
WNDCLASS wc1 = {0}; //OPENPLAY
::GetClassInfo(AfxGetInstanceHandle(),L"Dialog",&wc1);
wc1.lpszClassName=L"OPENPLAYER";
AfxRegisterClass(&wc1);
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
2.2隐藏调用部分
BOOL CPlayerIIIDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
RegOpenKeyEx(HKEY_CURRENT_USER, gszBaseInstance, 0, 0, &g_hkVolume);
CoInitialize(NULL); //自己加的控制初始化,调用了winx.h文件
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CPlayerIIIDlg::OnHide()
{
// TODO: Add your control notification handler code here
m_test.SetWindowText(_T("hide first!"));
// m_test.ShowWindow(false);
RegCloseKey(g_hkVolume);
this->ShowWindow(SW_HIDE);//隐藏
}
LRESULT CPlayerIIIDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if (message == HIDEMP3) //预处理隐藏部分
{
RegCloseKey(g_hkVolume);
this->ShowWindow(SW_HIDE);
}
if (message == SHOWMP3WINDOW)//显示歌曲信息控件。预处理显示
{
m_test.ShowWindow(true);
}
return CDialog::WindowProc(message, wParam, lParam);
}
谢谢指点,期待回复!
如果需要完整代码请发邮件给我,谢谢了
mercury002@gmail.com
...全文


