|
When using PostMessage with non-primitive data types, alwaysuse a deep copy of the object - passing a reference to an object that might cease to exist before the message is handled is just asking for trouble:
CString * lp = new CString(m_strDns);
if (!PostMessage(...,...,..., (LPARAM) lp))
delete lp;
the error handler avoids a memory leak (although you might be tempted to retry posting the message if your handling would break down otherwise)
the message handler needs to delete the object again:
CString* name = (CString*)lParam;
_ASSERTE(name!=NULL)
CString strName = *name;
delete name;
This solution is IMO easier than the one suggested in the post above..
*) reason:
skulls don't kiss for an explanation - wait for the vacation photos! [sighist]
|
|
|
|
|
Thanks to both of you for your posts.. I had a feeling that the thread was exiting before the string could be accessed by my main app.. I went with the easier solution posted below..
Thanks again,
Rob
|
|
|
|
|
You're welcome. Just make sure that you don't post the message to multiple windows, or else the object will be deleted before the second window processes the message
swine
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.
|
|
|
|
|
I have a simple SDI MFC application.
When I click on the view I show popup menu.
In the OnDraw function of my view I draw some things and I want to know,
if the popup menu is shown, because I want to mark the point where I clicked with
the mouse to open the popup menu!
I want to do like something:
...
if (???->???())
{
... draw a point ...
}
So, how can I check if the popup menu is shown????
Here the code I use to show the popup menu:
CMenu menu;
menu.LoadMenu(IDR_POPUPS);
menu.GetSubMenu(1)->TrackPopupMenu(TPM_LEFTALIGN | TPM_VERTICAL | TPM_NONOTIFY,
pInfo->ptAction.x, pInfo->ptAction.y, this);
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
I think the problem is to know when menu is closed (you know exaclly when it is opened). It is not problem also to detect when user closes context menu selecting it's item. The last thing you need is to know when user closes menu without selecting item.
Playing with Notepad and Spy++ I found that when I close context menu pressing Esc Spy++ prints the line:
S WM_MENUSELECT uItem: 0 fuFlags:FFFF(menu was closed) hMenu:00000000
Try to investigate this.
|
|
|
|
|
Say I have two views in my application v1 and v2 that belong to class v1 and class v2 ;
Both these views have the same parent frame type i.e same Parent Frame class F
In F's ActivateFrame Method i need to make a decision based on the view .As for eg I want to show v1 as Maximized , but v2 as minimized . How can I get run time class information from the View ??????
All i can do i ActivateFrame() is
this->GetActiveView() and check the class information and make a decision !
|
|
|
|
|
You can use the RTTI mechanism provided by MFC to determine what type you have as follows:
CView* pView = GetActiveView();
if ( pView != NULL )
{
if ( pView->IsKindOf( RUNTIME_CLASS(CMyView1) ) )
{
// Do something
}
else if ( pView->IsKindOf( RUNTIME_CLASS(CMyView2) ) )
{
// Do something different
}
}
Dave
|
|
|
|
|
What I want to Happen: If function is called, open another webbrowser if one is open already.
Problem: Function uses same instance of default webbrowser when called
Sample Code:
ShellExecute(m_hWnd, "open", str_Homepage, NULL, NULL, SW_SHOWDEFAULT);
I tried researching this one, can not jump the hurdle.
Thanks
Joe
"You can't throw yourself a parade every time you win, and you can't bury yourselves when you lose."-Levon Kirkland Philadelphia Eagles
|
|
|
|
|
<br />
ShellExecute( m_hWnd, _T("open"), _T("iexplore.exe"), str_Homepage, NULL, SW_SHOWDEFAULT );<br />
should do the trick. This will of course always open Internet Explorer however.
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Perfect thanks!
"You can't throw yourself a parade every time you win, and you can't bury yourselves when you lose."-Levon Kirkland Philadelphia Eagles
|
|
|
|
|
If you don't want to read this lengthy explanation here is the question first.
Does anyone have any "gotcha" type of information on MSMQ or any type of message queue architecture or suggestions as to whether this is a viable solution? Or, of any other alternative solutions, I should consider?
Problem(s):
Multiple applications written by different developers (from different groups/orgs) without a standard library or core set of functions. This causes alot of redundant coding and a lack of standardization. i.e. file I/O routines are duplicated/redundant, the format of the data is basically the same but are sometimes treated differently by different software authors. Most applications are either analysis (algorithmic) or empirical representations of the data. No standards exist for the algorithms, and so many programs exist some of which perform analysis better than others.
Additionally, the developers use either C, C++ (Microsoft, Borland, MFC, OWL) or VB. Some of the apps are realtime but most do post analysis of the data. I must also state that there is no central organization in a position of authority to fully mandate standards or even require what applications be developed and their priorities.
Sounds silly? Yeah, welcome to the US govt agency I work for. I have been trying to coordinate a cooperative agreement on some development standards but am finding this very difficult. We have pockets of one or two developers spread throughout the country, developing in their language/development suite of their choice. The biggest problem, of course, is a lack of funding (resources) and one organization to implement a central plan not to mention defensive territorialism by managers who control these developers. On the positive side, at least we are all developing in Windows since DOS is so outdated but there was a time when very few of us developed for Windows.
Thus, for the past year or so I have been trying to come up with a plan that may not address all issues but at least make us more efficient. Initially, I looked at COM but then realized that our agency does not have enough qualified personnel to develop for COM.
Possible Solution:
My next approach that I am considering is a compromise. My group (presently 2 people) has developed a standard core library we would like to implement in some form but the language compatability problems arise. Thus, I am thinking to ignore/dump support for VB or Delphi but instead support C or C++ for Microsoft only. I have converted our core library from Borland C++ to VC++ and it currently has no GUI built for it.
If I provide this core library in VC/C++ or MFC, then previously developed apps should be able to use it without too much modifications as long as they also were written in VC/C++ or MFC. I am thinking that if we used some form of queing architecture such as MSMQ (or whatever its called now), then my group can maintain the core, and we can deliver a standard core library or interface. I'm figuring that previously developed applications could modify their file I/O routines to connect to the queue architecture and receive data messages from that instead. Another side benefit, is that a good queue architecture can encapsulate networking code for us, so that not all developers would need to learn that, and we could have some true client/server based applications.
This resolves standardization issues regarding data, File I/O, and realtime data handling routines, but still does not address standards regarding algorithms, programming languages, or develoment environments. Thus, the compromise. Additionally, the message queue architecture may even allow us to use different languages and support other platforms (I don't know if MSMQ will do this) if we make interfacing to the core library, totally message based. I should say that a standard programming language or platform is not mandatory, and in the best case scenario we would like to support multi-platforms and languages, if such a message queue architecture or other exists.
Does anyone have any "gotcha" type of information on MSMQ or any type of queue architecture or suggestions as to whether this is a viable solution? Or, of any other alternative solutions, I should consider?
Sorry, so long. Thanks in advance for any info.
|
|
|
|
|
I am using CreateFont to create the appropriate font to use in the print preview of my application. For example ->
m_PrintFont.CreateFont(80,34,0,0,0,0,0,0,0,0,0,0,FIXED_PITCH,"");
I understand that CreateFont uses the font that most closely matches what you ask for. The problem is that this works on my machine, but other machines do not output the same font. I'm assuming if I can figure out which font is being chosen on my machine, I can copy it to other machines and it will choose the same one. So how do I know exactly which font it is actually using on my machine?
Ed
|
|
|
|
|
You can use GetTextFace() to retrieve the typeface name of the font that is selected into the specified device context.
For example:
CClientDC dc( this );
dc.SelectObject( &myFont );
CString strFont;
dc.GetTextFace( strFont );
Dave
|
|
|
|
|
After looking at Jörgen Sigvardsson's implementation of the Observer pattern, I have a couple of questions about a few STL thingy that he uses :
struct IObserver {
virtual void OnNotify(class Observable* pObservable) = 0;
};
...
void Notify()
{
std::for_each( setObservers.begin(),
setObservers.end(),
std::bind2nd(std::mem_fun1(&IObserver::OnNotify), this));
}
...
which goes like this ( since it's working! ):
Call the OnNotify method on each iterator of the set setObserver with the this parameter, where it can be of the class IObserver or be inherited from it.
and will translate to something like <pseudo code="">:
for ( it = begin; it < end ++it )
{
it->OnNotify( this );
}
now, to the specific ( and from what I understand ( or not ) from STL's documentation )
std::mem_fun1 : this creates (adapt) a simple function call from the argument ( even if it's not a static function), mem_fun1 will generate a function without a parameter ( in that case ).
std::bind2nd : this will "add" a parameter to the mem_fun1 generated function ?! this is where I got lost ... at least more lost than before ....
I don't quite understand the definition given on SGI's STL pages :
"Binder2nd is a function object adaptor: it is used to transform an adaptable binary function into an adaptable unary function."
Why would I adapt a function from having 2 parameters ( binary ) to 1 parameter ( unary ) ? Or Am I reading this the other way around ? and the bind2nd will add the iterator to be passed to the for_each ?
Why use the binder and mem_fun functions while it can be done with a simple for loop
Max.
|
|
|
|
|
Maximilien wrote:
Why use the binder and mem_fun functions while it can be done with a simple for loop
Pure STL masturbation
lazy isn't my middle name.. its my first.. people just keep calling me Mel cause that's what they put on my drivers license. - Mel Feik
|
|
|
|
|
Daniel Turini wrote:
Pure STL masturbation
That must be the fun in mem_fun !!!
Max.
|
|
|
|
|
As far as I understand it:
bind2nd: can turn an fun(x,y) function call into an g(x):=f(x,y) with constant y
mem_fun1: can turn an one-param object member function into an two-param global function, e.g. y->member(x) ==> non_member(x,y)
i.e. to call a one-arg member function, you first turn it into a two-arg global function, than reduce it to a one-arg global function (making the second param constant)
I may be far wrong here, though.
Maximilien wrote:
Why use the binder and mem_fun functions while it can be done with a simple for loop
because STL is better? I really don't know...
skulls don't kiss for an explanation - wait for the vacation photos! [sighist]
|
|
|
|
|
Nope. STL for loops tend to be much slower in RL. In my testing, it has run 4-5 to 1 in favor of handwritten loops as far as performance.
Now, as far as program correctness, it is the job of the STL people to PROVE that the STL method generates less bugs. They have failed to do this. This means that the claim has no more merit than me saying I can read the minds of dead people.
This example is pure STL masterbation that tends to confuse people more than it helps them to maintain the code. IMHO, it makes it a "BAD THING". And I don't really give a sh*t what Herb and Steve say. Until they can come up with proof (which is something Herb tends to do more of), their claims hold no weight.
EDIT: I don't mean to talk negatively about Jörgen Sigvardsson here. We just disagree on this point.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
my last line obviously missed an <sarcasm>> emoticon
I think if you use the more complex STL stuff daily, the thing Jörgen does seems just more "natural" than a for loop.
However, in real life I'd always opt for the easier-to-understand method.
skulls don't kiss for an explanation - wait for the vacation photos! [sighist]
|
|
|
|
|
Hi all, may I know how to change my own menu bar.
I have created single document application and I don't want the menu bar that get created for you.
I have search for it but don't know where they attaching the menu bar that they created for me.
Thanks
|
|
|
|
|
|
no.. no.. you misunderstood me. I create a new menu bar using MFC. not my own drawing.. just regular menu bar.. I want to attachment it to my MainFrame but don't know how.
for example..
when you choose Single Document while you were creating application or building a new project, the menu bar get created too. The menu bar contains
File Edit View Help you can add more menu item to there.
I have created a new menu bar by Insert Menu then I type in only
File in side File only have New and Exit I don't want anything else like original menu bar File which consists, New, open, save,close,save as, exit...
I only want to know how to attach the menu bar to my application??
Thanks
|
|
|
|
|
In the .cpp of your application Class, add the following lines (in BOLD) for attaching an user defined menu...eg shows system menu getting replaced by IDR_MY_MENU1
(Like you I am also learning..hence if this fails please do not hold me responsible ). If there is any other better that you come across let me know
CSingleDocTemplate* pDocTemplate;<br />
pDocTemplate = new CSingleDocTemplate(<br />
IDR_MAINFRAME,<br />
RUNTIME_CLASS(CMyDoc),<br />
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CMyView));<br />
AddDocTemplate(pDocTemplate);<br />
CCommandLineInfo cmdInfo;<br />
ParseCommandLine(cmdInfo);<br />
if (!ProcessShellCommand(cmdInfo))<br />
return FALSE;<br />
<br />
CMenu* pMenu = m_pMainWnd->GetMenu();<br />
if (pMenu)<br />
pMenu->DestroyMenu();<br />
<br />
pMenu = new CMenu();<br />
pMenu->LoadMenu(IDR_MY_MENU1);<br />
m_pMainWnd->SetMenu(pMenu);<br />
((CMainFrame*)m_pMainWnd)->m_hMenuDefault = pMenu->GetSafeHmenu();<br />
m_pMainWnd->ShowWindow(SW_SHOW);<br />
m_pMainWnd->UpdateWindow();<br />
<br />
return TRUE;<br />
-Mahesh Shimpi
Ideas multiply by sharing!!
|
|
|
|
|
Thank you very much for your help... That's what I wanted..
Thank you.
|
|
|
|
|
Hey Everybody,
I am using CListCtrl in my application with check boxes.
By default windows provides various selection mechanism like
1. 'click' on an item, OR
2. multiple files by pressing 'ctrl' key and clicking on various items OR
3. using 'shift' and page down/up or end/home to select all item etc..
However mere selection does not check the checkboxes of the selected items. I want to implement functionality whereby as soon as a selection is made the check boxes gets checked.
1. What notification message should I trap?
2. Can somebody just give a pseudo code OR various steps in doing so?
Using "OnClick" I can trap a single item selection and I can set its check state. Problem is when I do a select using Shift + End/Home OR Shift + PageUp/Down. At this point I am not sure what message should be trapped to check the selection of the item and mark it checked.
I tried something to do like this with the notify mesg
BOOL CMyListView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
LPNMLVODSTATECHANGE pNMListView = (LPNMLVODSTATECHANGE) lParam;
NMHDR pNMHDR = (NMHDR)pNMListView->hdr;
if (pNMListView->uOldState == 0 && pNMListView->uNewState == 0)
{
*pResult = 0;
return FALSE; // Do nothing and return
}
//ELSE
//Here I think I should have got items with selected state set so
//that I can call SetCheck on the item and programmitically to
//check the checkbox for those items.
//Please advise..
}
Thanks in Advance
-Mahesh Shimpi
Ideas multiply by sharing!!
|
|
|
|
|