// JP opened flex table

Click to See Complete Forum and Search --> : List Box DBLCLK event & reading file contents


Suresh.hc
February 16th, 2007, 05:50 AM
Hello all,

I have List Box and rich edit box in my Dialog IDC_SLIST & IDC_FILECONT

List Box contains the text file names , When the user double click on the list box that file content should be displayed in the rich edit box.

Can u please tell me what all the changes I have to make and how to do the double click event in win 32 Api application ??


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[30];
SendMessage(hwndListBox,LB_GETTEXT,(WPARAM)iCurSel,(LPARAM)FName);


CStdioFile file(FName, CFile::modeRead);
DWORD dwSize = file.GetLength();
char *pBuffer = new char[dwSize + 1];
UINT uRead = file.Read(pBuffer, dwSize);
pBuffer[uRead] = '\0';
file.Close();


HWND hwndRichEdit = GetDlgItem(hwnd, IDC_FILECONT);
::SendMessage(hwndRichEdit,WM_SETTEXT, 0,(WPARAM)pBuffer);
delete [] pBuffer;
}

-----------
this code works in MFC but its not working in win 32 api, i am not able to use CFile what has to be done ??

CStdioFile file(FName, CFile::modeRead);
DWORD dwSize = file.GetLength();
char *pBuffer = new char[dwSize + 1];
UINT uRead = file.Read(pBuffer, dwSize);
pBuffer[uRead] = '\0';
file.Close();

Thanking you,
Suresh HC

humptydumpty
February 16th, 2007, 06:32 AM
did u include file #include <afxdlgs.h> to your project
Thanx

Suresh.hc
February 16th, 2007, 06:39 AM
hi Humpty,

I included that header file.

now i am getting new error

c:\program files\microsoft visual studio\vc98\mfc\include\afxv_w32.h(14) : fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
Error executing cl.exe.

humptydumpty
February 16th, 2007, 06:43 AM
Can you tell what is the type of your project is it Win32 Console application or Win32 Application or something else.and what is the imv you are using VC6.0 o something else.

Thanx

Suresh.hc
February 16th, 2007, 06:45 AM
humpty i am using Win 32 Application and VC++6

humptydumpty
February 16th, 2007, 06:55 AM
Then Instead of CFIle Simply use CreateFile and ReadFile and WriteFile Method

have alook on the Following Link to Understand Difference between MFC and WIn32 FILE IO

http://www.samspublishing.com/library/content.asp?b=Visual_C_PlusPlus&seqNum=90&rl=1

Thanx

Suresh.hc
February 16th, 2007, 07:05 AM
Humpty I will read that thanks for the link.

Can u please tell me what I have to do for Double click event for list box ??

humptydumpty
February 16th, 2007, 07:54 AM
Dude Right now i am in hurry try this
http://www.codeproject.com/listctrl/listview.asp?df=100&forumid=4748&exp=0&select=1309640

if still Problem Please Post your Project ZIP file here SO anyone can help you. or show your code.

Thanx

//JP added flex table