NO

Author Topic: ComboBox doesn't load  (Read 7476 times)

triola

  • Guest
ComboBox doesn't load
« on: July 13, 2014, 09:54:08 PM »
This is my first go with Pelles, I used the Wizard to create a win32 dialog project.
I used the dialog editor to add combobox and button controls rather than creating them programmatically.
 
I can't figure out why I fail to get strings to load in a combobox.
I checked for a valid handle on GetDlgItem() (not NULL) and SendMessage() returns 0.
I also tried SendDlgMessage(), same result, no strings load to combobox.

Curious, can you see anything that might be wrong here?

headers:
Code: [Select]
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include "main.h"
linker-Libs:
Code: [Select]
kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib delayimp.lib
In main.h:
Code: [Select]
#define DLG_MAIN        1001
#define IDR_ICO_MAIN    8001
//combobox IDs
#define  IDMODGLOBAL    6001
#define  IDMODCAMPAIGN  6002
#define  IDMODMULTIPLAY 6003
#define  IDMODMUSIC     6004
In main.c - globals:
Code: [Select]
//control handles
static HWND hmodglobal;
static HWND hmodcampaign;
static HWND hmodmultiplay;
static HWND hmodmusic;
In MainDlgProc():
Code: [Select]
case WM_INITDIALOG:
   
//get handles
hmodglobal   =GetDlgItem(hwndDlg, IDMODGLOBAL ); 
hmodcampaign =GetDlgItem(hwndDlg, IDMODCAMPAIGN );   
hmodmultiplay=GetDlgItem(hwndDlg, IDMODMULTIPLAY ); 
hmodmusic    =GetDlgItem(hwndDlg, IDMODMUSIC );     

//these fail to load combobox
SendMessage(hmodglobal, CB_ADDSTRING, 0, (LPARAM)"this is test 1");
SendMessage(hmodglobal, CB_ADDSTRING, 0, (LPARAM)"this is test 2");
SendMessage(hmodglobal, CB_ADDSTRING, 0, (LPARAM)"this is test 3");
SendMessage(hmodglobal, CB_ADDSTRING, 0, (LPARAM)"this is test 4");
           
return TRUE;

These are the only references that have anything to do with loading the comboboxes. I don't see anything obviously out of place, but strings won't load.

Thanks


triola

  • Guest
Re: ComboBox doesn't load
« Reply #1 on: July 14, 2014, 03:42:33 AM »
It might be more helpful to see what I'm trying to do, in context.
The problem may not be with the code, but some other issue in the project.
So far, I can't figure out why there's a messaging problem.

Code: [Select]
/****************************************************************************
 *                                                                          *
 * File    : main.c                                                         *
 *                                                                          *
 * Purpose : Generic dialog based Win32 application.                        * 
 *           This case: warzone mod loader in Pelles-C                      *
 *                                                                          * 
 * When run, read directories associated with warzone mods and list any     *
 * mods found in drop-down combo boxes. Select mod to be used as an arg     *
 * to warzone2100.exe, create command-line string and run with system()     *
 * or CreateProcess().                                                      *
 *                                                                          *
 *                                                                          *
 * **************************************************************************                                                                         *
 * NOTE: in order to test this, if you don't have warzone installed:        *
 *       1.)Create a path on C: equivelent to WZGLOBAL, below.              *
 *       2.)Put several dummy-files (text files) and change thier           *
 *          extensions from .txt to .wz (EX: textfile1.wz).                 *
 * ISSUES:                                                                  *
 *          SendMessage doesn't populate comboboxes.                        *
 *          Code remains unfinished until combo-messaging is resolved.      *
 *                                                                          *
 ****************************************************************************/

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include "main.h"

//for loadcombo()
#include <stdio.h>
#include <io.h>

//*************************************
//comment this out to run release code
#define test
//*************************************

#define NELEMS(a)  (sizeof(a) / sizeof((a)[0]))

//paths for different wz-mod types
#define WZGLOBAL     "C:\\Program Files\\Warzone 2100-3.1.1\\mods\\global\\*.wz"
#define WZMULTIPLAY  "C:\\Program Files\\Warzone 2100-3.1.1\\mods\\multiplay\\*.wz"
#define WZCAMPAIGN   "C:\\Program Files\\Warzone 2100-3.1.1\\mods\\campaign\\*.wz"
#define WZMUSIC      "C:\\Program Files\\Warzone 2100-3.1.1\\mods\\music\\*.wz"


/** Prototypes **************************************************************/

static INT_PTR CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);
int    loadcombo(HWND combo, char*path);

/** Global variables ********************************************************/
static HANDLE ghInstance;

//control handles
static HWND hmodglobal;
static HWND hmodcampaign;
static HWND hmodmultiplay;
static HWND hmodmusic;


