|
john5632 wrote: Any problem with API to transdfr the string to server into UNOCIDE format?
Assuming both ends are working in Unicode there should be no problems. You need to check both ends are following the same rules.
I must get a clever new signature for 2011.
|
|
|
|
|
Is the incorrect size comes in debug version? Please run in release mode and analyze nFileLen by means of messagebox or some thing else.
|
|
|
|
|
i wanted to create dynamically popupmenu on clicking rightclick... the item may very more than thousands worst case otherwise hundreds only. Is it possible?
|
|
|
|
|
yogish293 wrote: s it possible?
Did you try?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
For how long are you going to repost the same question ? You already got a lot of answers suggesting that it was a very bad design. Why don't you look at it from the user point of view and see if you can't use a more user-friendly approach ?
|
|
|
|
|
How much more information do you need on this? You have already been shown:
- This is not a good design, and you should consider alternatives.
- If you insist on doing it this way then you probably need to use a virtual menu - i.e. owner drawn.
I must get a clever new signature for 2011.
|
|
|
|
|
In that case instead of using regular menu , create a WS_POPUP style window, and handle the drawing and messages for performance improvement.
If u can Dream... U can do it
|
|
|
|
|
I guess you have to back to your class because its not a problem its very a basic question to write it,I think you dont know this secret(we have a site on the net its name is codeproject it has many articles(about menus and pop up menus,....)
Please dont read this post its a secret.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
|
Anything is possible; the question is: IS IT FEASABLE?
Why would you want to create menu with hundreds, not to mention thousand items. Put yourself in a position of a user of your application and imagine browsing hundreds of items to find one to choose.
You have to rethink your design.
JohnCz
MS C++ MVP
|
|
|
|
|
I am running my code in Winodws 7. I am using MessageBox() but it's not showing in the screen. The control is reaching there.
|
|
|
|
|
This is a very vague description.
You could try setting the hWnd parameter to HWND_DESKTOP.
Or Open Spy++ (aka SpyXX) from the Vistual Studio Tools Menu. Then find your application window in the Windows page. The message box should be a child window of the window you provide to the hWnd parameter
|
|
|
|
|
is it a windows service you are writing?
|
|
|
|
|
Whats the return value of MessageBox?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hi all,
I have 2 hard disk in my system. I want to get Logical drives of both hard drives i.e. Physical drive 1 contains c: and e: partitions and Physical drive 2 contains d: f: and g: partitions. I have used this code to get the hard disk details.... but it is giving wrong result....
TCHAR szTemp[BUFSIZE];
szTemp[0] = '\0';
if (GetLogicalDriveStrings(BUFSIZE-1, szTemp))
{
TCHAR szName[MAX_PATH];
TCHAR szDrive[MAX_PATH] = TEXT(" :");
BOOL bFound = FALSE;
TCHAR* p = szTemp;
do
{
*szDrive = *p;
if (QueryDosDevice(szDrive, szName, BUFSIZE))
{
CString str = szDrive;
str = str+szName;
m_Tree_Ctrl.InsertItem(str,root,TVI_LAST);
}
while (*p++);
} while (!bFound && *p);
}
m_Tree_Ctrl.Expand(root,TVE_EXPAND);
It is making a tree like
Drives
C:\Device\Harddiskvolume1
D:\Device\Harddiskvolume2
E:\Device\Harddiskvolume3
.
.
.
I am not getting what exactly is the problem...
Can anybody help me in this...
Thanks in advance
|
|
|
|
|
 This is a function in 1 of my utilities which does what i thiny you are wanting
#include <windows.h>
#include <stdio.h>
LPCSTR FormatSize(QWORD nSize) {
static char szSize[16];
if (nSize < 1024) {
sprintf(szSize, "%uB", nSize);
} else {
char szScales[] = "KMGTPEZY";
int nScale = 0;
for (; nScale < sizeof(szScales); ++nScale) {
if (nSize < 1024 * 1024) {
sprintf(szSize, "%6.2f%cB", nSize / 1024.0f, szScales[nScale]);
break;
}
nSize = (nSize + 512) / 1024;
}
if (nScale == sizeof(szScales)) {
strcpy(szSize, "Unknown Size");
}
}
return szSize;
}
void PrintDrives(char *szDrives) {
DWORD nDrives = GetLogicalDrives();
char szDrive[] = "A:\\";
char szDriveName[MAX_PATH + 1];
int nPrintedDrives = 0;
while (nDrives != 0) {
if (nDrives & 1) {
szDrives[nPrintedDrives] = szDrive[0];
GetVolumeInformation(szDrive, szDriveName, sizeof(szDriveName), NULL, NULL, NULL, NULL, 0);
QWORD nAvaliable;
QWORD nTotal;
QWORD nFree;
if (!GetDiskFreeSpaceEx(szDrive, (PULARGE_INTEGER)&nAvaliable, (PULARGE_INTEGER)&nTotal, (PULARGE_INTEGER)&nFree)) {
nAvaliable = 0;
nTotal = 0;
nFree = 0;
}
if (*szDriveName == 0) {
if (nTotal > 0) {
printf("%s (%s)\n", szDrive, FormatSize(nTotal));
} else {
printf("%s (Unknown Size)\n", szDrive);
}
} else {
if (nTotal > 0) {
printf("%s (%s) [%s]\n", szDrive, FormatSize(nTotal), szDriveName);
} else {
printf("%s (Unknown Size) [%s]\n", szDrive, szDriveName);
}
}
}
nDrives >>= 1;
++szDrive[0];
}
}
int main(int argc, char *argv[]) {
char szDrives[27];
szDrives[26] = 0;
PrintDrives(szDrives);
return 0;
}
|
|
|
|
|
How do I terminate a thread from outside of that thread.
My thread contains some function iand it takes some time to finish it .
i want when i send signal to stop thread its should stop immedeatily.
CWinThread *Th;
Th = AfxBeginThread( RUNTIME_CLASS(CTest_Thread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL);
if (NULL != Th)
{
Th >ResumeThread();
}
Th ->PostThreadMessage(WM_QUIT,NULL,NULL);
after using postthreadmessage to exit its not stop the thread immediately and its takes full time to perform thread functioning than stop and exit this.
so please tell me how can i stop the thread imeediately from outside of thread.
|
|
|
|
|
You define your own custom message and then override CWinThread::PreTranslateMessage http://msdn.microsoft.com/en-US/library/67d74wsy(v=VS.80).aspx[^].
The thread intercepts messages before your main application does, so you cannot use WM_QUIT or other windows messages without affecting your application.
in the header file
#define CM_KILL_THREAD WM_USER + 0 //can go up to WM_USER + 0x7BFF
class CTest_Thread : public CWinThread {
protected:
virtual BOOL PreTranslateMessage(MSG *pMsg);
};
in the source file
BOOL CTest_Thread::PreTranslateMessage(MSG *pMsg) {
if (pMsg->message == CM_KILL_THREAD) {
ExitThread(0);
return TRUE;
}
return FALSE;
}
in your code
Th->PostThreadMessage(CM_KILL_THREAD, 0, 0);
Edit: corrected invalid indentation error
modified on Thursday, January 13, 2011 1:24 AM
|
|
|
|
|
Andrew Brock wrote: ExitThread(0); //0 is the return code, if you need to send a message back to your application
return TRUE; //I have procesed the message, nothing else needs to
BOOL CTest_Thread::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == ERR_KILL_THREAD)
{
ExitThread(0);
return TRUE;
}
return FALSE;
}
error on these line
1. error C2065: '' : undeclared identifier
2. error C2146: syntax error : missing ';' before identifier 'ExitThread'
modified on Thursday, January 13, 2011 1:18 AM
|
|
|
|
|
It is an indentation problem... delete the 2 tabs infront of the ExitThread, then put them back, there is an invalid character hiding in there at the first character on the line
|
|
|
|
|
thanks no compiling errors are resolved.
but i m stuck at this point.
i m using this inside the thread
CCriticalSection sec_s;
CSingleLock lock(&sec_s);
lock.Lock();
lock.Unlock();
so thread not close immediately even after send message as you said.
modified on Thursday, January 13, 2011 1:58 AM
|
|
|
|
|
Threads will very rarely close immediately after you tell it to. The reasons are too complex for me to explain here, but that isn't very important to this.
All that matters is that you wait for it to close. We do this with WaitForSingleObject http://msdn.microsoft.com/en-us/library/ms687032(v=vs.85).aspx[^], which will wait for almost anything that has a HANDLE
Th->PostThreadMessage(CM_KILL_THREAD, 0, 0);
switch (WaitForSingleObject(Th->m_hThread, 5000)) {
case WAIT_OBJECT_0:
TRACE("Thread terminated.\n");
break;
case WAIT_TIMEOUT:
TRACE("Wait for terminate timed out.\n");
break;
default:
TRACE("WaitForSingleObject failed with error %d.\n", GetLastError());
break;
}
DWORD nRetCode;
GetExitCodeThread(hRemoteThread, &nRetCode);
Be very careful with the earlier suggestion of TerminateThread, it can end badly. See http://msdn.microsoft.com/en-us/library/ms686717(v=vs.85).aspx[^] for more details
|
|
|
|
|
once i use TerminateThread when i call this to terminate the thread my application is hanged and looks disabled and not respond ever after long time,so im scared and not want to to use TerminateThread,please tellme any other option or tell me where i can use WaitForSingleObject.
|
|
|
|
|
That code I supplied earlier kills the thread by posting the CM_KILL_THREAD message that I showed you earlier and waits for it to terminate itself.
You may consider making it into a function like
DWORD KillThreadAndWait(CTest_Thread *pThread, DWORD nTimeoutMs = 5000) {
HANDLE hThread = pThread->m_hThread;
pThread->PostThreadMessage(CM_KILL_THREAD, 0, 0);
switch (WaitForSingleObject(hThread, nTimeoutMs)) {
case WAIT_OBJECT_0:
TRACE("Thread terminated.\n");
break;
case WAIT_TIMEOUT:
TRACE("Wait for terminate timed out.\n");
return 0x80000000;
default:
TRACE("WaitForSingleObject failed with error %d.\n", GetLastError());
return 0x80000001;
}
DWORD nRetCode;
GetExitCodeThread(hThread, &nRetCode);
return nRetCode;
}
Then your code from earlier would look like
CTest_Thread *pThread;
pThread = (CTest_Thread *)AfxBeginThread(RUNTIME_CLASS(CTest_Thread), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED, NULL);
if (pThread != NULL) {
pThread->ResumeThread();
}
TRACE("Thread exited with code 0x%08X\n", KillThreadAndWait(pThread, 5000));
Also, a correction from earlier, instead of using ExitThread, http://msdn.microsoft.com/en-us/library/s3w9x78e(v=vs.80).aspx says "To end the thread, call AfxEndThread from within the thread, or return from the controlling function of the worker thread."
BOOL CTest_Thread::PreTranslateMessage(MSG *pMsg) {
if (pMsg->message == CM_KILL_THREAD) {
AfxEndThread(0);
return TRUE;
}
return FALSE;
}
EDIT: Corrected wrong variable name
modified on Thursday, January 13, 2011 3:17 AM
|
|
|
|
|