Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mattman

Adding Controls to Windows through Code?

This topic is 5751 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

Does anyone know a site where I can learn to add controls to windows through coding in MS VC++? Or perhaps some code you can paste in here to show me how it''s done? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
It''s easy:

HWND Button_Wnd = CreateWindow( "Button", "I''m a button",
WS_CHILD,
5, 5, 100, 20,
hWnd_Parent, NULL, hInst, 0 );

With that code you''ll create a button in you window.


KaMiKaZe

Share this post


Link to post
Share on other sites
Ahhh...just a note to anyone else who looks at this, to make the button immediately visible, you also need to include the style "WS_VISIBLE" in combination with the "WS_CHILD" flag. (So in other words, you''d put "WS_CHILD | WS_VISIBLE".) Also, I''m assuming you can exclude this flag, and just use the ShowWindow(...) function.

Share this post


Link to post
Share on other sites
On a similar note, if I choose to use VC++''s built in dialog editor instead, how would I go about displaying it? I looked through the help files a bit and tried a few things, but I don''t understand how to display a dialog that I made in the editor. Any ideaS?

Share this post


Link to post
Share on other sites
can anyone tell me why nothing is added to the list here? I also can't get anything to work when I switch the comments between the two SendMessage lines...


hWndTemp = CreateWindow("combobox", "", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | CBS_SORT | CBS_DROPDOWNLIST | CBS_HASSTRINGS, 10, 10, 125, 150, hWnd, (HMENU) ID_DRIVE, hInst, 0);
SendMessage(hWndTemp, CB_DIR, DDL_DRIVES | DDL_READWRITE, (LPARAM) "*.*");
//SendMessage(hWndTemp, CB_ADDSTRING, 0, (LPARAM) "Testing");


[edited by - Mattman on January 24, 2003 7:04:49 PM]

Share this post


Link to post
Share on other sites
I don''t know for sure, I never used comboboxes by hardcoding them, I use dialogeditor, that''s what everybody does. If you run the app, and press on the pulldown button for the app, does there appear a small black 1 or 2 pixel high bar? If so, the bar is the dropdown part and needs to be resized, no idea how you do that, maybe change the height. If not, try uncommenting your line of code(The line you use to send the stuff isn''t for the combobox).

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.


My Site

Share this post


Link to post
Share on other sites
quote:
Original post by Peon
On a similar note, if I choose to use VC++''s built in dialog editor instead, how would I go about displaying it? I looked through the help files a bit and tried a few things, but I don''t understand how to display a dialog that I made in the editor. Any ideaS?


You should take a look at this.

here''s an example code that would open a Dialog:

#include <Windows.h>
#include "Resource.h" // Don''t forget to build you dialog first

LRESULT CALLBACK Dlg_Messages( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR CommandLine, int nShowCmd )
{
DialogBox( hInst, MAKEINTRESORUCE( IDD_MAIN ), NULL, Dlg_Messages );
return 0;
}

LRESULT CALLBACK Dlg_Messages( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch(msg)
{
case WM_CLOSE:
EndDialog( hDlg, 0 );
}
return 0;
}

Hope that helps you


KaMiKaZe

Share this post


Link to post
Share on other sites
Kamikaze: Thanks I saw something similar in another thread which I used, to no avail. Turns out the "Is Visible" flag on the dialog was set to false by default... go figure

Share this post


Link to post
Share on other sites

  • 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!