|
I dont see any problem there, as long as array has some value.
|
|
|
|
|
Prasad I think since we are using WM_SETTEXT its replacing the rich edit contents ?? can we use some message where it adds to rich edit box with out replacing the old contents ??
|
|
|
|
|
There is message EM_SETTEXTEX .
But instead, read whole file content in to string, and use WM_SETTEXT .
|
|
|
|
|
Hi prasad,
How to read the whole file content in to string at a time ::???
|
|
|
|
|
Loop though for reading for a fixed length, as you are doing now, and keep appending that array in a std::string variable.
|
|
|
|
|
Suresh H wrote: case WM_COMMAND:
switch(LOWORD(wParam))
{
case LBN_DBLCLK:
{
HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST);
int iCurSel =::SendMessage(hwndListBox,LB_GETCURSEL,0,0);
TCHAR FName[25];
SendMessage(hwndListBox,LB_GETTEXT,(WPARAM)iCurSel,(LPARAM)FName);
This is Win32 code. Since you have an MFC application, based on the presence of CStdioFile , take advantage of it. Use ClassWizard to create a LBN_DBLCLK handler. In that handler, call the listbox's GetCurSel() method to get the index of the currently selected item. Then call the edit control's SetWindowText() method, or its StreamIn() method, to display the text (after opening the file and reading its contents, of course).
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hello,
I'm working with/on an application with a resource based menu. This application is more or less driven by the programming (script) language tcl and has a lot of APIs introducing C++ functionality to tcl.
Now I built an API to manage (popup) menus and their menu items, to create new items with tcl script callbacks, etc.
The main point in my "construct" is to use a template menu item from a template menu resource.
I created a menu in the resources as template containing a menu item as template.
Everything was fine until I realized, that I seemed to have no chance to differentiate between the new commands having all the same id, but different application defined data - changed via the MENUITEMINFO and the related functions Get/SetMenuItemInfo.
I changed the menus after their creation to send a WM_MENUCOMMAND message instead of a WM_COMMAND message by setting the dwStyle flag MNS_NOTIFYBYPOS inside the MENUINFO structure via a call to SetMenuInfo.
Now - finally to the problem and the question - why I never receive the WM_MENUCOMMAND message?
I patched CMainFrame::PreTranslateMessage method to catch the WM_MENUCOMMAND message, I tried with CMainFrame::WindowProc, and by registering a ON_MESSAGE handler inside the message map, but ... nothing worked!
Thanks for any reaction in advance!
Best regards,
Martin Lemburg
|
|
|
|
|
Can you provide code ? how you are creating menu, using SetMenuInfo etc. ?
|
|
|
|
|
Yes - here's some "reduced" code:
1. the creation of a popup menu:
DWORD style = 0;
CMenu *popup = (CMenu *) NULL;
MENUINFO menuInfo;
memset( &menuInfo, 0x0, sizeof( MENUINFO ) );
popup = new CMenu();
if ( ( popup != NULL ) && ( popup->CreatePopupMenu() == TRUE ) )
{
menuInfo.cbSize = sizeof( MENUINFO );
menuInfo.fMask = MIM_STYLE;
if ( popup->GetMenuInfo( &menuInfo ) == TRUE )
{
style = menuInfo.dwStyle;
memset( &menuInfo, 0x0, sizeof( MENUINFO ) );
menuInfo.cbSize = sizeof( MENUINFO );
menuInfo.fMask = MIM_APPLYTOSUBMENUS | MIM_STYLE;
menuInfo.dwStyle = style | MNS_NOTIFYBYPOS;
if ( popup->SetMenuInfo( &menuInfo ) == TRUE )
{
tcl_publishResult( ip, (char *) create_popup_token( popup ) );
return TCL_OK;
}
}
}
system_error_message( ip, "couldn't create popup menu" );
if ( popup != NULL )
{
delete popup;
}
return TCL_ERROR;
2. the insertion of a created popup menu:
int itemPosition = 0;
char *label = (char *) NULL;
CWnd *root = (CWnd *) NULL;
CMenu *menu = (CMenu *) NULL,
*popup = (CMenu *) NULL;
MENUITEMINFO menuInfo;
Menu_if_tcl_MenuItem_s_t *menuItem = (Menu_if_tcl_MenuItem_s_t *) NULL;
memset( &menuInfo, 0x0, sizeof( MENUITEMINFO ) );
menuInfo.cbSize = sizeof( MENUITEMINFO );
root = AfxGetApp()->m_pMainWnd;
menu = get_owning_menu( ip, root->GetMenu(), positionsList, itemPosition );
if ( ( menu != NULL ) &&
( itemPosition != -1 ) &&
( (UINT) itemPosition <= menu->GetMenuItemCount() ) )
{
if ( menu->InsertMenu( itemPosition, MF_BYPOSITION | MF_STRING | MF_POPUP, (UINT) popup->m_hMenu, label ) == TRUE )
{
menuItem = create_menu_item( PopupMenuItem, "" );
menuInfo.fMask = MIIM_DATA | MIIM_STATE;
menuInfo.fState = MFS_ENABLED;
menuInfo.dwItemData = (ULONG_PTR) menuItem;
if ( menu->SetMenuItemInfo( itemPosition, &menuInfo, TRUE ) == TRUE )
{
root->DrawMenuBar();
tcl_publishResult( ip, menuItem->token );
return TCL_OK;
}
}
}
system_error_message( ip, "couldn't insert popup menu" );
return TCL_ERROR;
After using the MNS_NOTIFYBYPOS flag and setting the MENUINFO of the created popup menu I expected to get WM_MENUCOMMAND messages, when selecting menu items, but I always get WM_COMMANDS.
Thanks for your reply!
Best Regards,
Martin Lemburg
|
|
|
|
|
The problem , I see in your code is, you have applied MENUINFO , before inserting menu and submenus.
I tried on simple SDI application, creating a pop - up menu in resource, and using SetMenuInfo . It work like charm.
|
|
|
|
|
Hello Prasad,
thanks for your engagement!
I changed my sources, so that ...
1. no MENUINFO action happens while creating the popup
2. the insertion is slightly changed:
2.1 menu->InsertMenu( itemPosition, ..., popup->m_hMenu, ... )
2.2 popup = menu->GetSubMenu( itemPosition )
2.3 requesting with popup->GetMenuInfo the MENUINFO to get the current dwStyle member => oldStyle
2.4 changing and setting with popup->SetMenuInfo the MENUINFO with dwStyle = oldStyle | MNS_NOTIFYBYPOS
I have introduced the ON_MESSAGE handler for WM_MENUCOMMAND, extended the CMainFrame::WindowProc and the CMainFrame::PreTranslateMessage, but none of them gets a WM_MENUCOMMAND message.
Even if a CMainFrame instance is the owner of the menu I insert my popups in, can I really be sure, that CMainFrame instance really receives the WM_MENUCOMMAND messages?
Thanks again and best regards,
Martin Lemburg
|
|
|
|
|
Hi Martin,
You must be using TrackPopupMenu for invoking pop up menu, isn't it ?
Now, I'll tell you ,steps I followed to got it working.
1. Create a menu in resource editor with pop-up style.
2. Use CMenu::LoadMenu to load that menu.
3. Use SetMenuInfo as described in your original post.
4. Use TrackPopupMenu , set its parent as main frame window.
5. Override DefWndProc of CMainFrame (or you can use PreTranslateMessage ).
6. I can see WM_MENUCOMMAND sent when clicked this menu.
May this give you some idea.
|
|
|
|
|
Ok - got it working - a bit different than you told me to, and with a lot of consequences.
The current state:
1. we have a MFC application
2. our MFC application has a resource based menu, with one ON_COMMAND handler per menu item
3. I wrote a tcl API to access the MFC application menu, which allows to create new sub menus and menu items.
4. before I insert a popup menu, I switch the MFC application menu MENUINFO to MNS_NOTIFYBYPOS , so that WM_MENUCOMMAND messages are used, instead of WM_COMMAND messages
5. after inserting a popup menu, I switch the new sub menu to use WM_MENUCOMMAND messages
6. I registered a ON_MESSAGE handler for WM_MENUCOMMAND messages
The consequences:
1. None of the resource based menu items, with ON_COMMAND handlers, will work anymore, because there are no WM_COMMAND messages anymore
2. every selected menu item causes the wanted WM_MENUCOMMAND message
3. every menu in the "path" of (sub)menus seem to have this MENUINFO style flag MNS_NOTIFYBYPOS , so that this model is really working.
If I don't switch all containing menus of a sub menus to send WM_MENUCOMMAND messages, than the whole model won't work.
The suggestion above to use TrackPopupMenu must work, if the popup menu is used all alone, but if it is used inside a "path" of cascaded menus, than this would be more problematic.
4. the whole menu system of ON_COMMAND handlers must be rewritten, or I must find a way to get rid of the dummy or template menu item and create resources on the fly, but ... I don't know how!
A change of question:
How do I create on-the-fly resources or menu items with new, non-existing IDs?
If I'd know, how to create on-the-fly resources, than I could stay with the normal WM_COMMAND system.
Thanks to you Prasad!
Best regards, and a happy weekend!
Martin Lemburg
|
|
|
|
|
Dear All
I have following problem:
In a multi threaded application I want to debug my program.
But when I set break point one one thread, I find that all the threads are suspended. (In visual C++ 6 environment)
Is there any way to block the thread that we want to see its bahavior , without blocking other threads.
Regards
Mahdi
|
|
|
|
|
I don't have an answer to your question but I really don't see why you want to do that ? Is there any particular reason to do that ?
|
|
|
|
|
One of my threads works with hardware, and an small time of disconnection will resutl in intefrace error with hardware.
Because of it.
|
|
|
|
|
|
Hi all,
I have the following problem. I using a while loop, and if the user hits any key I prompt the user whether he/she wants to exit (Thats working ... awaiting previous thread). The problem comes in when the users selects No, when every loop cycle it asks the same question over and over again. How can I clear the buffer of the key board hit funtion ??
while(1)
{
if(kbhit())
{
UINT msg_rc;
msg_rc = MessageBox(NULL,"Are you sure you want to close the TCP/IP Server","Confirmation",MB_YESNOCANCEL);
if (msg_rc == IDYES)
{
exit(1);
break;
}
}
....
Many thanx
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
else
{
printf( "\nKey struck was '%c'\n", _getch() );
}
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
I overlooked , that you got answer, reading printf statement in this post. And posted my reply.
Any way, use _getch() , at the start in if statement instead of else . So that it will be executed irrespective of condition.
|
|
|
|
|
Use _getch .
while(1)
{
if(kbhit())
{
_getch();
UINT msg_rc;
msg_rc = MessageBox(NULL,"Are you sure you want to close the TCP/IP Server","Confirmation",MB_YESNOCANCEL);
if (msg_rc == IDYES)
{
exit(1);
break;
}
}
-- modified at 4:18 Friday 16th February, 2007
Didn't noticed that you already got your answer, I ignore your second post, seeing its printf statement.
|
|
|
|
|
Just out of curiosity, why are you using kbhit() and getch() with a GUI application? Those functions had their place with console applications, but with Windows, much more elegant solutions exist.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi all,
I have the following piece of code that displays a messagebox, it's working and everything, but how can I display an icon in the message box. I am well aware of the MB_ICONEXCLAMATION, MB_ICONWARNING ... ext, but I want to use a yes - no button with a question mark icon:
msg_rc = MessageBox(NULL,"Are you sure you want to close the TCP/IP Server","Confirmation",MB_YESNOCANCEL);
Many thanx
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
msg_rc = MessageBox(NULL,
"Are you sure you want to close the TCP/IP Server",
"Confirmation",
MB_YESNOCANCEL <code>| MB_ICONQUESTION</code>);
|
|
|
|
|
Thank you very much toxcct ...
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|