|
Got it to work with SetIcon! Thanks so much!
|
|
|
|
|
I'm generating a popup menu and dynamically attaching it on the fly: (The STL part is incidental)
void CSTrainDoc::GenerateSearchCriteriaMenu()
{
CMenu* mmenu = ((CMainFrame*)AfxGetMainWnd())->GetMenu();
int pos = ((CMainFrame*)AfxGetMainWnd())->FindMenuItem(mmenu, "Current Search");
if (pos == -1)
return;
CMenu* submenu = mmenu->GetSubMenu(pos);
for (int i = 0; i < mmenu->GetMenuItemCount(); i++)
submenu->DeleteMenu(0, MF_BYPOSITION);
int size = m_menuKeyOptMap.size();
if(size == 0)submenu->AppendMenu(MF_STRING, NULL, "All selected");
MenuKeyOptMap::iterator itDyn = m_menuKeyOptMap.begin();
CMenu* pFlyOutMenu = new CMenu[size];
for (i = 0; itDyn != m_menuKeyOptMap.end(); itDyn++, i++)
{
char * tempDyn;
CString tempCDyn = (*itDyn).first;
tempDyn = new char [tempCDyn.GetLength() + 1];
strcpy(tempDyn, tempCDyn);
MenuOptSet& subMenuSet = m_menuKeyOptMap[tempCDyn];
pFlyOutMenu[i].CreatePopupMenu();
MenuOptSet::iterator itSub = subMenuSet.begin();
for (; itSub != subMenuSet.end(); itSub++)
{
char * tempSub;
CString tempCSub = *itSub;
tempSub = new char [tempCSub.GetLength() + 1];
strcpy(tempSub, tempCSub);
pFlyOutMenu[i].AppendMenu(MF_STRING, 0, tempSub);
delete tempSub;
}
submenu->AppendMenu(MF_POPUP,(int)(pFlyOutMenu[i].m_hMenu),tempDyn);
}
}
I call this function in my OnItemchangedList1(). If I include the delete[] above, it freezes. WIthout the delete, the first time I click my list 1, the menu comes up fine. Then if click on the listbox again, the menu now has a cyclic repeat.. (the item stored in tempdyn ). Theres no pattern. Each time I click on list1, depending on which item I clicked, another bunch of tempdyns gets added to the menu...it keeps growing and growing . Its not purely cyclic because its not A-Z-A-Z...its like H-Z-A-Z..........
Why does the app freeze if I delete[]? I stepped into it and the code assures mne that its only appending the correct tempdyns as I step along, yet when the UI comes up its got a ton of repeats. They dont start at the top and repeat ,,,.but strat repeating somewhere midway down the list, changing where the repeat starts when a different item is clicked .......
Appreciate your help,
ns
|
|
|
|
|
WHta I do when I click on the item is change the stuff in submenuset, but not the number of flyout items (which are the tempdyns...). But instead of theoriginal 31, I get 54 on the second click at some item etc...
Appreciate your help,
ns
|
|
|
|
|
GetMenuITemCount assures me I only have 31 items....every time I step through.......but ui shows many more....adding each time I click...
Appreciate your help,
ns
|
|
|
|
|
this may not be 100% correct.
You need to call Detach() of pFLyOutMenu before the delete call as when you call append the HMENU handle is then owned by the other menu. The destructor of CMenu calls DestroyMenu() on the HMENU thus you end up with a CMenu which has partially invalid data in it.
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
msdn:<br />
<pre>CMenu mnu;
HMENU hmnu = AfxGetMainWnd()->GetMenu()->GetSafeHmenu();
mnu.Attach( hmnu );
hmnu = mnu.Detach();
</pre><br />
<br />
I have:<br />
<br />
<pre> CMenu* mmenu = ((CMainFrame*)AfxGetMainWnd())->GetMenu();
</pre><br />
<br />
no hmenu...<br />
<br />
Also:<br />
<br />
<pre>
CMenu* pFlyOutMenu = new CMenu[size];
</pre><br />
<br />
which one needs detached? <br />
I did:<br />
<br />
<pre>
pFlyOutMenu->Detach();
delete[] pFlyOutMenu;</pre><br />
<br />
and its not freezing now, but still the same problem.... <br />
<br />
Appreciate your help,<br />
ns
|
|
|
|
|
I want to change the button state of the tool bar window when i will click inside a dialog box(or CFormView).
how can i ?
manoj Kumar Dalei,
IIT Delhi
|
|
|
|
|
You can map the UPDATE_COMMAND_UI handler for the toolbar buttons in your CFormView class. In that function you would call:
pCmdUI->SetCheck(TRUE/FALSE);
See the MSDN help for CCmdUI class
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
Another bit of code ripped from my software:
ON_UPDATE_COMMAND_UI_RANGE(IDM_TOOLS_MB_FLAT_FIRST, IDM_TOOLS_MB_FLAT_LAST, OnUpdateTools)
void CMidasViewFlat::OnUpdateTools(CCmdUI* pCmdUI)
{
if (m_CommentDrag.bOn)
pCmdUI->Enable ((pCmdUI->m_nID == m_nMouseMode) ? TRUE : FALSE);
else
pCmdUI->Enable (TRUE);
pCmdUI->SetCheck ((pCmdUI->m_nID == m_nMouseMode) ? 1 : 0);
}
I must be in a good mode. I mean, what sort of idiot just gives away code!
Iain.
|
|
|
|
|
But I beat you for both replies!
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
No fair!
But does quality beat speed?
Iain.
|
|
|
|
|
Iain Clarke wrote:
But does quality beat speed?
In that case, I beat you with both....
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
I want to change the cursor of the view window when i will click on different buttons of the main tool bar. When i will click on a particular button a particular cursor should be loaded.
how can i ?
manoj Kumar Dalei,
IIT Delhi
|
|
|
|
|
You need to map the WM_SETCURSOR message for your view. In that function you will need to call ::SetCursor(HCURSOR) to set the cursor you want to display. THis will be based on the flags set in your mainframe. To keep it efficeint, you should load all your cursor resources just once at the start of your program and reference those from your view.
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
You need to handle the WM_SETCURSOR message. Here is some code lifted
straight from application of mine. (OK, I cut some long winded bits)
BOOL CMidasViewFlat::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (nHitTest != HTCLIENT)
return CMidasView::OnSetCursor(pWnd, nHitTest, message);
...Obscure case removed here...
::SetCursor (m_hModeCursor [m_nMouseMode - IDM_TOOLS_MB_FLAT_FIRST]);
return TRUE;
}
Of course, this won't work if you haven't got any cursors...
CMidasViewFlat::CMidasViewFlat ()
{
for (int n = IDM_TOOLS_MB_FLAT_FIRST; n <= IDM_TOOLS_MB_FLAT_LAST; n++)
m_hModeCursor [n - IDM_TOOLS_MB_FLAT_FIRST] = ::LoadCursor (ghInstance, MAKEINTRESOURCE (n));
...Snipped...
}
You will also need to change the "mouse mode" depending on the tool button you
just pressed:
ON_COMMAND_RANGE(IDM_TOOLS_MB_FLAT_FIRST, IDM_TOOLS_MB_FLAT_LAST, OnToolMode)
void CMidasViewFlat::OnToolMode (UINT nToolMode)
{
m_nMouseMode = nToolMode;
::SetCursor (m_hModeCursor [m_nMouseMode - IDM_TOOLS_MB_FLAT_FIRST]);
}
I hope that helped...
Iain.
|
|
|
|
|
Hi,
I am using the WNetAddConnection2 function to create a user connection on a Windows2000 server. The connection is not persistent but I need it to remain active for the lifetime of a component on the client PC.
What is currently happening is that after 15 minutes idle time the server is deleting the clients connection.
I could run a timer, which calls the WNetAddConnection2 again.
However, apart from needlessly running a Windows timer, this only has an effect if the connection has already been deleted. So as we don't know the exact period between creation and idle time deletion there maybe a period before the timer tick where the client is disconnected.
Does anyone have any ideas on how this connection can be kept active until the component that created the connection wants to terminate it ?
Thanks in advance.
Nic
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nic.oughton@trikon.com
|
|
|
|
|
What is about just "using" the connection every, lets say, 10 minutes. (List the directory, access some file or, if it is not a connection to an UNC share, call an API that routes over IPC$ like remote registry access or the SCM API.)
Then the system should not detect it as beeing idle
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
Never done any printing before from MFC. Trying for the first time, but i've fallen at the first hurdle.
The "print" menu item is disabled. Is there a "proper" way to tell the framework to enable it??
Thanks
Jon
#include <beer.h>
|
|
|
|
|
If its an MFC Doc/View app, you need to have these entries in your MESSAGE_MAP to get the base print functions working
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
The above assumes your view is from CFormView . If not, change to the correct base class.
You may/will need to implement the following virtual function to get your output
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo);
The most important being OnPrint() where you generate the actual output of the given page (pInfo->m_nCurPage) and OnPreparePrinting() where you can specify the actual number of pages to print.
Also, take a look at the printing articles here at CP. Any big problems, you can mail me direct as I am usually able to answer printing questions.
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
My App is MFC Doc/View, SDI, with Splitter windows. One view in one splitter pane is called CGraphView, it's : public CView, and it's the view i used when creating the document template.
I've added those entries to the messagemap for CGraphView; I have (empty) implementations of all of those virtual functions, but i *still* have greyed out print/print preview menu items.
any ideas?
Jon
#include <beer.h>
|
|
|
|
|
I have made a modeless dialog.Then i put one edit control. At the run time when i click for a particular position the edit box moves there. Now i want that it should receive particular values(Numeric,floating,string) for particular click positions in the dialog box.
how can i do that ?
manoj Kumar Dalei,
IIT Delhi
|
|
|
|
|
In your WM_LBUTTONDOWN handler, can't you just call CWnd::SetWindowText for your Edit control or just use UpdateData(FALSE) depending on the CPoint value passed by the handler function? or am i missing something more subtle??
Hope this helps,
Adam.
www.beachwizard.com/travelogue[^]
"I spent a lot of my money on booze, birds and fast cars. The rest I just squandered"
George Best.
|
|
|
|
|
|
One solution is to override OnSize() in child window and update the parent window accordingly via MoveWindow() and SetWindowPos().
Kuphryn
|
|
|
|
|
I would like to make some sort of copy protection that only allows the software to run on one computer with the given registration key. First i thought that the user should send me the serial number of the c: drive, a number that my program would show and ask the user to send it to me and get a key in return, based on the serial number.
But the serial number can be changed by the user, or when formatting the drive.
Is there any other kind of serialnumber that i can find on every computer that can be the base for a registration key?
|
|
|
|