Sorry! I do have to apologize! You were right all the time!
While preparing the code to show the problem with the least amount of code and recompiling all the time to check whether the problem still exists, the thing suddenly miraculously started working properly. Please don't ask me what the culprit was - I only can assume there was a flaw in my code, which was rectified by my preparations ...
Sorry about that and thank you again for your patience and for your valuable help!
Ernst
NB: I only find "Have a question or comment" or "Add your solution", but no "reply" ...
This is the working solution for a combobox not being part of a dialogue:
#include "TestCombo.h"
#include "resource.h"
#include <string.h>
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#define MAX_LOADSTRING 100
#define WM_TAB (WM_USER)
#define WM_ESC (WM_USER + 1)
#define WM_ENTER (WM_USER + 2)
WNDCLASSEX wcex;
WNDPROC lpfnParProc;
HACCEL hAccelTable;
TCHAR szClass[MAX_LOADSTRING];
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
MSG msg;
HWND hMain;
HWND hListtitel;
HWND hEdittitel;
HDC hdc;
HINSTANCE hInst;
RECT rt;
PAINTSTRUCT ps;
POINT pt;
int wmId;
int wmEvent;
int lmId;
int lmEvent;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ChldProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
hInst = hInstance;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TESTCOMBO));
LoadString(hInstance, IDC_TESTCOMBO, szWindowClass, MAX_LOADSTRING);
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_TESTCOMBO));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_TESTCOMBO);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
if (!RegisterClassEx(&wcex))
{ return FALSE; }
hMain = CreateWindow (szWindowClass,"Test Combobox",
WS_TILED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
100,100,905,667,NULL,NULL,hInstance,NULL);
hListtitel = CreateWindow("COMBOBOX","",
WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | WS_VSCROLL | CBS_HASSTRINGS,
200, 170, 540, 400,hMain,NULL,hInst,NULL);
hEdittitel = FindWindowEx(hListtitel,NULL,"EDIT",NULL);
lpfnParProc = (WNDPROC) SetWindowLong(hEdittitel,GWL_WNDPROC, (DWORD) ChldProc);
InvalidateRect(hMain,NULL,TRUE);
ShowWindow(hMain, SW_SHOWNORMAL);
UpdateWindow(hMain);
SetFocus(hListtitel);
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_TAB:
break;
case WM_ESC:
break;
case WM_ENTER:
break;
case WM_COMMAND:
wmEvent = HIWORD(wParam);
if ((hListtitel != 0) && (lParam == (LPARAM)hListtitel))
{
switch (wmEvent)
{
case CBN_EDITUPDATE:
break;
case CBN_KILLFOCUS:
break;
case CBN_SELCHANGE:
break;
}
break;
}
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK ChldProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_KEYDOWN:
switch (wParam)
{
case VK_TAB:
SendMessage(hMain, WM_TAB, 0, 0);
return 0;
case VK_ESCAPE:
SendMessage(hMain, WM_ESC, 0, 0);
return 0;
case VK_RETURN:
SendMessage(hMain, WM_ENTER, 0, 0);
return 0;
}
break;
}
return CallWindowProc(lpfnParProc, hwnd, msg, wParam, lParam);