/****************************************************************************
 *                                                                          *
 * Function: WinMain                                                        *
 *                                                                          *
 * Purpose : Initialize the application.  Register a window class,          *
 *           create and display the main window and enter the               *
 *           message loop.                                                  *
 *                                                                          *
 * History : Date      Reason                                               *
 *           00/00/00  Created                                              *
 *                                                                          *
 ****************************************************************************/

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
    INITCOMMONCONTROLSEX icc;
    WNDCLASSEX wcx;

    ghInstance = hInstance;

    /* Initialize common controls. Also needed for MANIFEST's */
    /*
     * TODO: set the ICC_???_CLASSES that you need.
     */
    icc.dwSize = sizeof(icc);
    icc.dwICC = ICC_WIN95_CLASSES /*|ICC_COOL_CLASSES|ICC_DATE_CLASSES|ICC_PAGESCROLLER_CLASS|ICC_USEREX_CLASSES|... */;
    InitCommonControlsEx(&icc);


    /* Get system dialog information */
    wcx.cbSize = sizeof(wcx);
    if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
        return 0;

    /* Add our own stuff */
    wcx.hInstance = hInstance;
    wcx.hIcon     = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
    wcx.lpszClassName = _T("wzmodClass");
    if (!RegisterClassEx(&wcx))
        return 0;

    /* The user interface is a modal dialog box */
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}


static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   
 
switch (uMsg)
    {
        case WM_INITDIALOG:
   
    //get handles to controls
            hmodglobal   =GetDlgItem(hwndDlg, IDMODGLOBAL ); 
            hmodcampaign =GetDlgItem(hwndDlg, IDMODCAMPAIGN );   
            hmodmultiplay=GetDlgItem(hwndDlg, IDMODMULTIPLAY ); 
            hmodmusic    =GetDlgItem(hwndDlg, IDMODMUSIC );     
           
//init combos with mods, if any
loadcombo(hmodglobal,    WZGLOBAL);
loadcombo(hmodcampaign,  WZCAMPAIGN);
loadcombo(hmodmultiplay, WZMULTIPLAY);
loadcombo(hmodmusic,     WZMUSIC);
 
            return TRUE;

        case WM_SIZE:
            /*
             * TODO: Add code to process resizing, when needed.
             */
            return TRUE;

        case WM_COMMAND:
            switch (GET_WM_COMMAND_ID(wParam, lParam))
            {
                /*
                 * TODO: Add more control ID's, when needed.
                 */
                case IDOK:

                    EndDialog(hwndDlg, TRUE);
                    return TRUE;
            }
            break;

        case WM_CLOSE:
//call wz.exe with args, at this point.
            EndDialog(hwndDlg, 0);
            return TRUE;

        /*
         * TODO: Add more messages, when needed.
         */
    }

    return FALSE;
}

//populate combos with mods, if any
int loadcombo(HWND hcombo, char *path)
{
char buf[2048];
struct _finddata_t fd;
long   hfile;
   

if((hfile=_findfirst(path, &fd))<1) return 0;
   #ifdef test
   strcpy(buf,fd.name);
   strcat(buf, "\n");
     #endif

   #ifndef test
   SendMessage(hcombo, CB_ADDSTRING, 0,(LPARAM)fd.name);     
   #endif
while (_findnext(hfile, &fd)==0)
    {
   #ifdef test
   strcat(buf,fd.name);
   strcat(buf,"\n");
     #endif

   #ifndef test
   SendMessage(hcombo, CB_ADDSTRING, 0,(LPARAM)fd.name);     
   #endif
     
    }
_findclose(hfile);

   #ifdef test
           MessageBox(NULL, buf, "test", MB_OK|MB_ICONINFORMATION);
   #endif

return 0;
}

laurro

  • Guest
Re: ComboBox doesn't load
« Reply #2 on: July 14, 2014, 10:28:05 AM »
   Hi triola, welcome to forum.

I'm pretty sure it's a problem with your IDs.
Overwrite main.c, main.h, main.rc with this:

Code: [Select]

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include "main.h"


static INT_PTR CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);
static HANDLE ghInstance;

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
INITCOMMONCONTROLSEX icc;
WNDCLASSEX wcx;

ghInstance = hInstance;
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&icc);
wcx.cbSize = sizeof(wcx);

if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
return 0;

wcx.hInstance = hInstance;
wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDR_ICO_MAIN));
wcx.lpszClassName = _T("hfghhfdgClass");
if (!RegisterClassEx(&wcx))
return 0;

return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)MainDlgProc);
}


static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hmodglobal;
static HWND hmodcampaign;
static HWND hmodmultiplay;
static HWND hmodmusic;

