Advertisement

Adding Controls to Windows through Code?

Started by January 22, 2003 05:42 PM
6 comments, last by Mattman 21 years, 9 months ago
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!
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
Advertisement
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.
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?
Peon
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]
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
----------------(Inspired by Pouya)
Advertisement
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 firstLRESULT 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
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
Peon

This topic is closed to new replies.

Advertisement