|
Hi there,
I've been stuck on this problem for over a day now and it's driving me crazy:
From the mainframe i create a new dialog (modeless):
void CMainFrame::OnMachineInit()
{
CInitmachinedialog *initmachinedialog;
initmachinedialog = new CInitmachinedialog;
initmachinedialog -> Create (IDD_MACHINEINITDIALOG, this);
initmachinedialog -> ShowWindow(SW_SHOW);
initmachinedialog -> init_pre_operations(2);
}
void CInitmachinedialog::init_pre_operations(int init_status)
{
[...]
running = TRUE;
THREADSTRUCT *_param = new THREADSTRUCT;
param->_this = this;
AfxBeginThread (init_thread,_param,THREAD_PRIORITY_ABOVE_NORMAL,0,0,NULL);
}
UINT CInitmachinedialog::init_thread (LPVOID param) // thread 1
{
THREADSTRUCT* ts = (THREADSTRUCT*)param;
while (running) ts->_this->initmachine(); // while (running = true) the thread is running
ts->_this->DestroyWindow();
return 0; // same as afxendthread(0)
}
The "destroywindow" command has no effect? It doesn't close the dialog or do anything?
Any idea why????
|
|
|
|
|
arrayjet_c++ wrote: Any idea why?
Proably because MFC uses thread local storage so the _this pointer is not available in the worker thread. There are really old KB Articles about this problem. You might look into using PostThreadMessage() to send a message to the dialog and then it would handle the message and call DestroyWindow() in the proper thread.
led mike
|
|
|
|
|
Hi,
Have you actually checked if DestroyWindow function has ever been reached?
Is running variable a member of CInitmachinedialog class, and if so, is it static?
Are you sure that ts->_this->DestroyWindow(); is working at all? eg. isn't overriden.
Try putting ts->_this->DestroyWindow(); inside init_pre_operations function to test it outside of a thread.
Regards
|
|
|
|
|
Yes the destroywindow function is definitely being reached.
Running is declared as static volatile and is used to monitor the working thread,
this is how THREADSTRUCT is definied in my header file:
typedef struct THREADSTRUCT
{
CInitmachinedialog* _this;
}THREADSTRUCT;
Any ideas?
|
|
|
|
|
Hi again,
Try to replace ts->_this->DestroyWindow(); with
ts->_this->SendMessage(WM_CLOSE);
It definitely works.
Regards
|
|
|
|
|
No i'm afraid it doesn't
ts->_this->SendMessage(WM_CLOSE) has no effect - same as ts->_this->DestroyWindow() really.
|
|
|
|
|
Ensure that the dialog style contains WS_SYSMENU flag.
Also, make sure that virtual DestroyWindow function is not overriden in your class with not functional code.
Regards
|
|
|
|
|
My program is SDI application. In order to support multi-language interface,all text of menus , tooltips of tool buttons and text displayed in dialogs are wrote in a text file.when mouse move over the tool buttons and the menus ,the tooltips will display on the status button.
I want change tooltip text on the statusbar when mouse move over diffrent tool buttons in the toolbar ,or move over diffrent menus ,and the tooltip text is from the text file .the tooltip text is not from string table in Resouce .
how can i do in my application?
Could you help me ?
Any help will definitely be appreciated.
|
|
|
|
|
In MFC, see the CToolTipCtrl class.
In CWnd, check out these functions: EnableToolTips, CancelToolTips, FilterToolTipMessage, and
OnToolHitTest.
Mark
|
|
|
|
|
hello,
i write a service and it can run well,but i have found a problem,that is if the service is running i can uninstall it successfully(stop it ,delete the record in the service list and registry),but if the service is already stoppped,then i can not delete the service(the record is still in the service list and the registry),and the service labeld disabled and the service can not be installed again after reboot the machine,what is the matter?what can i do to solve this problem?
|
|
|
|
|
|
Hi,
You should post a bit of code, responsible for the process of service uninstall.
Regards
|
|
|
|
|
the code is below,all code i found to uninstall service like this:
void CService::UnInstallService(TCHAR *tcServiceName)
{
SC_HANDLE schService;
SC_HANDLE schSCManager;
if(lstrlen(tcServiceName)<=0)
return;
schSCManager = OpenSCManager(
NULL, // machine (NULL == local)
NULL, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required
);
if ( schSCManager )
{
schService = OpenService(schSCManager, tcServiceName, SERVICE_ALL_ACCESS);
if (schService)
{
// try to stop the service
if ( ControlService( schService, SERVICE_CONTROL_STOP, &serviceStatus ) )
{
_tprintf(TEXT("Stopping %s."), tcServiceName);
Sleep( 1000 );
while( QueryServiceStatus( schService, &serviceStatus ) )
{
if ( serviceStatus.dwCurrentState == SERVICE_STOP_PENDING )
{
_tprintf(TEXT("."));
Sleep( 1000 );
}
else
break;
}
if ( serviceStatus.dwCurrentState == SERVICE_STOPPED )
_tprintf(TEXT("\n%s stopped.\n"), tcServiceName );
else
_tprintf(TEXT("\n%s failed to stop.\n"), tcServiceName );
}
// now remove the service
if( DeleteService(schService) )
_tprintf(TEXT("%s removed.\n"), tcServiceName );
else
_tprintf(TEXT("DeleteService failed - %s\n"), GetLastErrorText(szErr,256));
CloseServiceHandle(schService);
}
else
_tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256));
CloseServiceHandle(schSCManager);
}
else
_tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
}
someone can help me or give me the reason?
|
|
|
|
|
Make sure that SERVICE_STOP_PENDING is reported by service in ServiceCtrl callback function for SERVICE_CONTROL_STOP code as well as proper timeout for service stop completion.
Regards
|
|
|
|
|
everybody can download some sample code from here,and tried,almost have the problem.
|
|
|
|
|
from where?
|
|
|
|
|
you can download a sample service from the link:
http://www.codeproject.com/system/cntservice.asp
|
|
|
|
|
Hello All
Actually i found an article on codeproject for exporting messages from outlook in text form now i want that messages should be .msg type .I simply changed this function given in the code too
const char* typetoext(long type)
{
if(type == 0){//message (email)
return ".txt";
}else if(type == 1){//calendar
return ".ics";
}else if(type == 2){//contact
return ".vcf";
}else if(type == 3){//task
return ".ics";
}else{
return 0;
}
}
const char* typetoext(long type)
{
if(type == 0){//message (email)
return ".msg";
}else if(type == 1){//calendar
return ".ics";
}else if(type == 2){//contact
return ".vcf";
}else if(type == 3){//task
return ".ics";
}else{
return 0;
}
}
Its giving the file
but when i click to open the file it gives an error "cannot open this file"
Can anybody help me in doing this
|
|
|
|
|
Changing the extension of the file won't adapt magically the contents of the file to the file format you are looking for. You need to follow the format which is required by the .msg file. You can have a look here[^], see if it helps.
|
|
|
|
|
I'd like to do "on the fly" compression during a recording from sound card.
I know how to record into PCM .wav file. I don't want to use codecs
to compress but LAME or oggenc external programs.
But still I can not figure out how to pass in data, I just got from sound card buffer, into for example LAME.
..somehow from stdin ?
I can not use lame dll, i need it more flexible.
Does anyone know some example?
Thank you
viliam
|
|
|
|
|
Hello everyone:
I want to send a dummy mouse click message to desktop from a application. Please help me how to do, Thank you .
-Freehawk
|
|
|
|
|
If I understood your question clearly; is this what you want ?
::SendMessage(GetDesktopWindow(),WM_RBUTTONDOWN,wParam,lParam);
|
|
|
|
|
Hi,
Use SendInput or mouse_event function to emulate mouse actions.
Regards
|
|
|
|
|
I have started using VS 2005 for my MFC C++ applications, however I get loads of warnings, mainly the use of strcpy.
Are they a simple guide for moving up to VS 2005, I am having problems with strcpy etc.
I get in a mess if I just change to strcpy_s.
Also keep getting told to use new options to suppress these warnings, but they dont seem to make any difference.
Any suggestions please.
|
|
|
|
|