Jump to content
  • Advertisement
Sign in to follow this  
linchpin02

windows forms and direct3d - how i combine it ?

This topic is 3903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, thats my first visit in this forum and sorry for my bad english, its not my native language. So my problem is, how can i programm a "Windows-Forms"-Window with an direc3d window in it. I know how to make Windows-Forms application and i also know how to write a drirect3d application but i have no clue how to combine them. What i want to make is a menu bar for my completed direct3d-program which is written with c++. Thanks for the help.

Share this post


Link to post
Share on other sites
Advertisement
IMO making a .NET app just for a menu bar is overkill, considering you'll have to go through quite a bit of effort just to make your managed code work properly with your un-managed DLL. Why not just add a menu to your window using Win32? It's a piece of cake to do either when you're creating the window or afterwards, then all you have to do is handle the WM_COMMAND messages you'll get from the menu.

Not to say Windows Forms isn't great for building a GUI app, I just don't think you're going to save any time and effort if you just want a menu.

Share this post


Link to post
Share on other sites
Are you using Visual Studio? If you are, the easiest way to do this will be to use the resource editor. Go to the resources tab and add a new resource, then click menu. From there, it's very similar to using the Forms Editor in .NET. Simply add the menu items you want, and give them appropriate text. Then what you need to do is give each menu item a unique ID, which usually take the form of ID_FILE_NEW, ID_FILE_SAVE, ID_EDIT_COPY, etc. In your message handler, when you get a WM_COMMAND message the lower word of the WPARAM will contain the ID of the menu item. So your message handler will look something like this:



LRESULT CALLBACK WndProc ( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{

if ( uMsg == WM_COMMAND )
{
if ( LOWORD( wParam ) == ID_FILE_NEW )
return CreateNewDocument();
else if ( LOWORD( wParam ) == ID_FILE_SAVE )
return SaveDocument();

.....
}

.....

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





Hopefully this makes sense, lemme know if it doesn't or if you need some more help. Good luck!

EDIT: I forgot to mention how to add the menu to your window...the two easiest ways are to either associate the window with your window class or add it to your window when you create it. For the first way, set the "lpszMenuName" member of your WNDCLASSEX struct equal to "MAKEINTRESOURCE(IDM_MENU)" (or instead of IDM_MENU use whatever ID you gave to your menu). For the second way, use LoadMenu and pass the "MAKEINTRESOURCE(IDM_MENU)" to get a handle to the menu, then pass that menu as the "hMenu" parameter to CreateWindow or CreateWindowEx.

Share this post


Link to post
Share on other sites
This works good.
But i can´t find help how to control the "check" "and "uncheck" of a menu element.
(I mean the hook-symbol)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!