Quick Sign In:  

Forum: VirtualDJ Plugins

Topic: Weird behavior of tab control on VD

This topic is old and might contain outdated or incorrect information.

alou83Home userMember since 2013
Hi,

I am writing a VD plugin that s got a Win Tab Control on it. The problem it never select tabs other than the first one when you click on them. I don t thinks it has something to see with the code as it works fine when I launch the window independently (I mean not as a VD plugin but a standalone application).

I am so struggling to find what did I do wrong. If someone could help, I would be greatfull.

I paste here the code of main windows (on the plugin side, I use createwindow and pass the hwnd to VD as advised in the VD plugin doc):

Thanks

#include "DJ4Me_gui.h"


LRESULT CALLBACK DJ4Me_gui::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
DJ4Me_gui* This = (DJ4Me_gui*)GetWindowLongPtr(hwnd,GWL_USERDATA);

switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;

case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);

FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));

EndPaint(hwnd, &ps);
return 0;
}

case WM_NOTIFY:
{

HWND tab = This->_tabBox;
HWND sender = (HWND)lParam;
int selectedTab = TabCtrl_GetCurSel(tab);

wchar_t buffer[256];
wsprintf(buffer, L"%d", selectedTab);


switch (((LPNMHDR)lParam)->code)
{
case TCN_SELCHANGING:
{
// Return FALSE to allow the selection to change.
return FALSE;
}

case TCN_SELCHANGE:
{
MessageBox(0,buffer, L"Title", MB_OK);
int selectedTab = TabCtrl_GetCurSel(tab);

switch ( selectedTab ) {
case 0: if ( This->_tab1 == This->_currentTab ) break;
ShowWindow(This->_currentTab, SW_HIDE);
ShowWindow(This->_tab1, SW_SHOW);
This->_currentTab = This->_tab1;
break;
case 1: if ( This->_tab2 == This->_currentTab ) break;
ShowWindow(This->_currentTab, SW_HIDE);
ShowWindow(This->_tab2, SW_SHOW);
This->_currentTab = This->_tab2;
break;
}
}
}

}

}

return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

DJ4Me_gui::DJ4Me_gui(HINSTANCE hInstance)
{
this->the_instance = hInstance;
init_win(hInstance);

this->create_toolbar();
this->create_tabBox();
this->create_listbox();

this->resize();

SetCursor(LoadCursor(NULL, IDC_ARROW));
SetWindowLongPtr(the_handle, GWL_USERDATA, (LONG)this);
}

int DJ4Me_gui::init_win(HINSTANCE hInstance)
{
// Register the window class.
const wchar_t CLASS_NAME[] = L"dj4me_gui";

WNDCLASS wc = { };

wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;

RegisterClass(&wc);

// Create the window.
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
L"Learn to Program Windows", // Window text
WS_OVERLAPPEDWINDOW, // Window style

// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

NULL, // Parent window
NULL, // Menu
NULL, // Instance handle
NULL // Additional application data
);

if (hwnd == NULL)
{
return 0;
}

the_handle = hwnd;

return 1;
}

int DJ4Me_gui::show()
{
ShowWindow(the_handle, 5);

// Run the message loop.
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return 1;
}

int DJ4Me_gui::create_toolbar()
{
HIMAGELIST g_hImageList = NULL;

// Declare and initialize local constants.
const int ImageListID = 0;
const int numButtons = 3;
const int bitmapSize = 16;

const DWORD buttonStyles = BTNS_AUTOSIZE;

// Create the toolbar.
HWND hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD | TBSTYLE_WRAPABLE, 0, 0, 0, 0,
the_handle, NULL, the_instance, NULL);

if (hWndToolbar == NULL)
return NULL;

// Create the image list.
g_hImageList = ImageList_Create(bitmapSize, bitmapSize, // Dimensions of individual bitmaps.
ILC_COLOR16 | ILC_MASK, // Ensures transparent background.
numButtons, 0);

// Set the image list.
SendMessage(hWndToolbar, TB_SETIMAGELIST,
(WPARAM)ImageListID,
(LPARAM)g_hImageList);

// Load the button images.
SendMessage(hWndToolbar, TB_LOADIMAGES,
(WPARAM)IDB_STD_SMALL_COLOR,
(LPARAM)HINST_COMMCTRL);

// Initialize button info.
// IDM_NEW, IDM_OPEN, and IDM_SAVE are application-defined command constants.

TBBUTTON tbButtons[numButtons] =
{
{ MAKELONG(STD_FILENEW, ImageListID), IDM_NEW, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"New" },
{ MAKELONG(STD_FILEOPEN, ImageListID), IDM_OPEN, TBSTATE_ENABLED, buttonStyles, {0}, 0, (INT_PTR)L"Open"},
{ MAKELONG(STD_FILESAVE, ImageListID), IDM_SAVE, 0, buttonStyles, {0}, 0, (INT_PTR)L"Save"}
};

