|
He has created list box, shown in above post.
|
|
|
|
|
Suresh H wrote: hwndListBox=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
Use CreateWindow instead of CreateWindowW . You are trying to use UNICODE version in Non -UNICODE application.
|
|
|
|
|
Hi prasad, again i am getting error..
HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST);<br />
hwndListBox=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);<br />
error :-
rror C2664: 'CreateWindowExA' : cannot convert parameter 11 from 'struct HWND__ *' to 'struct HINSTANCE__ *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
|
|
|
|
|
One question HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST);
what is it? before CreateWindow
|
|
|
|
|
WhiteSky I am creating a handle for the list box control {IDC_SLIST }
|
|
|
|
|
So do you have two listbox on your project?
|
|
|
|
|
Suresh H wrote: hwndListBox=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0);
Here, instead of handle you need to pass handle to instance. Pass instance that you will get through WinMain .
|
|
|
|
|
BOOL CALLBACK SDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
{
// HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST);
hwnd=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwnd,0);
again error :-
error C2664: 'CreateWindowExA' : cannot convert parameter 11 from 'struct HWND__ *' to 'struct HINSTANCE__ *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
|
|
|
|
|
You have two hwnds on CreateWindow? wheres HINSTANCE
|
|
|
|
|
Prasad what I am trying to do is
List box contains a list of file names , when we select any item in the list box that file contains should get added to rich edit box.
So is there any way I can do that ??? without double click trouble ???
|
|
|
|
|
Suresh H wrote: List box contains a list of file names , when we select any item in the list box that file contains should get added to rich edit box.
You can handle list box double click in following way,
case WM_COMMAND:
switch(LOWORD(wParam))
case IDC_LIST1:
if (HIWORD(wParam) == LBN_DBLCLK)
{
}
break;
|
|
|
|
|
Hi Prasad,
Thank you very much list box double click event is work.
|
|
|
|
|
Welcome !
|
|
|
|
|
Hi Prasad,
One more last problem. After the double click event
I am trying to read the file contents and display the file connects in rich edit box for that I am trying this code but I am not getting any out put can u please check what changes I have to make.
<br />
const N = 1000;<br />
char cont[N];<br />
<br />
ifstream fin;<br />
fin.open(FName);<br />
while(fin)<br />
{<br />
fin.getline(cont,1000);<br />
::SendMessage(hwndRichEdit,WM_SETTEXT, 0,(WPARAM)cont);<br />
}<br />
<br />
fin.close();<br />
i have tryed this code in mfc this is working properly but this code does not work in win 32 api,
<br />
CStdioFile file(str, CFile::modeRead);<br />
DWORD dwSize = file.GetLength();<br />
char *pBuffer = new char[dwSize + 1];<br />
UINT uRead = file.Read(pBuffer, dwSize);<br />
pBuffer[uRead] = '\0';<br />
file.Close();<br />
::SendMessage(hwndRichEdit,WM_SETTEXT, 0,(WPARAM)pBuffer);<br />
delete [] pBuffer;
|
|
|
|
|
Suresh H wrote: const N = 1000;
char cont[N];
ifstream fin;
fin.open(FName);
while(fin)
{
fin.getline(cont,1000);
::SendMessage(hwndRichEdit,WM_SETTEXT, 0,(WPARAM)cont);
}
fin.close();
Here, are you succesfully able to open the file ?
Initialize char array like this,
char cont[N] = { '\0'};
|
|
|
|
|
Hi Prasad,
I just did that changes but no output.
I traced the statements, it open the file and it reads till end of the file,
Since its in the loop the cont value keeps on changing ….and also nothing is added to the rich edit box.
Is there any way where I can open the file read the complete contents of the file and store it in one variable and pass that variable to get displayed in the rich edit ???
Files which I am trying to open are simple text files which contains lots of blank lines in the starting and end of the file .
|
|
|
|
|
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
|
|
|
|
|