switch (uMsg)
{
case WM_INITDIALOG:
{
hmodglobal = GetDlgItem(hwndDlg, IDMODGLOBAL);
hmodcampaign = GetDlgItem(hwndDlg, IDMODCAMPAIGN);
hmodmultiplay = GetDlgItem(hwndDlg, IDMODMULTIPLAY);
hmodmusic = GetDlgItem(hwndDlg, IDMODMUSIC);

SendMessage(hmodglobal, CB_ADDSTRING, 0, (LPARAM)"this is test 1");
SendMessage(hmodglobal, CB_ADDSTRING, 0, (LPARAM)"this is test 2");
SendMessage(hmodglobal, CB_ADDSTRING, 0, (LPARAM)"this is test 3");
SendMessage(hmodglobal, CB_ADDSTRING, 0, (LPARAM)"this is test 4");

return TRUE;
}

case WM_SIZE:
return TRUE;

case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case IDOK:
EndDialog(hwndDlg, TRUE);
return TRUE;
}
break;

case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;

}
return FALSE;
}


Code: [Select]
// INCLUDE FILE generated by "Pelles C for Windows, version 1.00".
#define DLG_MAIN  1001
#define IDR_ICO_MAIN  8001

#define  IDMODGLOBAL    4001
#define  IDMODCAMPAIGN  4002
#define  IDMODMULTIPLAY 4003
#define  IDMODMUSIC     4004

open main.rc as a text file

Code: [Select]
// RESOURCE SCRIPT generated by "Pelles C for Windows, version 7.00".

#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "main.h"

LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US

DLG_MAIN DIALOGEX DISCARDABLE 6, 18, 194, 102
STYLE DS_SHELLFONT|DS_MODALFRAME|DS_3DLOOK|WS_THICKFRAME|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_VISIBLE
CAPTION "hfghhfdgdffd Program"
CLASS "hfghhfdgClass"
FONT 8, "MS Shell Dlg", 0, 0, 1
{
  CONTROL "OK", IDOK, "Button", WS_TABSTOP, 72, 4, 45, 15
  CONTROL "", 4001, "ComboBox", WS_BORDER|CBS_DROPDOWN|CBS_SORT|WS_VSCROLL|WS_TABSTOP, 4, 32, 96, 64
  CONTROL "", 4002, "ComboBox", WS_BORDER|CBS_DROPDOWN|CBS_SORT|WS_VSCROLL|WS_TABSTOP, 104, 32, 88, 40
  CONTROL "", 4003, "ComboBox", WS_BORDER|CBS_DROPDOWN|CBS_SORT|WS_VSCROLL|WS_TABSTOP, 0, 80, 100, 40
  CONTROL "", 4004, "ComboBox", WS_BORDER|CBS_DROPDOWN|CBS_SORT|WS_VSCROLL|WS_TABSTOP, 104, 80, 88, 40
}

IDR_ICO_MAIN ICON "main.ico"


the line in main.rc:
    CONTROL "",4001, "ComboBox" ......
must match with:
    #define IDMODGLOBAL 4001
in main.h in order to make work:
    hmodglobal = GetDlgItem(hwndDlg, IDMODGLOBAL);

Laur

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: ComboBox doesn't load
« Reply #3 on: July 14, 2014, 11:07:28 AM »
Yes seems there are no problems unless ID'd and test.
See attached demo.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

triola

  • Guest
Re: ComboBox doesn't load
« Reply #4 on: July 14, 2014, 05:32:05 PM »
I'm pretty sure it's a problem with your IDs.
Thanks for looking, laurro, that's what I thought too.

But no, the code changed between my first post and second post. In my efforts to find the reason for a messaging conflict, I had changed both main.rc and main.h IDs to be sure they corresponded with each other.  These are the versions used with the code in post #2:

main.h:
Code: [Select]
// INCLUDE FILE generated by "Pelles C for Windows, version 1.00".

#define DLG_MAIN        1001
#define IDR_ICO_MAIN    8001

//control IDs
#define  IDMODGLOBAL    4001
#define  IDMODCAMPAIGN  4002
#define  IDMODMULTIPLAY 4003
#define  IDMODMUSIC     4004
main.rc:
Code: [Select]
// RESOURCE SCRIPT generated by "Pelles C for Windows, version 7.00".

#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "main.h"

LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US

