Solved

Stubborn Combo Box appears to ignore my LB_ADDSTRING messages.

Posted on 1997-01-07
1
379 Views
Last Modified: 2013-12-03
I have been attempting to insert five strings into a combo box, to no avail.  Not only do the strings not display, but my DBWin app reports "err DLG_LBOX 02AF:B39F: Invalid string pointer: 0000:0000".  Here is the dialog procedure I'm using:

/* Start of C Code */
BOOL FAR PASCAL MainDlgProc(HWND hDlg, UINT msg, WPARAM wP, LPARAM lP)
{
    switch (msg)
    {
        case WM_INITDIALOG:
        {
            HWND hwLBox;
            DWORD dwRet;
            int i;

            LPSTR prgNames[5]={"File Manager", "Character Map", "Windows Help", "Solitaire", "Minesweeper"};

            hwLBox=GetDlgItem(hDlg, IDL_PROGS);
            if(hwLBox==NULL)
                MessageBox(NULL, "Debugging message number 0 inserted in \"DLG_LBOX.C\" on 05-Jan-1997 at 12:18:05", "Debugging Message...", MB_APPLMODAL|MB_ICONINFORMATION|MB_OK);
            dwRet=SendMessage(hwLBox, LB_RESETCONTENT, 0, 0L);
            if(dwRet==LB_ERR)
                MessageBox(NULL, "Debugging message number 1 inserted in \"DLG_LBOX.C\" on 04-Jan-1997 at 11:54:57", "Debugging Message...", MB_APPLMODAL|MB_ICONINFORMATION|MB_OK);
            for(i=0;i==4;i++)
                SendMessage(hwLBox, LB_ADDSTRING, 0, (LPARAM)(LPSTR)prgNames[i]);
            return FALSE;
            }
            break;

        case WM_COMMAND:
            switch(wP)
            {
                case IDB_EXECUTE:
                {
                    HWND hwLBox;
                    DWORD dwIndex;

                    hwLBox=GetDlgItem(hDlg, IDL_PROGS);
                    dwIndex=SendMessage(hwLBox, LB_GETCURSEL, 0, 0);

                    if(dwIndex==0)
                        WinExec("WINFILE.EXE", 1);
                    if(dwIndex==1)
                        WinExec("CHARMAP.EXE", 1);
                    if(dwIndex==2)
                        WinExec("WINHELP.EXE", 1);
                    if(dwIndex==3)
                        WinExec("SOL.EXE", 1);
                    if(dwIndex==4)
                        WinExec("WINMINE.EXE", 1);
                    if(dwIndex!=LB_ERR)
                        DestroyWindow(hDlg);
                    else
                    {
                        MessageBeep(MB_ICONHAND);
                        MessageBox(hDlg, "Please select a program from the listbox before selecting execute.\0", "Please make a selection...\0", MB_APPLMODAL|MB_ICONHAND|MB_OK);
                    }
                }
                break;
            }
        break;

        case WM_DESTROY:
        {
            HWND hwLBox, hwUnused;

            hwLBox=GetDlgItem(hDlg, IDL_PROGS);
            SendMessage(hwLBox, LB_RESETCONTENT, 0, 0L);
            PostQuitMessage(0);
        }
        break;

        default:
            return FALSE;
            break;
    }
    return TRUE;
}

/* End Code */

So, things appear to be okay.  I've tried just about everything I can think of, including sending each string as a literal using two casts (LPARAM and LPSTR) to send it.  I am going crazy!  If you can give me any help it would be appreciated.  Thank you.

                 Steven Spain
                 SJSME@IX.NETCOM.COM
0
Comment
Question by:sjsme
1 Comment
 

Accepted Solution

by:
msaraiva earned 120 total points
ID: 1298601
Have you tried, instead of SendMessage, PostMessage ?

/* ... */
for(i=0;i==4;i++)
  PostMessage( hwLBox, LB_ADDSTRING, 0, (LPARAM)(LPSTR)prgNames[i]);
/* ... */
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question