|
This is maybe a silly question. I thought it would as easy as adding an IDR_MAINFRAME menu to my dialog resource, but the miracle didn't occur
Should I create a CMenu and associate it to my dialog or is there a clever MFC mean ?
Thanks
Yarp
|
|
|
|
|
right click on the dialog and open properties. look there, u will find a combo box for choosing the menu
|
|
|
|
|
Hi Ganesh, this was obviously a silly question. I feel stupid but it doesn't matter I got it now. I spent 2 hours this morning trying to append my menu to the dialog. I thought many things but I could never figure it would be as simple.
Thanks a lot.
Yarp
|
|
|
|
|
Yarp
I have sent you a direct email with a sample project containing a dialog with a menu. Haven't looked at it in a while so won't make any comments here on how to do from my feeble memory.
Michael Martin
Australia
mjm68@tpg.com.au
"He orginally got the Tweezers of Destruction through the scanners but then popped back outside for a smoke."
- Chris Maunder 26/03/2002
|
|
|
|
|
Hi Michael, another way to create a menu. The way I was looking for and as there's also a status bar this is twice interesting for me. I compiled the project with VC6, it is still workable.
I'm doing an MFC dialog embedded in a dll with no MFC in the root program, so I emulate a CView behaving dialog from a CDialog class.
Thank a lot for the .zip file, CodeProject is really a cool C++ forum.
Yarp
|
|
|
|
|
Hi,
Can i pass a string in PostMessage parameters..
WPARAM or LPARAM..
Sameer
|
|
|
|
|
Sameer Maggon wrote:
Can i pass a string in PostMessage parameters..
WPARAM or LPARAM..
Yes you can, but remember, PostMessage just places the message in the message queue of the window in question, so you have to make sure that the string does not go out of scope or get deleted before the message is handled.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
If a man is standing in the middle of the forest speaking and there is no woman around to hear him...is he still wrong?
|
|
|
|
|
Have you tried (WPARAM)szString?
I think you should try it only for windows from the same process.
rechi
|
|
|
|
|
Yes. Not a CString or std::string though. LPTSTR are fine as long as you guarantee that it remains allocated until the message has been processed.
|
|
|
|
|
Niklas Lindquist wrote:
Yes. Not a CString or std::string though. LPTSTR are fine as long as you guarantee that it remains allocated until the message has been processed.
One of many ideas is to use a ptr on a static buffer - or using PostMessage() (so the data can get evaluated before returning and releasing a dynamic memory).
|
|
|
|
|
Yes, I do this in a lot of my applications. Especially in multi-threaded apps where you should only post messages between threads. Here is an example posting a CString.
Note you should allocate whatever you wish to post. It can be any kind of object.
...
CString *pStr = new CString();
*pStr = "Set String Here!";
pMyView->PostMessage(WM_MY_MSG, 0, (LPARAM)pStr);
... Note that the receiver of this message MUST free the allocated memory.
LRESULT CMyView::OnHandleMyMsg(WPARAM wParam, LPARAM lParam)
{
CString *pStr = (CString *)lParam;
if(pStr)
{
delete pStr;
}
return 0;
} This last step is important. Before the window is destroyed, check for any unhandled messages and delete their memory.
void CMyView::OnDestroy()
{
MSG msg;
while(::PeekMessage(&msg, (HWND)NULL, WM_MY_MSG, WM_MY_MSG, PM_REMOVE))
{
CString *pStr = (CString *)msg.lParam;
if(pStr)
delete pStr;
}
CView::OnDestroy();
} Hope this helps.
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
Hi,
what is a good way to combine a listbox with an edit control?
I run a small chat application (heavy alpha yet). I have the problem that the interface is not very user friendly yet. For example, when setting focus on listbox the keyboard input is not shown in edit control - or - when being in edit control the mouse wheel is not routed to the listbox. Both controls should be merged more together.
Thx for some design guide lines or pointing me into the right direction!
Thx, Moak
|
|
|
|
|
ComboBox?
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
If a man is standing in the middle of the forest speaking and there is no woman around to hear him...is he still wrong?
|
|
|
|
|
Redirect keystrokes from your list to your dialog. Mouswheel events from your edit to your dialog. Keystrokes from your dialog to your edit. Mousewheel events from your dialog to your list.
|
|
|
|
|
Niklas Lindquist wrote:
Redirect keystrokes from your list to your dialog. Mouswheel events from your edit to your dialog. Keystrokes from your dialog to your edit. Mousewheel events from your dialog to your list.
thx, will try that!
I know the window handle of each other. Which is the MFC place to scan the correspoding messages, is it PreTranslateMessage() handler from CListBox/CEdit?
|
|
|
|
|
That is probably the easiest place.
|
|
|
|
|
okie... will hook me up there.
If there are any alternatives, let me know.
But I wont add a unique handler for every message type, hmm maybe a combined handler for 'relaying'.... hmmm.
|
|
|
|
|
Does map reserve memory space like vector does? To check
the cost of having a map inside my class, I make a test
class like this:
struct object {
map<int, int=""> data;
};
the class size itself is 16 byte, obviously. But when I
make instances of that class, such as
int main() {
for(int i=0;i<10000;++i) object* ob = new object();
}
from the task manager I see that my process takes up about
1 MB for each additional 10000 objects, which means one
object cost about 100 bytes. Where did the extra 100-16 =
84 bytes come from? I haven't even added any entry to the maps. What can I do to reduce memory usage per object?
Thanks in advance,
Danny
.
|
|
|
|
|
The map manages its memory through the allocator that is specified for the map. So it is up to the allocator that is chosen to decide how memory is allocated. I suspect that the default allocator does cache a few map entry nodes to speed up the use of the map.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Probably in release mode the memory used is much less (give it a try). Also, my STL block allocator could help gain a little space (though it was not designed for that purpose.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I did use the release version. I even run the release exe directly from windows instead of the debugger (there was a slight difference). I'll experiment with your block allocator, thank you.
Danny
|
|
|
|
|
Is there any function to add time delay to a process;( like delay() function in c,c++)
thanking u
|
|
|
|
|
Maybe you are looking for _sleep or Sleep .
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Thanx
for reply ; can u please tell the syntax of sleep .
|
|
|
|
|
VOID Sleep(
DWORD dwMilliseconds
);
Parameters
dwMilliseconds
[in] Specifies the time, in milliseconds, for which to suspend execution. A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution. A value of INFINITE causes an infinite delay.
Return Values
This function does not return a value.
|
|
|
|