DLG_MAIN DIALOGEX DISCARDABLE 6, 18, 238, 166
STYLE DS_SHELLFONT|DS_MODALFRAME|DS_3DLOOK|WS_THICKFRAME|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_VISIBLE
CAPTION "WZ MODS LAUNCHER"
CLASS "wzmodClass"
FONT 8, "MS Shell Dlg", 0, 0, 1
{
  CONTROL "LAUNCH",         IDOK,          "Button",   WS_TABSTOP, 184, 144, 45, 15
  CONTROL "MODS-GLOBAL",    4007,          "Static",   WS_GROUP, 8, 4, 96, 8
  CONTROL "",               IDMODGLOBAL,   "ComboBox", WS_BORDER|CBS_DROPDOWN|WS_VSCROLL|WS_TABSTOP, 8, 16, 172, 16
  CONTROL "MODS-CAMPAIGN",  4008,          "Static",   WS_GROUP, 8, 36, 92, 8
  CONTROL "",               IDMODCAMPAIGN, "ComboBox", WS_BORDER|CBS_DROPDOWN|WS_VSCROLL|WS_TABSTOP, 8, 48, 172, 16
  CONTROL "MODS-MULTIPLAY", 4009,          "Static",   WS_GROUP, 8, 68, 88, 8
  CONTROL "",               IDMODMULTIPLAY,"ComboBox", WS_BORDER|CBS_DROPDOWN|WS_VSCROLL|WS_TABSTOP, 8, 80, 172, 16
  CONTROL "MODS-MUSIC",     4010,          "Static",   WS_GROUP, 8, 100, 84, 8
  CONTROL "",               IDMODMUSIC,    "ComboBox", WS_BORDER|CBS_DROPDOWN|WS_VSCROLL|WS_TABSTOP, 8, 112, 172, 16
  CONTROL "Select",         4011,          "Button",   BS_AUTORADIOBUTTON, 192, 16, 44, 10
  CONTROL "Select",         4012,          "Button",   BS_AUTORADIOBUTTON, 192, 48, 40, 10
  CONTROL "Select",         4013,          "Button",   BS_AUTORADIOBUTTON, 192, 80, 40, 10
  CONTROL "Select",         4014,          "Button",   BS_AUTORADIOBUTTON, 192, 112, 40, 10
}

IDR_ICO_MAIN ICON "main.ico"




triola

  • Guest
Re: ComboBox doesn't load
« Reply #5 on: July 14, 2014, 05:40:13 PM »
Yes seems there are no problems unless ID'd and test.
See attached demo.

Thanks, frankie, I'll run your example and let you know how it goes.  Meanwhile, I'm thinking I've got something else wrong in my project config (maybe), so I'm attaching the project so those more experienced with this compiler might spot the issue. It's got me stumped, so far.

laurro

  • Guest
Re: ComboBox doesn't load
« Reply #6 on: July 14, 2014, 07:38:05 PM »
Make the height of combobox bigger.

Laur.

triola

  • Guest
Re: ComboBox doesn't load
« Reply #7 on: July 15, 2014, 04:21:10 AM »
See attached demo.

Frankie, the demo worked perfectly (in your project space).

What I found after checking my rc-file again, (recall that it was as is shown in my previous post), is that it had either reverted or had not saved.
After saving it three times in a row (to make sure) I ran the compile again and it managed to load -one- string, just one.

Finally, I moved my main.c over to your project space, renamed your .c  file to triola.bak, renamed my main.c to triola.c and without changing a line, it worked as expected.
Of course it used your RC file, so I'm still left with the 'iffys' on what may have gone south with either the rc-file, makefile, or resource compiler.

Anyway, though I'd really like to know what went wrong, it does work now.

Thanks for all your effort on this somewhat 'odd' problem.

Tony

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: ComboBox doesn't load
« Reply #8 on: July 15, 2014, 11:05:09 AM »
Finally, I moved my main.c over to your project space, renamed your .c  file to triola.bak, renamed my main.c to triola.c and without changing a line, it worked as expected.
Of course it used your RC file, so I'm still left with the 'iffys' on what may have gone south with either the rc-file, makefile, or resource compiler.
Tony
Tony,
the problem should be the ID's again.
If you open the rc file in PellesC IDE you will see that the name of each element, dialog and controls, is set as the symbol that you use in the code, and its value is automatically assigned by IDE itself (that also updates the include file main.h). This way using the selected symbol the numeric value of ID's is alway aligned with the value used in the code.
If you put the numeric values by hand it's your responsability that they are the same in RC compilation and code.
Maye you want get some exercise on use of the IDE and its features.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

laurro

  • Guest
Re: ComboBox doesn't load
« Reply #9 on: July 15, 2014, 11:53:55 AM »
No Frankie, his problems are not with his IDs, he has modified inside the resource editor
the heights of combo boxes, the controls are too small to cover both edit and list box childs,
download his attachment, see the problem.

Laur

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: ComboBox doesn't load
« Reply #10 on: July 15, 2014, 12:08:18 PM »
Oh yes Laur you're right, I haven't downloaded it  :(.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

triola

  • Guest
Re: ComboBox doesn't load
« Reply #11 on: July 15, 2014, 03:52:47 PM »
...he has modified inside the resource editor the heights of combo boxes...

Laurro, indeed this is the difference. However, I didn't modify the height parameter. Notice all combos are the same height, apparently the rc/dialog editor defaulted to this height for each combo I inserted and I wasn't aware I had to change this to accommodate more entries.

Thank you for showing me this, I had  no idea what the problem was.