以windows服务程序启动运行一个程序(无窗口),如何弹出窗口(如对话框)
DWORD dwThreadId;
//开启线程
CloseHandle(CreateThread(NULL, 0, ShowArarm, this, 0, &dwThreadId));
DWORD WINAPI ShowArarm(LPVOID lParam)
{
CUsbControl08Dlg *pDlg = (CUsbControl08Dlg *)lParam;
HDESK hdeskCurrent;
HDESK hdesk;
HWINSTA hwinstaCurrent;
HWINSTA hwinsta;
pDlg->ShowStatus(_T("Get Process Window Station"));
hwinstaCurrent = GetProcessWindowStation();
if(!hwinstaCurrent)
{
pDlg->ShowStatus(_T("get window station err"));
return 0;
}
pDlg->ShowStatus(_T("Get Thread Desktop"));
hdeskCurrent = GetThreadDesktop(GetCurrentThreadId());
if(!hdeskCurrent)
{
pDlg->ShowStatus(_T("get window desktop err"));
return 0;
}
pDlg->ShowStatus(_T("Open winsta0"));
// Open winsta0
hwinsta = OpenWindowStation(_T("winsta0"), FALSE,
WINSTA_ACCESSCLIPBOARD |
WINSTA_ACCESSGLOBALATOMS |
WINSTA_CREATEDESKTOP |
WINSTA_ENUMDESKTOPS |
WINSTA_ENUMERATE |
WINSTA_EXITWINDOWS |
WINSTA_READATTRIBUTES |
WINSTA_READSCREEN |
WINSTA_WRITEATTRIBUTES);
if(!hwinsta)
{
pDlg->ShowStatus(_T("open window station err"));
return 0;
}
pDlg->ShowStatus(_T("Set Process Window Station"));
if( !SetProcessWindowStation(hwinsta))
{
pDlg->ShowStatus(_T("Set window station err"));
return 0;
}
pDlg->ShowStatus(_T("Open default desktop"));
// Open default desktop
hdesk = OpenDesktop(_T("default"), 0, FALSE,
DESKTOP_CREATEMENU |
DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE |
DESKTOP_HOOKCONTROL |
DESKTOP_JOURNALPLAYBACK |
DESKTOP_JOURNALRECORD |
DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP |
DESKTOP_WRITEOBJECTS);
if(!hdesk)
{
pDlg->ShowStatus(_T("Open desktop err"));
return 0;
}
pDlg->ShowStatus(_T("Set Thread Desktop"));
if(!SetThreadDesktop(hdesk))
{
pDlg->ShowStatus(_T("Set desktop err"));
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
// Display the string.
//MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
pDlg->ShowStatus((LPCTSTR)lpMsgBuf);
// Free the buffer.
LocalFree( lpMsgBuf );
}
MessageBox(NULL,_T("非法操作"),_T("警告"),MB_OK|MB_SETFOREGROUND);
pDlg->ShowStatus(_T("End Box"));
if (!SetProcessWindowStation(hwinstaCurrent))
return 0;
if (!SetThreadDesktop(hdeskCurrent))
return 0;
if (!CloseWindowStation(hwinsta))
return 0;
if (!CloseDesktop(hdesk))
return 0;
pDlg->ShowStatus(_T("End Show ararm"));
return 0;
}
程序运行到MessageBox(NULL,_T("非法操作"),_T("警告"),MB_OK|MB_SETFOREGROUND);停止了,但没弹出对话框.请高手赐教