954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Win32 - Controls on main window

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 ?

bops
Posting Whiz in Training
214 posts since Aug 2005
Reputation Points: 23
Solved Threads: 5
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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 ?

bops
Posting Whiz in Training
214 posts since Aug 2005
Reputation Points: 23
Solved Threads: 5
 

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...
bops
Posting Whiz in Training
214 posts since Aug 2005
Reputation Points: 23
Solved Threads: 5
 

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.

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 
.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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 
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.

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

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.

bops
Posting Whiz in Training
214 posts since Aug 2005
Reputation Points: 23
Solved Threads: 5
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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?

bops
Posting Whiz in Training
214 posts since Aug 2005
Reputation Points: 23
Solved Threads: 5
 

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);
Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You