编辑:现在这很奇怪,如果我将jItems::populate ( std::string myList )的调用从jDropDown::jDropDown的其他位置转移到jDropDown ::jDropDown 的构造函数,则创建子窗口。
最初它在下拉(jDropDown)窗口可见(显示)时被调用,并且程序的流程不允许对jItems::populate ( std::string myList )的调用移动到jDropDown::的构造函数下拉菜单。
我试图做的是从头开始创建一个自定义下拉框,我面临的问题是没有创建最终的 Items(jItem) 窗口,它是一个 oop 设计,每个 Items(jItem) 都是从 jPanel 派生的,其他部分下拉框的一部分也是从 jPanel 驱动的,因此创建每个窗口都遵循相同的过程,但未创建最终的 Items(jItem) 窗口,它们不可见,我无法使用 Visual Studio Spy++ 找到它们
我检查了实例句柄和窗口句柄,两项检查都返回 true,但 jItem 窗口不可见,在 spy++ 中找不到它们(我可以在 spy++ 中看到所有其他窗口)
任何帮助表示赞赏。
这是参考图像和一些相关代码。
bool jPanel::registered = false;
jPanel::jPanel( std::string txt, int x, int y, int width, int height, HWND parent, HINSTANCE hInstance, WORD bitmap, DWORD style )
: jControl( parent, hInstance, bitmap )
{
if ( ! registered )
{
WNDCLASSEX wincl;
wincl.hInstance = hInstance;
wincl.lpszClassName = "jPanel";
wincl.lpfnWndProc = WndProc;
wincl.style = CS_BYTEALIGNWINDOW;
wincl.cbSize = sizeof ( WNDCLASSEX );
wincl.hIcon = 0;
wincl.hIconSm = 0;
wincl.hCursor = ::LoadCursor ( NULL, IDC_ARROW );
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 4;
wincl.hbrBackground = ::CreateSolidBrush ( backgroundColor );
::RegisterClassEx ( &wincl );
jPanel::registered = true;
}
DWORD flag = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_CHILD;
if ( style ) flag = flag | style;
hwnd = ::CreateWindowEx ( 0, "jPanel", txt.c_str ( ), flag, x, y, width, height, parent, 0, hInstance, ( LPVOID ) this ) ;
};
jDropDown::jDropDown ( std::string txt, int x, int y, int width, int height, HWND parent, HINSTANCE hInstance, WORD bitmap )
: jPanel ( txt, x, y, width, height, parent, hInstance, bitmap ), capture ( false ), populated ( false )
{
RECT rect;
::GetWindowRect ( hwnd, &rect );
::MapWindowPoints ( HWND_DESKTOP, ::GetParent ( parent ), ( LPPOINT ) &rect, 2 );
items = new jItems ( "My Items List", rect.left, rect.top + height, width, 300, ::GetParent( parent ), hInstance, 0 );
items->setBackgroundColor ( RGB ( 100, 100, 100 ) );
};
jItems::jItems ( std::string txt, int x, int y, int width, int height, HWND parent, HINSTANCE hInstance, WORD bitmap )
: jPanel ( txt, x, y, width, height, parent, hInstance, bitmap ), wWidth ( width ), wHeight ( 30 )
{
::SetWindowPos ( this->hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
};
bool jItems::populate ( std::string myList )
{
int y = 0;
Hinstance hInstance = ::GetModuleHandle ( NULL );
std::vector < std::string > list = model::Service::explode ( "^", myList );
for ( std::vector < std::string >::const_iterator it = list.begin ( ); it != list.end ( ); ++it )
{
std::string s = *it;
jItem *i = new jItem ( "Your Item", 0, y, wWidth, wHeight, this->hwnd, hInstance, 0 );
}
::SetWindowPos ( this->hwnd, HWND_TOP, 0, 0, wWidth, list.size ( ) * wHeight, SWP_NOMOVE | SWP_NOZORDER );
return true;
};
jItem::jItem ( std::string txt, int x, int y, int width, int height, HWND parent, HINSTANCE hInstance, WORD bitmap )
: jPanel ( txt, x, y, width, height, parent, hInstance, bitmap ), empty ( false )
{
this->setBackgroundColor ( RGB ( 65, 65, 65 ) );
};