so im rebuilding a console app i made that basically has your password stored in a text file, you log on and can write you private document that no one else can read. you are able to change you password too. and im making a replica but as a windows app, i have got the logon screen made with a button and 2 textbox's. if you log on with the proper credentials, a msg box will appear saying "Succesfully Logged In!" and if not the a msg box saying "Wrong Username/Password". i was wondering how i can "Clear" the buttons off the screen if logged in properly. i know how to add more buttons after being logged in, but i need to get rid of the login button and 2 textbox's. i hope this made sence, this is my very first post. if requested i can post either source code.
Personally, I wouldn't do it like that. I feel that a log on screen/form/dialog should be a seperate screen from the one you get to that performs the main app's function. Therefore, I wouldn't code the app the way you suggest. I'd dismiss the log on screen after the user is done with it, then show the main work screen if the user successfully logged on.
The sample shows how to clear the console window (the name cls, clear screen, comes from the olden, DOS says). But the same functions, in particular FillConsoleOutputCharacter, could be used to clear specific bits of the screen as well.
thankyou, and sorry i was not specific enough. i used MessageBox, and CreateWindow for the textboxes and buttons. it is not a console app, rather a windows app. i need to remove/hide/delete the button and txtbox's off the window if the password and username are entered properly.
If i use ShowWindow to hide the controls, do you know what the downsides are from that?
If coded correctly, it should function well enough.
The downside is that the main window's window proceedure will have to handle the logon sequence is well, which is less elegant from a design point of view.
Ideally:
- the logon window should handle logon
- the main window whatever you app does when it's been successfully logged on
So what you need to do is register two seperate Window Classes, i.e., one for your log on dialog, and one for your main app. This will require two seperate Window Procedures.
There I teach how to create multiple forms/windows/dialogs in the same program. Actually, starting with Reply #1 at that link wouldn't hurt you, as its all about the same material.
Basically, as Andy said, each form/window/dialog has a job to do, and the Window Procedure of that module should be geared to responding to events related to that job. For example, your Log On screen will have a text box and button perhaps which is related to the job of logging in. Your Main App screen has a different job.
In terms of program organization, you can have a Main.cpp and Main.h file which basically has program initialization and WinMain, then you can have seperate *.cpp and *.h files for the various windows/dialogs/forms your program needs. My example I gave links to above shows that.
Usually what I do is Register my main program window in WinMain(), then register other Window Classes my program needs in the WM_CREATE handler of my main program window. Once a Window Class has been registered, you can create windows of that class anywhere in your code with CreateWindowEx() calls.