|
The code is:
void DataCryptMain ::ProcessCrypt()
{
...
cryptthread.Start(_staticThreadProc, this)
...
}
DWORD WINAPI _staticThreadProc(LPVOID lpData)
{
DataCryptMain *dcr = reinterpret_cast<datacryptmain>(lpData);
return dcr->CryptThreadProc(NULL);
}
DWORD WINAPI DataCryptMain::CryptThreadProc(LPVOID lpData)
{
int iErrorOrInfo = INFO_PROCESS_DONE;
iErrorOrInfo = CryptoRijnDaelProcess();
Notify_Progress_GUI(NOTIFY_PROGRESS_END, NULL, iErrorOrInfo);
return 0;
}
void DataCryptMain::Notify_Progress_GUI(int iNotificationType, WPARAM wParam, LPARAM lParam)
{
if (iNotificationType == NOTIFY_PROGRESS_RUNNING)
{
PostMessage(hWnd, WM_PROGRESS_RUNNING, wParam, lParam);
}
else
{
PostMessage(hWnd, WM_PROGRESS_END, wParam, lParam);
}
}
bool _ProgressBarProc(PRBDATA *prbdata)
{
DataCryptMain *dcr = reinterpret_cast<datacryptmain>(prbdata->lpOtherData);
return dcr->ProgressBarProc(prbdata);
}
bool DataCryptMain::ProgressBarProc(PRBDATA *prbdata)
{
if (cryptthread.WaitToExit()) return TRUE;
PRBDATA *_prbdata = new PRBDATA;
memcpy(_prbdata, prbdata, sizeof(PRBDATA));
Notify_Progress_GUI(NOTIFY_PROGRESS_RUNNING, NULL, (LPARAM)_prbdata);
return FALSE;
}
int DataCryptMain::CryptoRijnDaelProcess()
{
int iErrorOrInfo = OK;
RijnDaelCrypto *rdc = new RijnDaelCrypto;
...
...
SetProgressFunc(_ProgressBarProc, (LPVOID)this);
------------------- Here this function loops through the file encryption
if (rdc->Encrypt(wcgFileNameIn, wcgFileNameOut, cryptParams.iCipherMode) < 0)
iErrorOrInfo = ERR_PROCESS_STOPPED_BY_USER;
_DELETE(rdc);
return iErrorOrInfo;
}
bool DataCryptMain::OnProgressRunning(WPARAM wParam, LPARAM lParam)
{
float fPercent[3];
char sTemp[64];
PRBDATA *prbdata = reinterpret_cast<prbdata>(lParam);
fPercent[0] = ((float)prbdata->iReadBytesIncByFuncRead / (float)prbdata->dwSize) * 100.0f;
fPercent[1] = ((float)prbdata->iBlocksIncrement / (float)prbdata->iBlocksNum) * 100.0f;
fPercent[2] = (fPercent[0] + fPercent[1]) / 2;
SendDlgItemMessage(hWnd, IDC_PROGRESSSTATUS, PBM_SETPOS, (WPARAM)fPercent[2], 0);
sprintf_s(sTemp, "%0.1f %%", fPercent[2]);
SetDlgItemText(hWnd, IDC_PERCENT1, sTemp);
sprintf_s(sTemp, "%d bytes", prbdata->dwSize);
SetDlgItemText(hWnd, IDC_FILESIZE, sTemp);
sprintf_s(sTemp, "%d bytes", prbdata->iReadBytesIncByFuncRead);
SetDlgItemText(hWnd, IDC_READBYTES, sTemp);
sprintf_s(sTemp, "%d block/s", (int)prbdata->iBlocksIncrement);
SetDlgItemText(hWnd, IDC_BLOCKSPROCESSED, sTemp);
_DELETE(prbdata);
return FALSE;
} </prbdata></datacryptmain></datacryptmain>
modified on Thursday, January 29, 2009 9:03 AM
|
|
|
|
|
At the first look i don't see any obvious errors (althorough they might be there and i am a blind mouse). Try pausing your (DEBUG build) programs's execution in VS (with the pause button on the toolbar for example) and check what your threads are doing, you might find out what your GUI thread seems to be waiting for. You could also try placing a sleep here and there to see if the situation gets any better or not, if it does then most likely it's the "run away thread" thing, or try removing the PostMessage from the thread temporarily, or make it Post a message every 100th time it is called and run your program to see if your GUI is reponsive or not, if it is, than it is likely you are flooding it with the "status-report" messages.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
If it works as i've shown it uses about 86% of CPU, the changes are displayed but I can't, for example, move the window or push a button.
If i place a sleep function then it works OK
About the first you'said, i didn't understand "you might find out what your GUI thread seems to be waiting for"
|
|
|
|
|
Dennis L wrote: About the first you'said, i didn't understand "you might find out what your GUI thread seems to be waiting for"
I mean, when you break the execution of your program you can check out where that execution was in your code (assuming you have debug information) so you can see where your GUI thread gets stuck, the debugger shows you, it will point at the place where the program was halted. But if everything works with a sleep then for now you can forget about this part.
Where did you place the sleep? Does this sleep slow down the thread that is posting the messages towards your GUI thread? If yes, then i'd say you are flooding your GUI with messages. Try to decrease the number of messages sent to your GUI, for example, send only every 10th status report, or check when you sent the last report and if a given amount of time (like,for exaple 100 ms) didn't ellapse yet then skip sending the message, OR perform the percentage calculation in your thread and only send a message towards the GUI if the new percentage is different from the previous one, this should reduce the messages heading towards the GUI to not more than around a 100 messages per run, which shouldn't be too much, unless you are some very low end hardware.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I have placed the Sleep in the progress callback function as:
bool DataCryptMain::ProgressBarProc(PRBDATA *prbdata)
{
...
Notify_Progress_GUI(NOTIFY_PROGRESS_RUNNING, NULL, (LPARAM)_prbdata);
Sleep(1);
}
You said: "Try to decrease the number of messages sent to your GUI, for example, send only every 10th status report, or check when you sent the last report and if a given amount of time (like,for exaple 100 ms) didn't ellapse yet then skip sending the message, OR perform the percentage calculation in your thread and only send a message towards the GUI if the new percentage is different from the previous one, this should reduce the messages heading towards the GUI to not more than around a 100 messages per run, which shouldn't be too much, unless you are some very low end hardware"
All these i'll try them by using PostMessage or SendMessage?
|
|
|
|
|
The code you posted is horribly formatted and missing < and > symbols and what's between them.
Steve
|
|
|
|
|
Please post code snippets..
Regards,
Sandip.
|
|
|
|
|
I wrote a simple app that hooks WH_MOUSE events. The application receives a stream of events when the mouse is moved over most windows. However it does not get any events from:
- the Command (MSDOS) application
- the menu bar of old (16-bit?) applications such as Calculator or Paint.
- the title bar of all apps
How can catch mouse messages in these cases?
--
Goop
|
|
|
|
|
Please mention the problem clearly.
|
|
|
|
|
Mmm, I thought I had
It seems that the Command/MSDOS window is capturing mouse movements before my application. As my application was started from that window, I assumed that my app would be earlier in the hook list and therefore receive messages first. But the app does not see the mouse movements for the Command window.
I guess the problem goes deeper, because I want to see ALL mouse movements, wherever my hook is in the hooks list. So I guess I need to get the messages before any hook functions.
Hope that is clearer
Regards
--
Goop
|
|
|
|
|
Command/DOS applications do not have a message loop.
But you should get mouse messages on title bars of Windows apps using this hook.
If not you should try WH_MOUSE_LL .
«_Superman_»
|
|
|
|
|
Thanks for your reply. You are right, messages really are received on title bars. I needed to test for the Non-Client messages, WM_NCRBUTTONDOWN, as well as for WM_RBUTTONDOWN. This also fixes it for the menu bars of Calculator/Paint.
But the Command/MSDOS window still somehow captures messages - I see none of them, even for the title bar. How does it do this (ie. which API)? Does this mean that keyloggers also cannot intercept text typed into the Command window? This would imply that an application should grab the keyboard events directly (as in Command) to avoid snooping, eg during password entry.
Regards
--
Goop
|
|
|
|
|
Hi
In my project, the controls have to be created depending on the user input, which will be made at the beginning.
Depending on the user input, the controls have to be created at Runtime.
How to create Resource ID for Form View, Static Control, Tool Bar, Menu, Dialog Bar in VC++ at the Runtime?
Thank you
Preethi
|
|
|
|
|
Does this article[^] help?
Regards,
Sandip.
|
|
|
|
|
Why not just create them at design time, and then enable/disable them accordingly? It's much easier that way.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hello,
i use a function MultiByteToWideChar() to show Unicode letters, Arabic and Cyrillic letters are showed properly,
but not the Chinese or Korean or Japanese letters!
I try to show text from Internet in my list control, but they are only a funny square showed instead of letters ,
does any one have suggestion how to start to solve my issue?
Thanks for any help
termal
|
|
|
|
|
Are you sure the font in the edit control has these characters? You can use the charmap utility to check.
Also guessing, did you create the control using CreateWindowW? Maybe the control is being all ASCII-y ?
Try making your project UNICODE (which you should anyway) and see if the problem goes away?
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Hi,
first thanks for answer!
I create a dialog with the designer of VS and the CListCtrl i added from a toolbox!
And project is in unicode, other languages are showed normal!
"Are you sure the font in the edit control has these characters? You can use the charmap utility to check"
This can be a reason tor my problem, i use Tahoma as font for all my dialogs and i can't find any chinese character in charmap utility!!
regards
termal
|
|
|
|
|
You may need to install the language pack for Asian languages.
«_Superman_»
|
|
|
|
|
Hi,
yes i found that they are not installed by default!
regards
termal
|
|
|
|
|
Hi,
i found my font it's Arial Unicode MS
bye
termal
|
|
|
|
|
I want to change the image of the toolbar button, that is, When I cilcked one tool bar button then I want to change the image of the button. So I have used the following code, but it saying some runtime error.
CToolBarCtrl &ctrl = m_wndToolBar.GetToolBarCtrl();
ctrl.AddBitmap(3,IDB_BITMAP3);
Pls provide me some solution,
|
|
|
|
|
try using LoadImages(). and what is this AddBitmap?
|
|
|
|
|
gopalraja wrote: ctrl.AddBitmap(3,IDB_BITMAP3);
This function is used to add bitmap to imagelist associated with toolbar control.
Look at function SetImageList, and use it according to your need.
Images on toolbar shown according to imagelist associated with that toolbar control.
|
|
|
|
|
Hi,
You can set cold and hot images for the toolbar.
This is the sample code.
CImageList img;
img.Create(IDB_HOTTOOLBARS, 22, 0, RGB(128, 128, 128));
m_wndToolBars.GetToolBarCtrl().SetHotImageList(&img);
img.Detach();
img.Create(IDB_COLDTOOLBAR, 22, 0, RGB(255, 255, 255));
m_wndToolBars.GetToolBarCtrl().SetImageList(&img);
img.Detach();
Here m_wndToolBars is the CToolBar object.And IDB_HOTTOOLBARS and IDB_COLDTOOLBAR are the Bitmap imges in the resourse editor.
Regards
Arun
|
|
|
|
|