|
Many thanks, I am unworthy!
|
|
|
|
|
El debugero says that Track PopupMenu is returning a zero...what gives?
bool bDone = false;<br />
int x,y;<br />
HTREEITEM hSelectedItem;<br />
DWORD mousePosition;<br />
mousePosition = ::GetMessagePos();<br />
x = GET_X_LPARAM(mousePosition);<br />
y = GET_Y_LPARAM(mousePosition);<br />
<br />
<br />
CMenu newMenu;<br />
newMenu.CreatePopupMenu();<br />
bDone = newMenu.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,x,y, <br />
AfxGetApp()->m_pMainWnd,NULL);<br />
if(bDone)<br />
Beep(678,46);<br />
<br />
<br />
hSelectedItem = this->m_SetUpTree.GetSelectedItem();<br />
<br />
<br />
*pResult = 0;
|
|
|
|
|
If this is the exact code you're using, then the problem is that you're not adding items to the menu before you call TrackPopupMenu(). You have to either call newMenu.LoadMenu() to load a menu from a resource, or call newMenu.InsertMenu()/AppendMenu() to create the menu items at runtime.
At the moment, you're trying to display a menu with no items in it.
Ryan Binns
He who laughs last... thinks too slowly.
|
|
|
|
|
With this code I get a menu but it's about 1 mm thick. I don't see any functions that let me adjust the size or shape of the new menu...
void CSacmanSetupDlg::OnRclickSacmanSetupTree(NMHDR* pNMHDR, LRESULT* pResult) <br />
{<br />
int x,y;<br />
int menuHandle;<br />
bool bDone = false;<br />
char * newItem = "Does It Work?";<br />
<br />
UINT nPosition = 0;<br />
HTREEITEM hSelectedItem;<br />
DWORD mousePosition;<br />
<br />
mousePosition = ::GetMessagePos();<br />
x = GET_X_LPARAM(mousePosition);<br />
y = GET_Y_LPARAM(mousePosition);<br />
<br />
<br />
CMenu newMenu;<br />
<br />
newMenu.CreateMenu();<br />
newMenu.InsertMenu(nPosition,MF_POPUP,menuHandle,newItem);<br />
<br />
<br />
newMenu.EnableMenuItem(1,MF_BYPOSITION);<br />
newMenu.TrackPopupMenu(TPM_CENTERALIGN,x,y,<br />
::AfxGetMainWnd(),0);<br />
if(bDone)<br />
Beep(678,46);<br />
<br />
<br />
hSelectedItem = this->m_SetUpTree.GetSelectedItem();<br />
<br />
<br />
*pResult = 0;<br />
}
I'm vexed...
|
|
|
|
|
You can't adjust the size or shape of the menu (not without using owner-draw anyway), but 99.9% of the time you won't have to. Windows will automatically size the menu based on its contents.
What you have done here is created a menu with a single item in it - a submenu that has no items, and you haven't given the submenu a name. If an item's name has no characters, then nothing is displayed and the menu is very thin, which is exactly what is happening.
To add useful items to your menu, use the following:
<br />
newMenu.InsertMenu(nPosition, MF_BYPOSITION | MF_STRING, ID_MENU_ITEM, strMenuText);<br />
Where:
ID_MENU_ITEM is the menu item identifier of your menu item
strMenuText is the text of your menu item ("Cut", "Copy", etc...)
Ryan
He who laughs last thinks too slowly.
|
|
|
|
|
Is the ID_MENU_ITEM a menu resource that I create in the resource editor? If so, what is the difference between load menu and insert menu? I'm not a work right now so I can't take a look at the documentation...
|
|
|
|
|
adonisv wrote:
Is the ID_MENU_ITEM a menu resource that I create in the resource editor?
NO! As I said before, ID_MENU_ITEM is the identifier of a menu ITEM, not a whole menu. If you want to load a menu from a resource, then you have to use LoadMenu(). All this is in the documentation.
Ryan
He who laughs last thinks too slowly.
|
|
|
|
|
Thanks man, that sucked! I went the Load Menu route, although the instructions you gave me worked as well. I had to create a menu called ID_INITIAL_MENU. Then in the properites section, I had to check popup. Then create ID's and captions for each new popup I wanted in the menu. Once the menu was associated with a class I was able to add message maps that allow me to do something when the pop up menu's were selected. I think those were the steps I really needed. Thanks for putting up with me though...;P
|
|
|
|
|
How do i read JPEG ,GIF files to get the following info ...
1.Image Width
2.Image Height
3.Monochromw or color
4.Frame Rate ( for Gif)
Can some one give the code along with the Header structure of JPEG,GIFF
|
|
|
|
|
Take a look at CXImage - http://www.codeproject.com/bitmap/cximage.asp
Dave
|
|
|
|
|
Hi,
In a dialog-based application, i have a a worker
thread which read 256k data from Cdrom at one times (step).
But it failed with memory leak. Would you please
provide me a safe thread method to be used for my problem?
I see many example code of the "thread", but i don't know
which one is best for my problem.
Thanks in advance!
chen
|
|
|
|
|
If you're using AfxBeginThread then it's possible to have the returned CWinThread* as memory leak.
rechi
|
|
|
|
|
Thanks!
but how to solve this problem (i really used AfxBeginThread function)
and there is 256K data needed read from CD and save it to a file for
each iteration step.
chen
|
|
|
|
|
chen wrote:
there is 256K data needed read from CD and save it to a file
I don't know if this is the problem, it might work fine.
Save the CWinThread* returned by AfxBeginThread and delete it after the thread terminates.
rechi
|
|
|
|
|
The following is the part of the code, would you please try to
find where is my mistake?
class CEfmraDlg : public CResizableDialog
{
public:
CEfmraDlg(CWnd* pParent = NULL);
struct SToto
{
BOOL m_bToto;
};
static UINT StartThreadEfmRead (LPVOID param);
...........
bool m_bStop;
}
void CEfmraDlg::OnEfmRead()
{
m_bStop = FALSE;
SToto stToto;
stToto.m_bToto = TRUE;
AfxBeginThread(CEfmraDlg::StartThreadEfmRead, this);
}
UINT CEfmraDlg::StartThreadEfmRead (LPVOID param)
{
char buff1[100];
CEfmraDlg* ts = (CEfmraDlg*)param;
if(ts->m_scsi.EFM_open(newSparam) == 0)
{
FILE *fp;
if( NULL == (fp = fopen("cd.txt", "wb"))){
ts->m_ListBox.AddString("Open cd.txt error");
}
ts->m_ListBox.AddString("Read CD begin ...");
int count = 0;
for(;
{
count++; //256k
if(ts->m_bStop)
{
ts->m_ListBox.AddString("Read EFM data aborted.");
ExitThread(0);
break;
}
if(ts->m_scsi.EFM_read(fp))
{
ts->m_ListBox.AddString("Read Error!");
ExitThread(0);
break;
}
memset(buff1, 0, 100);
sprintf(buff1,"CD Reading - Count: %d Bytes: %d", count, count*256*1024);
ts->m_diff = buff1;
ts->ShowText();
}
ts->m_scsi.EFM_close();
fclose(fp);
AfxEndThread (0);
return 0;
}
return 1;
}
chen
|
|
|
|
|
Replace ExitThread(0) with AfxEndThread(0) . Don't mix up these calls when you're using MFC.
When you're exiting the thread because of some read error or abort you have to call fclose(fp) . This could be your memory leak, with the greatest probability.
Use CWinThread *pThread = AfxBeginThread(CEfmraDlg::StartThreadEfmRead, this) . If your program ends before the thread exits, then you must delete pThread.
rechi
|
|
|
|
|
I have tried using AfxEndThread(0), the result is same. In addition, when quit/abort from the thread the fclose(fp) really
called at the end of the UINT CEfmraDlg::StartThreadEfmRead (LPVOID param).
I will try to remove the
struct SToto
{
BOOL m_bToto;
};
and using CWinThread *pThread = AfxBeginThread(CEfmraDlg::StartThreadEfmRead, this).
and delete the pThread try again.
chen
|
|
|
|
|
When i using using CWinThread *pThread = AfxBeginThread(CEfmraDlg::StartThreadEfmRead, this).
How to delete the pThread and transfer the varibles?
chen
|
|
|
|
|
chen wrote:
In addition, when quit/abort from the thread the fclose(fp) really
called at the end of the UINT CEfmraDlg::StartThreadEfmRead (LPVOID param)
Be careful, when you call AfxEndThread(0) , the thread is killed on the spot! The call you are talking about will not be executed; put fclose(fp) before any AfxEndThread(0) call.
chen wrote:
How to delete the pThread and transfer the varibles?
You don't have to transfer any variable, judging by what i saw in your code. To delete pThread, try this:
try {
if (pThread->ExitInstance())
delete pThread;
}
catch(...)
{
TRACE("never mind\n");
}
Not the best option but it's easy to write
rechi
|
|
|
|
|
Would you like re-write above code onece again by using your
method?
chen
|
|
|
|
|
Gee, you really are persistent
Let's do it:
class CEfmraDlg : public CResizableDialog
{
CWinThread *pThread;
public:
CEfmraDlg(CWnd* pParent = NULL);
virtual ~CEfmraDlg()
{
try
{
if (pThread)
if (pThread->ExitInstance())
delete pThread;
}
catch(...)
{
TRACE("never mind\n");
}
}
struct SToto
{
BOOL m_bToto;
};
static UINT StartThreadEfmRead (LPVOID param);
bool m_bStop;
}
void CEfmraDlg::OnEfmRead()
{
m_bStop = FALSE;
SToto stToto;
stToto.m_bToto = TRUE;
pThread = AfxBeginThread(CEfmraDlg::StartThreadEfmRead, this);
}
UINT CEfmraDlg::StartThreadEfmRead (LPVOID param)
{
char buff1[100];
CEfmraDlg* ts = (CEfmraDlg*)param;
if(ts->m_scsi.EFM_open(newSparam) == 0)
{
FILE *fp;
if( NULL == (fp = fopen("cd.txt", "wb")))
{
ts->m_ListBox.AddString("Open cd.txt error");
}
ts->m_ListBox.AddString("Read CD begin ...");
int count = 0;
for(; count<=256*1024; )
{
count++;
if(ts->m_bStop)
{
ts->m_ListBox.AddString("Read EFM data aborted.");
fclose(fp);
AfxEndThread(0);
}
if(ts->m_scsi.EFM_read(fp))
{
ts->m_ListBox.AddString("Read Error!");
fclose(fp);
AfxEndThread(0);
}
memset(buff1, 0, 100);
sprintf(buff1,"CD Reading - Count: %d Bytes: %d", count, count*256*1024);
ts->m_diff = buff1;
ts->ShowText();
}
ts->m_scsi.EFM_close();
fclose(fp);
AfxEndThread (0);
}
return 1;
}
rechi
|
|
|
|
|
could any one give me or tell me where I can download c library for soket.h and other internet library? thanks;P
|
|
|
|
|
Does anyone know of a way to detect if a volume is set up as a Dynamic Drive ? I know that the System ID field of the partition table will be set to 0x42 but cannot determine a way to access this information using the SDK.
|
|
|
|
|
Just a guess: Open drive, read sector 1, cylinder 0.....
|
|
|
|
|
Nope.
I found it late yesterday. In the hardware SDK using DeviceIoControl(), however at the moment I am getting access errors, but I am sure I will get around those. Thanks for your help.
|
|
|
|