|
Do the file change notificaiton/waiting in a secodnary thread. Post messages to your main thread. Process those messages in the main thread. Don't try ot directly update controls from the secodnary thread which processed the file notification. You can look into ON_REGISTERED_MESSAGE.
// example for ON_REGISTERED_MESSAGE
const UINT wm_Find = RegisterWindowMessage( FINDMSGSTRING );
BEGIN_MESSAGE_MAP( CMyWnd, CMyParentWndClass )
ON_REGISTERED_MESSAGE( wm_Find, OnFind )
// ... Possibly more entries to handle additional messages
END_MESSAGE_MAP( )
Post the registered message fromt he notiifcaiton thread. When the main dialog receives it, then call the updatedata.
This should work fine for you.
|
|
|
|
|
Good afternoon
I got this message for the app after finished debug:
The thread 0x6B8 has exited with code 2 (0x2).
The program 'C:\DEV\C++\Billing\Report\Debug\Report.exe' has exited with code 2 (0x2).
the 0x6B8 thread is CDialog::OnCancel, the part of code that calling OnCancel is from here:
LRESULT CReportDlg::OnComplete( WPARAM, LPARAM )
{
m_thrReport.Wait( INFINITE );
PostMessage( WM_CLOSE );
return S_OK;
}
Is it because of infinite waiting causing exited with code 2? what is code 2 mean? thank you!
|
|
|
|
|
When the dialog-based MFC program exits, it usually returns the ID of the button that caused the closing, or else 2 meaning CANCEL or CLOSE and 0 meaning OK.
If you want custom exit codes, override ExitInstance at application and set your own exit code.
|
|
|
|
|
That's the answer I was looking for hours ago! Thank you kind Sir!
After looking into the ressource.h-File I can confirm that it's because of the ID of the Control which lead to the end of the thread.
For example: I was kinda terrified of the unknown thread-exit code 32780. Cannot look up what's this about because usually the exit codes are not as far specified.
After launching my exit procedere mindlessly with my overloaded OnCancel with ID 32780 the weird exit messages kept coming. But I never thought that far.
Hopefully someone will spare some time with this information.
best regards
|
|
|
|
|
I need to perform continous job in RPC Server and then execute callback from a parallel thread to inform client about job completion. Server call should submit new job and exit immediately. In order to do such thing, i think i have to acquire call context, and then restore it in later time.
The bad thing that i still haven't found functions in RPC API for polling client contexts and entering into certain context.
Maybe the functions for context polling is RpcMgmtEpEltInqBegin()/RpcMgmtEpEltInqNext()/RpcMgmtEpEltInqDone(), but i am unsure. I still haven't any ideas how i can activate context.
|
|
|
|
|
Hi, is there a way to compute usage of the stack size of a thread. More precisely, I'd like to know the maximum size that was used during the thread's life. Someone proposed to me that I fill the memory with a pattern before launching the thread, then looking at the end how much was overwritten, but I do not know how to get the thread stack pointer.
You guys have any ideas ?
"Invent a idiot-proof system and a new improved idiot will be invented"
|
|
|
|
|
Last i checked, it was still in the esp register (while the thread is executing, of course).
|
|
|
|
|
That won't get you the maximum size, only perhaps the current size.
|
|
|
|
|
Right. He was going to check for a pattern within the stack, see what changed during execution.
|
|
|
|
|
The trick is to fill the stack with a pattern before the thread is launched. Then, when the thread exits, dump the memory content and compare with an empty stack to compute the size. But I don't want to do this in a debugger, I want to write code that will compute that. So, I need to create a suspended thread, find it's stack pointer, fill it's memory with a pattern, then start the thread. And my problem is, how do I get the stack pointer of another thread ?
|
|
|
|
|
Zykalus wrote:
Then, when the thread exits, dump the memory content and compare with an empty stack to compute the size.
I see... You might want to have a look at GetThreadContext() then. Haven't used it myself, but it looks like just what you're looking for.
|
|
|
|
|
You might want to look at VirtualQuery.
The region size will be approximately how much memoryhas been commtted for stack size. I am pretty sure it never shrinks. Of course, the value is in the granularity of the syste's smallest allocation unit, which I think is 8K. But anyway, it gives you an idea if it used 64K versus 1 MB or such.
You need to pass the value of ESP register in as the lpAddress to the VirtualQuery call.
Use a little bit of inline assembler to get to it.
|
|
|
|
|
Thanks, I'll look into it. What I want to do is add debugging code in my app,. Currently, all threads are using the default size. But since I have a lot of threads, I just want to add in my thread code that will tell me how much was use during the thread life time.
"Invent a idiot-proof system and a new improved idiot will be invented"
|
|
|
|
|
Windows will expand the stack as needed.
Software Zen: delete this;
|
|
|
|
|
Hi all,
I was trying to trigger a button click event programmatically by doing
m_MyButton.SendMessage(BN_CLICKED);
but the event handler was not getting invoked. What did I do wrong and what's the correct way to do it?
Thank you for the help.
|
|
|
|
|
BN_CLICKED is not a message. It's a notification code to be used in the context of a WM_COMMAND message.
You need to send the WM_COMMAND message to the button's parent window, with the following parameters
wParam: MAKEWPARAM(id, BN_CLICKED)
lParam: m_MyButton.m_hWnd
where id is the numeric identifier of the button.
Example:
void CMyWindow::SomeMethod
{
SendMessage(WM_COMMAND, MAKEWPARAM(IDC_MY_BUTTON, BN_CLICKED), (LPARAM) m_MyButton.m_hWnd);
}
--
jlr
http://jlamas.blogspot.com/[^]
-- modified at 15:49 Wednesday 5th October, 2005
|
|
|
|
|
Ok, understand now.
Thank you very much!
|
|
|
|
|
Thanks Jose Lamas Rios for your solution. It helped me add button click event programmatically
|
|
|
|
|
Only one instance of the program can run at one time. When launching the program from explorer, the code below works just fine. But when I try to launch it from another program, the following occurs:
1)When an instance already exists, it only activates and maximizes the window when the window is in the minimized state. When it's not minimized but hidden behind other windows, it merely activates it (icon blinking in the taskbar) and does not maximize it or bring it to the foreground. Why is that?
2)When no instance exists, it launches the program but the window is not maximized or activated. It gets maximized only during initial startup.
Thanks!
BOOL CMyApp::InitInstance()
{
m_Instance = ::CreateMutex(NULL, FALSE, AfxGetApp()->m_pszExeName);
DWORD dwMutexErr = GetLastError();
if (dwMutexErr == ERROR_ALREADY_EXISTS)
{
CWnd *pPrevWnd = CWnd::GetDesktopWindow()->GetWindow(GW_CHILD);
while (pPrevWnd)
{
if ( ::GetProp(pPrevWnd->GetSafeHwnd(), AfxGetApp()->m_pszExeName) )
{
if ( pPrevWnd->IsIconic() )
pPrevWnd->ShowWindow(SW_RESTORE);
pPrevWnd->SetForegroundWindow();
pPrevWnd->GetLastActivePopup()->SetForegroundWindow();
return FALSE;
}
pPrevWnd = pPrevWnd->GetWindow(GW_HWNDNEXT);
}
}
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(MainFrame))
return FALSE;
m_pMainWnd = pMainFrame;
CCommandLineInfo cmdInfo;
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
ParseCommandLine(cmdInfo);
if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated)
return TRUE;
_Module.UpdateRegistryFromResource(IDR_APP, TRUE);
_Module.RegisterServer(TRUE);
if (!ProcessShellCommand(cmdInfo))
return FALSE;
pMainFrame->ShowWindow(SW_SHOWMAXIMIZED);
pMainFrame->UpdateWindow();
::SetProp(pMainFrame->GetSafeHwnd(), m_pszExeName, (HANDLE)1);
return TRUE;
}
-- modified at 13:11 Wednesday 5th October, 2005
|
|
|
|
|
|
1. Try BringWindowToTop .
2. Replace SW_RESTORE with SW_MAXIMIZE in the pPrevWnd->ShowWindow call.
Regards,
BB
http://spin.bartoszbien.com
|
|
|
|
|
The above proved unsuccessful. What I did try was minimize the window and then restore it if the window was not already minimized. You can see the window minimize and then pop back up for display. Why does minimizing it work? This seems like poor coding to me but it serves as a workaround? How can I make it more efficient? Thanks!
if ( !pPrevWnd->IsIconic() )
{
pPrevWnd->ShowWindow(SW_MINIMIZE);
}
pPrevWnd->ShowWindow(SW_RESTORE);
pPrevWnd->SetForegroundWindow();
pPrevWnd->GetLastActivePopup()->SetForegroundWindow();
|
|
|
|
|
Hi fellows
I'm a doubt: I have this program to read each line of a file and write into it again with some new values, but the program doesn't read the lines and in the message box, it show the value "0". Who can helps me to solve this?
I want to read all lines of my file and write values in a determined position.
Below the code, thanks a lot for help:
void EscreveArquivo(char* cValues)
{
notas* tNotas = new notas;
char* cValue = new char[256];
FILE* pFile;
bool bEnd = false;
char* c = new char[256];
pFile = fopen("c:\\arquivo.txt", "a");
if(pFile != NULL)
{
while(!feof(pFile))
{
fread(cValue,4,1,pFile);
tNotas->iNota = atoi(cValue);
MessageBox(0, itoa(tNotas->iNota,cValue,10),"tela",0);
notas* aux = new notas;
aux->next = tNotas;
tNotas = aux;
break;
}
while(!bEnd)
{
//fread(tNotas, sizeof(tNotas), 1, pFile);
//tNotas->iNota += atoi(cValues);
switch(tNotas->iNota)
{
case 1:
i1Real += 1;
break;
}
itoa(i1Real,cValue, 10);
fseek(pFile, 2, 0);
fwrite(cValue, 1, 1, pFile);
if(tNotas->next == NULL)
{
bEnd = true;
}
tNotas = tNotas->next;
}
}
fclose(pFile);
delete tNotas;
delete[] cValue;
}
int main()
{
char* cBuffer = new char[256];
EscreveArquivo(itoa(10,cBuffer,10));
|
|
|
|
|
Alex Cutovoi wrote:
fread(cValue,4,1,pFile);
tNotas->iNota = atoi(cValue);
If you know the first item to read from the file is a number, why not treat it as such?
fread(&tNotas->iNota, sizeof(int), 1, pFile); Alex Cutovoi wrote:
tNotas->iNota = atoi(cValue);
atoi() will not work unless cValue is nul terminated.
What exactly are you trying to do? All of the calls to atoi() and itoa() appear to be making things unnecessarily hard.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
|