Hi, I have recently started windows programming in C/C++, I understand most of it, but 1 thing i cant find out how to do is to put controls on the main window of the application, not in a popup dialog box...can anyone give me any tips on how to do this ? thanks in advance ?

during the window's initialization, use the control's Create function, in which you specify the parent HWND, RECT containing the location and height, and the control's ID, among other things. The instance object of the control must NOT be local to a function, but global in the c++ class or program file in which it is used because it must stay in scope during the lifetime of the window.

Thanks, that makes a lot of sense lol...I will give that a go...is there any way of specifying the design of the window in the resource file in the way you can design your dialog box and menus etc ?

Oh also, do you have any good links on where I can get lists of styles etc for dialog boxes (Im not sure what they are called) and all fo the other kinds of controls etc for example...

DS_MODALFRAME | WS_POPUP | WS_CAPTION |  WS_SYSMENU
MB_OK | MB_ICONERROR
//and lots more...

well, if the number of controls is small, using global variables is okay. but i prefer to create them locally inside the create function and then use GetDialogItem API to get the handles of the controls when i need them. this eliminates the need of global window handles and makes the program less messy.

the best site regarding the apis is the msdn site itself.
Individual Controls
dialogs
The list of values can be obtained in CreateWindow

as for specyfing the design of the window like a dialog box, i have found a way to do that yet using a resource editor.

.is there any way of specifying the design of the window in the resource file in the way you can design your dialog box and menus etc ?

use CFormView instead of CView and the view will look and act like a dialog box -- and you can design it like one too.

as for specyfing the design of the window like a dialog box, i have found a way to do that yet using a resource editor.

I meant i have NOT found a way to do that yet. at least not in pure win32.

Hello again guys, I am having a lot of trouble simply setting the properties of controls on a dialog box, for example setting a command button to enabled and disabled, i have spent hours on msdn looking for ways of doing this but i still manage to get confused....also what is CView and CFormView and do you have any links to download a free decent resource editor? thanks.

CView and CFormView are MFC c++ classes. But you need to use VC++ 6.0 or newer to use them. Call the win32 api function EnableWindow() to enable and disable buttons and most other windows too.

oh i see, i have tried all kinds of ways including enablewindow(); function, could you give me an example on using it to disable a command button please?

very simple -- if you have the HWND of the button

// m_hWnd is the handle of the dialog
HWND hWhd =  GetdlgItem(m_hWnd,IDC_BUTTON1);
EnableWindow(hWnd,FALSE);
This article has been dead for over six months. Start a new discussion instead.