Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. List Box & Rich Edit box [modified]

List Box & Rich Edit box [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorialquestion
31 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Hamid Taebi

    Insert LBS_NOTIFY when create listbox hList=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hWnd,(HMENU)IDC_SLIST,hInst,0);


    WhiteSky


    S Offline
    S Offline
    Suresh H
    wrote on last edited by
    #7

    Hi whiteSky, I did that in the BOOL CALLBACK SDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_INITDIALOG: { HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0); i am getting error error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [8]' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe.

    H P 2 Replies Last reply
    0
    • S Suresh H

      Hi whiteSky, I did that in the BOOL CALLBACK SDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_INITDIALOG: { HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0); i am getting error error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [8]' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe.

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #8

      I wanted to said insert LBS_NOTIFY when create your listbox


      WhiteSky


      S P 2 Replies Last reply
      0
      • H Hamid Taebi

        I wanted to said insert LBS_NOTIFY when create your listbox


        WhiteSky


        S Offline
        S Offline
        Suresh H
        wrote on last edited by
        #9

        WhiteSky I am using wizard for creating dialog and dialog controls , I am not using any code to create the dialog.

        1 Reply Last reply
        0
        • S Suresh H

          Hi whiteSky, I did that in the BOOL CALLBACK SDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch(Message) { case WM_INITDIALOG: { HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindowW(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0); i am getting error error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [8]' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe.

          P Offline
          P Offline
          prasad_som
          wrote on last edited by
          #10

          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.

          Prasad Notifier using ATL | Operator new[],delete[][^]

          S 2 Replies Last reply
          0
          • H Hamid Taebi

            I wanted to said insert LBS_NOTIFY when create your listbox


            WhiteSky


            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #11

            He has created list box, shown in above post.

            Prasad Notifier using ATL | Operator new[],delete[][^]

            1 Reply Last reply
            0
            • P prasad_som

              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.

              Prasad Notifier using ATL | Operator new[],delete[][^]

              S Offline
              S Offline
              Suresh H
              wrote on last edited by
              #12

              Hi prasad, again i am getting error.. HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0); 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.

              H P 2 Replies Last reply
              0
              • P prasad_som

                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.

                Prasad Notifier using ATL | Operator new[],delete[][^]

                S Offline
                S Offline
                Suresh H
                wrote on last edited by
                #13

                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 ???

                P 1 Reply Last reply
                0
                • S Suresh H

                  Hi prasad, again i am getting error.. HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0); 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.

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #14

                  One question HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); what is it? before CreateWindow


                  WhiteSky


                  S 1 Reply Last reply
                  0
                  • S Suresh H

                    Hi prasad, again i am getting error.. HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); hwndListBox=CreateWindow(_T("LISTBOX"),NULL,LBS_NOTIFY|WS_BORDER|WS_CHILD|WS_VISIBLE,0,0,100,200,hwnd,(HMENU)IDC_SLIST,hwndListBox,0); 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.

                    P Offline
                    P Offline
                    prasad_som
                    wrote on last edited by
                    #15

                    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.

                    Prasad Notifier using ATL | Operator new[],delete[][^]

                    S 1 Reply Last reply
                    0
                    • H Hamid Taebi

                      One question HWND hwndListBox = GetDlgItem(hwnd, IDC_SLIST); what is it? before CreateWindow


                      WhiteSky


                      S Offline
                      S Offline
                      Suresh H
                      wrote on last edited by
                      #16

                      WhiteSky I am creating a handle for the list box control {IDC_SLIST }

                      H 1 Reply Last reply
                      0
                      • P prasad_som

                        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.

                        Prasad Notifier using ATL | Operator new[],delete[][^]

                        S Offline
                        S Offline
                        Suresh H
                        wrote on last edited by
                        #17

                        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.

                        H 1 Reply Last reply
                        0
                        • S Suresh H

                          WhiteSky I am creating a handle for the list box control {IDC_SLIST }

                          H Offline
                          H Offline
                          Hamid Taebi
                          wrote on last edited by
                          #18

                          So do you have two listbox on your project?


                          WhiteSky


                          1 Reply Last reply
                          0
                          • S Suresh H

                            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.

                            H Offline
                            H Offline
                            Hamid Taebi
                            wrote on last edited by
                            #19

                            You have two hwnds on CreateWindow? wheres HINSTANCE


                            WhiteSky


                            1 Reply Last reply
                            0
                            • S Suresh H

                              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 ???

                              P Offline
                              P Offline
                              prasad_som
                              wrote on last edited by
                              #20

                              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)
                              {
                              //double clicked
                              }
                              break;

                              Prasad Notifier using ATL | Operator new[],delete[][^]

                              S 1 Reply Last reply
                              0
                              • S Suresh H

                                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 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[25]; 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,EM_SETTEXTMODE, pBuffer,0); delete [] pBuffer; } Thanking you, Suresh HC -- modified at 5:37 Friday 16th February, 2007

                                D Offline
                                D Offline
                                David Crow
                                wrote on last edited by
                                #21

                                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

                                1 Reply Last reply
                                0
                                • P prasad_som

                                  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)
                                  {
                                  //double clicked
                                  }
                                  break;

                                  Prasad Notifier using ATL | Operator new[],delete[][^]

                                  S Offline
                                  S Offline
                                  Suresh H
                                  wrote on last edited by
                                  #22

                                  Hi Prasad, Thank you very much list box double click event is work.:)

                                  P 1 Reply Last reply
                                  0
                                  • S Suresh H

                                    Hi Prasad, Thank you very much list box double click event is work.:)

                                    P Offline
                                    P Offline
                                    prasad_som
                                    wrote on last edited by
                                    #23

                                    Welcome ! :)

                                    Prasad Notifier using ATL | Operator new[],delete[][^]

                                    S 1 Reply Last reply
                                    0
                                    • P prasad_som

                                      Welcome ! :)

                                      Prasad Notifier using ATL | Operator new[],delete[][^]

                                      S Offline
                                      S Offline
                                      Suresh H
                                      wrote on last edited by
                                      #24

                                      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. 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(); i have tryed this code in mfc this is working properly but this code does not work in win 32 api, CStdioFile file(str, CFile::modeRead); DWORD dwSize = file.GetLength(); char *pBuffer = new char[dwSize + 1]; UINT uRead = file.Read(pBuffer, dwSize); pBuffer[uRead] = '\0'; file.Close(); ::SendMessage(hwndRichEdit,WM_SETTEXT, 0,(WPARAM)pBuffer); delete [] pBuffer;

                                      P 1 Reply Last reply
                                      0
                                      • S Suresh H

                                        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. 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(); i have tryed this code in mfc this is working properly but this code does not work in win 32 api, CStdioFile file(str, CFile::modeRead); DWORD dwSize = file.GetLength(); char *pBuffer = new char[dwSize + 1]; UINT uRead = file.Read(pBuffer, dwSize); pBuffer[uRead] = '\0'; file.Close(); ::SendMessage(hwndRichEdit,WM_SETTEXT, 0,(WPARAM)pBuffer); delete [] pBuffer;

                                        P Offline
                                        P Offline
                                        prasad_som
                                        wrote on last edited by
                                        #25

                                        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'};

                                        Prasad Notifier using ATL | Operator new[],delete[][^]

                                        S 1 Reply Last reply
                                        0
                                        • P prasad_som

                                          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'};

                                          Prasad Notifier using ATL | Operator new[],delete[][^]

                                          S Offline
                                          S Offline
                                          Suresh H
                                          wrote on last edited by
                                          #26

                                          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 .

                                          P 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups