|
One method would be to have the MainFrame() the owner of the menu in the call to TrackPopupMenu(). The other would be to look at the code for
void CFrameWnd::OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu)
to see how its done there any in effect mirror the code yourself.
If you vote me down, my score will only get lower
|
|
|
|
|
Between calls to GetSubMenu() and TrackPopupMenu() , you should be able to use CheckMenuItem() .
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Yeah it's fine setting the check state, but I'd like to do it through the normal cmd UI mechanism. Much more elegant!
Joel Holdsworth
|
|
|
|
|
Joel Holdsworth wrote:
Much more elegant!
Agreed. Here's how I did it:
BEGIN_MESSAGE_MAP(CMyView, CListView)
ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
ON_UPDATE_COMMAND_UI(ID_ITEM_DELETE, OnUpdateItemDelete)
END_MESSAGE_MAP()
void CMyView::OnRclick(LPNMHDR, LRESULT* pResult)
{
CListCtrl &ctrlList = GetListCtrl();
CPoint pt;
CMenu menu,
*pSubMenu;
if (ctrlList.GetNextItem(-1, LVIS_SELECTED) != -1)
{
menu.LoadMenu(IDR_ITEM_MENU);
pSubMenu = menu.GetSubMenu(0);
pt = GetMessagePos();
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN, pt.x, pt.y, this);
}
*pResult = 0;
}
void CMyView::OnUpdateItemDelete(CCmdUI* pCmdUI)
{
CListCtrl &ctrlList = GetListCtrl();
pCmdUI->Enable(ctrlList.GetNextItem(-1, LVIS_SELECTED) != -1);
} Now the Delete item in the main menu, the toolbar button, and the context menu is enabled/disabled correctly.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hmm, that interesting. I'm basically doing the exact same thing, but it's not working. Maybe it's because your class is derrived from CView rather than CWnd, so MFC has added some voodoo magic. I'm not sure.
Joel Holdsworth
|
|
|
|
|
Aha.... Solved it. Just a case of tweaking the standard message routing a little:
BEGIN_MESSAGE_MAP(CLiveView, CWnd)
...
ON_MESSAGE(WM_INITMENUPOPUP, OnInitMenuPopup)
END_MESSAGE_MAP()
LRESULT CLiveView::OnInitMenuPopup( WPARAM wparam, LPARAM lparam )
{
return AfxGetMainWnd()->SendMessage(WM_INITMENUPOPUP, wparam, lparam);
} Thanks for your help.
Joel Holdsworth
|
|
|
|
|
char *a[5];
Above line allows me to enter 5 strings like *(a+1) etc.
thats fine when # of do not change.
How can i do it dynamically, ie. user enters the # of strings to be entered.
char *a;
a = new char[5];
above one only allocates 5 characters and not 5 strings
Please help thanx.
|
|
|
|
|
Just use char ** a to represent a "pointer to pointer to char." You can then allocate 5 strings of length 10 characters as follows:
a = new char ** [5];
for(int Index = 0; Index < 5; Index++)
{
a[Index] = new char [10];
}
Bob Ciora
|
|
|
|
|
Bob Ciora wrote:
a = new char ** [5]; // should be checked for NULL
It should be that instead:
a = new char * [5]; // should be checked for NULL
|
|
|
|
|
char (*a)[5];
a=(char**)new char;
-- modified at 1:48 Monday 29th August, 2005
|
|
|
|
|
#include "stdafx.h"
#include <iostream.h>
int main(int argc, char* argv[])
{
int NumOfStr = 0, StringLength = 10;
//get number of strings from the user
cout << "Enter number of strings: ";
cin >> NumOfStr;
char **a;
a = new char * [NumOfStr];
for(int Index = 0; Index < NumOfStr; Index++)
{
a[Index] = new char [StringLength];
sprintf(a[Index], "string #%d", Index);
}
//clean-up the memory
for(Index = 0; Index < NumOfStr; Index++)
{
delete [] a[Index];
}
delete [] a;
return 0;
}
|
|
|
|
|
Hello,
I have a class CStaticEx, which is derived from CStatic and the text is drawn in the OnPaint() of CStaticEx.
I use SetDialogBkColor(...) to change the background and text color of the dialogs in my program.
But the text drawn in OnPaint of CStaticEx is black.
Is there any function to get the dialog background and text colors?
Thanks in advance.
-- modified at 6:36 Friday 26th August, 2005
|
|
|
|
|
GetSysColor(COLOR_3DFACE) should give you the dialog color.
GetSysColor(COLOR_WINDOWTEXT) should give you the right text color.
He is smart. He will make our Windows go.
|
|
|
|
|
Hello.,
I used CMonthCalCtrl to getting Selected Date.
But Date field is getting error .
Plz suggest me.,
*****How to get User selected date using CMonthCalCtrl
Plz Give the complete code.
Praveen Chowdam Kumar
|
|
|
|
|
if m_Cal is your control
COleDateTime odt;
m_Cal.GetCurSel(odt);
~RaGE();
|
|
|
|
|
parims wrote:
But Date field is getting error .
And what would that error be?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
can anybody help me out for it???
thanks n regards
Supriya Tonape.
|
|
|
|
|
NetGroupGetUsers or use ActiveDirectory more directly if you have it.
Hint: MSDN search 'group users members enumerat*'
Steve S
Developer for hire!
|
|
|
|
|
thank u David It did help.bye.
Supriya Tonape
|
|
|
|
|
|
If Administrators is a local group, use NetLocalGroupGetMembers() . Otherwise if it is a global group, use NetGroupGetUsers() .
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I'm using CTabCtrl in my application.
It works fine except when I apply TCS_BOTTOM style.
In this case, tabs get align properly at bottom but no controls on tab pages are visible.
Can anybody help, it's very urgent.
Thanks in advance.
|
|
|
|
|
I read a raw(without file info head)file from the hard driver. raw file is a 1024x1024 8bit graylevel data. I put the data into a memory and draw it on a memDC and add some text on the memDC,then I want to use GetDlBits to get the raw data from memDC, but the data I get is always wrong with some bytes. So the raw image can not display correctly. But if I use memDC.GetPixel then the result is right.I can not find any problem, who can help me!!!
CBitmap memBitmap
CBitmap* pOldBmp=NULL ;
CDC memDC;
OldPal=NULL;
HDC hDC=pDC->GetSafeHdc();
CDIBDoc* pDoc=GetDocument();
BOOL bSuccess=FALSE;
if(pDoc->hDIB ==NULL)
{
AfxMessageBox("wrong");
return;
}
LPBYTE m_lpImage=(LPBYTE)GlobalLock(pDoc->hDIB);
if(pDoc->hDIB)
{
OldPal=pDC->SelectPalette(&m_Palette,FALSE);
if(OldPal==NULL)
{
AfxMessageBox("palette choose error");
}
if(pDC->RealizePalette()==GDI_ERROR)
{
AfxMessageBox("palette realize error");
}
}
else
{
AfxMessageBox("image datum are empty");
return ;
}
SetStretchBltMode(hDC,COLORONCOLOR);
memDC.CreateCompatibleDC(pDC);
memBitmap.CreateCompatibleBitmap(pDC,1024,1024);
pOldBmp = memDC.SelectObject(&memBitmap);
bSuccess=::StretchDIBits(memDC,0,0,1024,1024,
0, 0,1024, 1024,
m_lpImage,(LPBITMAPINFO)bmhdr,
DIB_RGB_COLORS,
SRCCOPY);
::SetBkMode(memDC,TRANSPARENT);
::SetTextColor(memDC,RGB(220, 220, 220));
CString str="DOG ";
CRect rect(20,20,70,50);
::DrawText(memDC,str,sizeof(str),rect,DT_LEFT|DT_WORDBREAK);
if(bSuccess==GDI_ERROR)
{
AfxMessageBox("error");
}
pDC->BitBlt(0,0,1024,1024,&memDC,0,0,SRCCOPY);
ZeroMemory(pDoc->pTemp, pDoc->dwBitsSize);
/*******************************wrong*************************/
int nCount = GetDIBits(memDC.GetSafeHdc(), (HBITMAP)memBitmap.m_hObject, 0, 1024,
pDoc->pTemp, (BITMAPINFO*)bmhdr, DIB_RGB_COLORS);
/*******************************test*************************/
if don't use GetDIBits but use these then right:
int nCount = memBitmap.GetBitmapBits(1024*1024,(LPVOID)pDoc->pTemp);
int i,j;
for (i=0;i<1024;i++)
{
for (j=0;j<1024;j++)
{
*(pDoc->pTemp+j*1024+i) = (BYTE)memDC.GetPixel(i,j);
}
}
|
|
|
|
|
why no one answer my question?
|
|
|
|
|
My be this is your problem:
Try CDibData[^] the notes I wrote in the source file covers every thing I know about its usage.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|