// Add buttons.
SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)numButtons, (LPARAM)&tbButtons);

// Resize the toolbar, and then show it.
SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);
ShowWindow(hWndToolbar, TRUE);

_toolBar = hWndToolbar;

return 1;
}

int DJ4Me_gui::create_tabBox()
{


HWND hwnd = CreateWindowEx(NULL, WC_TABCONTROL, NULL,
WS_CHILD | WS_VISIBLE,
0,0,0,0,
the_handle, NULL,
the_instance, NULL);

if (hwnd == NULL)
{
return NULL;
}

// Create two tabs.
TCITEM tab_info;
//memset(&tab_info, 0, sizeof(tab_info));
tab_info.mask = TCIF_TEXT;
tab_info.pszText = L"Available Songs";
tab_info.cchTextMax = 25;
SendMessage(hwnd, TCM_INSERTITEM, 0, (LPARAM)&tab_info);

tab_info.pszText = L"Requests Queue";
SendMessage(hwnd, TCM_INSERTITEM, 1, (LPARAM)&tab_info);

// Create the tab view windows
_tab1 = CreateWindowEx(NULL, L"STATIC", L"",
WS_CHILD | WS_VISIBLE|SS_OWNERDRAW,0,0,0,0,hwnd, (HMENU)1, the_instance, NULL);

SetParent(_tab1, the_handle);

_tab2 = CreateWindowEx(NULL, L"STATIC", L"",
WS_CHILD|SS_OWNERDRAW,0,0,0,0,hwnd, (HMENU)2,the_instance, NULL);

SetParent(_tab2, the_handle);

_tabBox = hwnd;

ShowWindow(_tab2, SW_HIDE);
ShowWindow(_tab1, SW_SHOW);
_currentTab = _tab1;

return 1;

}


int DJ4Me_gui::create_listbox()
{
HWND hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, L"Listbox", NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL |
LBS_DISABLENOSCROLL | LBS_SORT,
0, 0, 0, 0, _tab1, (HMENU)11,
the_instance, NULL);

if (hwnd == NULL)
{
return NULL;
}
_listBox1 = hwnd;

SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM)L"Martyn.Rae");

hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, L"Listbox", NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL |
LBS_DISABLENOSCROLL | LBS_SORT,
0, 0, 0, 0, _tab2, (HMENU)11,
the_instance, NULL);

if (hwnd == NULL)
{
return NULL;
}
_listBox2 = hwnd;

SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM)L"Alou.seck");

return 1;
}

int DJ4Me_gui::resize()
{
//Getting the toolbar size
RECT rect;
GetClientRect(_toolBar, &rect);
int height_t = rect.bottom - rect.top;

//Getting the windows size
GetClientRect(the_handle, &rect);
int width_tb = rect.right - rect.left;
int height_tb = rect.bottom - rect.top;

SetWindowPos(_tabBox, NULL,0, height_t, width_tb, height_tb - height_t,SWP_SHOWWINDOW);

//Getting the tab size
GetClientRect(_tabBox,&rect);
SendMessage(_tabBox, TCM_ADJUSTRECT, FALSE, (LPARAM)&rect);

SetWindowPos(_tab1,NULL, rect.left , rect.top + height_t , rect.right - rect.left, rect.bottom - rect.top,SWP_SHOWWINDOW );
SetWindowPos(_tab2,NULL, rect.left, rect.top + height_t , rect.right - rect.left, rect.bottom - rect.top,SWP_SHOWWINDOW );

//Getting the tab1 size
GetClientRect(_tab1,&rect);

SetWindowPos(_listBox1, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE|SWP_NOZORDER );

//Getting the tab1 size
GetClientRect(_tab2,&rect);

SetWindowPos(_listBox2, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE|SWP_NOZORDER );

return 1;
}

 

Posted Tue 24 Sep 13 @ 1:21 pm
SBDJPRO Infinity Member since 2006
No reason a tab control wouldn't work; I've used them in plugin windows in the past.

What does your tracing show when you follow the message flow?
 

Posted Tue 24 Sep 13 @ 4:03 pm
alou83Home userMember since 2013
In the message handling process, I try to show the selected tab by:

int selectedTab = TabCtrl_GetCurSel(tab);
wsprintf(buffer, L"%d", selectedTab);
MessageBox(0,buffer, L"Title", MB_OK);

It shows the expected behavior when run as standalone app. But shows always 0 when run as VD plugin. I have not no idea about why.

 

Posted Tue 24 Sep 13 @ 4:14 pm


(Old topics and forums are automatically closed)