Re: I want to get rid of a beep
On Sun, 15 Jul 2007 22:28:12 +0200, Eric Lilja
<mindcoolerremoveme@gmail.com> wrote:
Well, how am I supposed to specify its size then? When I look at the
resource files, what do I see there? Hardwired numbers.
Those numbers are different:
1. They are expressed in dialog units, which are translated to pixels at
runtime based on the font used in the dialog.
2. The controls were sized visually using the dialog editor.
The reason I'm
not placing a normal CEdit using the resource editor is because I wanted
it to perform an action when enter is pressed while it has input focus.
You can bind objects of your own classes to CEdit controls you add in the
resource editor. I know the VC6 ClassWizard let you do this directly. I'm
not sure offhand if this was one of the things lost in VC.NET, but
hopefully it still allows you to choose any class derived from CEdit. If
not, you can add a CEdit member variable and hand-edit it to be your class
name.
Sometimes, you do need to create controls at runtime, and instead of
hardwiring numbers, a common trick is to add a static control of the
desired size in the resource editor, do a GetWindowRect on it in
OnInitDialog, create your window with this position and size, move it just
after the static control in the Z-order with SetWindowPos, and then delete
the static control. You will have to give the static control a unique ID,
because by default, they are all set to IDC_STATIC. This "placeholder"
technique is easy and effective, and it removes all the guesswork and
tedious calculations with dialog units.
--
Doug Harrison
Visual C++ MVP