Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Beginner VC++ Programmer : Dialog Box Problem. Pls Help

Status
Not open for further replies.

cdgios

Technical User
Jul 17, 2002
40
US
Hello, I have a dialog box with a list box control and a bunch of edit box controls. When i excute the application, the dialog box shows up. But when the i try selecting an item from a list box and just happen to click any of the edit controls, the dialog box disappers. I have several other similar dialog boxes in my application which work just fine. Could you help me debug this problem.

Thanks a bunch
Best Regards
Chandra
 
I want to add, I have situation where, in the dialog procedure, I am writing to an edit control on the dialog box as follows,

1. wsprintf (szBuffer, TEXT ("%d"), 0) ;
2. SendDlgItemMessage (hdlg, IDC_EDIT_00, WM_SETTEXT, 0,
(LPARAM) (LPSTR) szBuffer) ;
Now for some reason, The presence of "2" causes the dialog box to not appear when i execute the program. When i comment out "2", the dialog box appears. Now i am pretty sure that i have used the function SendDlgItemMessage () correctly (I have used it several other places and it works fine).

Could you help me understand what the problem is.

Thanks
Best Regards
Chandra
 
I want to add that, I have modified the resource script (.RC) and the resource.h files outside the VC++ editor (i.e. through note pad). Esentially i changed the sizes and positions of some controls on the dialog box. I also removed some unused ID's from the resource.h.
Can this cause any problem. I can't think of a logical reason why it should. More over i have done such changes before without a problem.

Thanks
Best Regards
Chandra
 
Chandra, If you're using Visual C++ I can't understand why you're doing things the hard way??????????? This is probably why you're getting errors, etc. - you should let VC++ handle all that behind-the-scenes technical stuff.

Create a dialog in the resource editor. Add an edit control to it. In the class wizard, give the edit control a member variable and a name (eg. m_myEditCtrl).

If you want to set the text in the edit control before the dialog is displayed, use class wizard to add a member function for the dialog which responds to the WM_INITDIALOG message. In that function, you can use:

m_myEditCtrl.SetWindowText("Hello World");

to set the text before the dialog is seen.

You can use the same method to set the text in the edit control at any time. To retrieve the text from the edit control at any time, simply use:

CString myString;
m_myEditCtrl.GetWindowText(myString);

the text from the edit control is now stored in 'myString'.

You can treat edit controls and buttons and other controls just like CWnd objects (because they are all derived from CWnd). Therefore, you can use the methods:

ShowWindow();
MoveWindow();

etc, etc, etc, to set the position and state of the controls. For example,

m_myEditCtrl.MoveWindow(0,0,50,20,TRUE);

will move your edit box to the top left corner of your dialog. It will be 50 pixels wide and 20 tall.

Chandra, if you're using VC++ you should take advantage of the fact and let VC++ do all the hard niggly work for you wherever possible. That's the whole point of using VC++ - to make programmer's lives easier so it leaves you more time to do the fun stuff that sets your app apart from everyone elses.
 
PS: It looks to me like you've been reading some kind of C/C++ book that deals with the language in general. That's fine as it is obviously important for you to understand the basis of the language and what makes things tick.
However, going back to what I said above, I think you should take time out to read through a book such as 'Sams Teach Yourself Visual C++ 6 in 24 hours' or similar. This book will show you how to create dialogs, edit controls, tree controls, menus and almost everything you need to know from a complete beginners perspective.
 
Chandra, are you using the MFC library? If not, you should check the dialog-function. Normally, you write something like:

[tt]switch (message)
{
case ID_...:
...
case ID_...:
EndDialog(...);
}[/tt]

Do you call EndDialog() on the wrong event (= wrong ID_...)?

BTW, I prefer not to use the MFC library for small projects. In my eyes it's overhead. I would use MFC for greater projects such as MDI apps.

CIAO!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top