Go Back   Winamp Forums > Developer Center > Winamp Development

Reply
Thread Tools Search this Thread Display Modes
Old 19th September 2002, 21:18   #1
dilbert627
Junior Member
 
Join Date: Apr 2001
Posts: 7
How to make a window in a plugin??

I'm trying to make a general plugin based on a standalone exe I have already made. The program has one window with 2 buttons on it. Maybe I'm missing something, but when I try to run it, nothing happens. I have all the CreateWindow() code in the init() function. I'm not that familiar with Windows programming (this is actually my first program written in C for Windows. I'm surprised the standalone version actually worked ). So my questions: How do you make a window in a DLL? Do you have to use a window class? Am I totally off and you can only use dialog boxes? Any help would be greatly appreciated.
dilbert627 is offline   Reply With Quote
Old 1st October 2002, 15:28   #2
Cheesy
Junior Member
 
Join Date: Oct 2002
Location: UK
Posts: 15
Send a message via ICQ to Cheesy
something like this might work ... havent tested it

code:


// Begin - NeHe (for sizable window)
DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
DWORD dwStyle=WS_OVERLAPPEDWINDOW;

RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)width; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height
// End - NeHe

{ // Register our window class
WNDCLASS wc;
memset(&wc,0,sizeof(wc));

wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // And Own DC For Window.
wc.lpfnWndProc = WndProc; // our window procedure
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = this_mod->hDllInstance; // hInstance of DLL
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground= NULL; // no background
wc.lpszMenuName = NULL; // no menu
wc.lpszClassName = szAppName; // our window class name

if (!RegisterClass(&wc))
{
MessageBox(this_mod->hwndParent,"Error registering window class","Error",MB_OK);
return 1;
}
}

if (!(hMainWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
szAppName, // Class Name
this_mod->description, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
config_x, config_y, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
this_mod->hwndParent, // WinAmp Parent Window
NULL, // No Menu
this_mod->hDllInstance, // DLL Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
MessageBox(this_mod->hwndParent,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE;
}

Cheesy is offline   Reply With Quote
Old 28th April 2003, 10:28   #3
tourettes
Junior Member
 
Join Date: Apr 2003
Posts: 12
I did try this code and it didn't create a window in Winamp 2.91. There wehe no errors during DLL compiling.
tourettes is offline   Reply With Quote
Old 28th April 2003, 12:15   #4
Cheesy
Junior Member
 
Join Date: Oct 2002
Location: UK
Posts: 15
Send a message via ICQ to Cheesy
I think i forgot some things,

code:

SetWindowLong(hMainWnd,GWL_USERDATA,(LONG)this_mod); // set our user data to a "this" pointer

// show the window
ShowWindow(hMainWnd,SW_SHOWNORMAL);



"this_mod" is your winamp vizualisation/plugin module
Cheesy is offline   Reply With Quote
Old 28th April 2003, 12:59   #5
tourettes
Junior Member
 
Join Date: Apr 2003
Posts: 12
Thanks, now it started to work. Now I only need to learn how to put some GUI-elements in that window. Could you show some URLs? Of course it would be best if I could design window with Visual Studio 6.0 resource editor and use .rc file.
tourettes is offline   Reply With Quote
Old 7th May 2003, 10:18   #6
tourettes
Junior Member
 
Join Date: Apr 2003
Posts: 12
I'm still having problems with my new window. I'm creating it in plugin's init() and all I get is a window that doesn't paint itself. It just has a copy of screen from place where it was created.
tourettes is offline   Reply With Quote
Old 7th May 2003, 12:02   #7
tourettes
Junior Member
 
Join Date: Apr 2003
Posts: 12
code:
HWND DebugDlg;
DebugDlg=CreateDialog(plugin.hDllInstance,MAKEINTRESOURCE(IDD_DebugDlg),plugin.hwndParent,DialogProcDebug);
ShowWindow(DebugDlg, SW_SHOW);



I found this piece of code from DSP_example and it works in that dsp-plugin OK. But when I create own dialog in own plugin this piece of code creates dialog inside the Winamp's main window.
tourettes is offline   Reply With Quote
Old 7th May 2003, 14:02   #8
Cheesy
Junior Member
 
Join Date: Oct 2002
Location: UK
Posts: 15
Send a message via ICQ to Cheesy
Have a look at the winamp visualization config procedure, here it creates a dialog outside winamp window.

code:

void config(struct winampVisModule *this_mod)
{
DLGPROC lpProcInstance;

lpProcInstance = (DLGPROC) MakeProcInstance( (FARPROC) DialogProc,
this_mod->hDllInstance ) ;
DialogBoxParam(this_mod->hDllInstance, MAKEINTRESOURCE(IDD_DIALOG1),
hMainWnd, lpProcInstance, (LPARAM)this_mod);
FreeProcInstance( (FARPROC) lpProcInstance );
}



where "IDD_DIALOG1" is the name of your dialog in the resources and "DialogProc" is you callback function for the dialog e.g.

code:

BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static struct winampVisModule *this_mod;

switch (uMsg)
{
case WM_INITDIALOG:
// initialisation stuff for this dialog...
this_mod = (struct winampVisModule *)lParam;

config_read(this_mod); // might want to read config for your plugin
// and set the dialog to whatever the current config is like..
break;
case WM_PAINT:
// on paint stuff
break;
case WM_CLOSE: // on closing dialog
config_write(this_mod); // write your configuration if you must
EndDialog(hDlg, TRUE);
return ( TRUE );
// lots of other WM_ messages....
}

return 0;
}



hMainWnd is also the 'HWND' of the main window of your application. (i.e. the variable you assigned CreateWindowEx(..) to earlier)

see if that helps...
Cheesy is offline   Reply With Quote
Old 7th May 2003, 14:16   #9
Cheesy
Junior Member
 
Join Date: Oct 2002
Location: UK
Posts: 15
Send a message via ICQ to Cheesy
oh by the way you can probably stop the dialog from apperaing inside the winamp window using your code you submitted earlier, and change it a bit.

it should work if you use 'hMainWnd' instead of 'plugin.hwndParent' then it should create the dialog inside your window instead of the winamp one if thats what you want...
Cheesy is offline   Reply With Quote
Old 7th May 2003, 15:56   #10
tourettes
Junior Member
 
Join Date: Apr 2003
Posts: 12
Now I have completely working dialog. I did it a littlebit different than your example, but thanks anyway.

Now I have a different problem. Normaly I have build all my Windows applicaiton using Borland's C++ builder. Borland differens much from MFC and now I would like to know is there any better way to add text in Editbox.

code:

SetDlgItemText(DebugDlg,IDC_EDIT1,DebugText);



This is how I can write text to Editbox, but it will replace all text that is already in Editbox. (of cource I could use one variable to store text in Editbox using SetDlgItemText but it isn't a really good way to do it.) In Borland's C++ builder I simply can use following method.

code:

Editbox1.AddLine("New line");

tourettes is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > Winamp Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump