32 Replies - 1310 Views - Last Post: 02 October 2012 - 07:57 PM
#1
question: How do I implement a basic CUI in c++?
Posted 28 September 2012 - 07:56 PM
Also,
How can I change the background of the output screen? Do i need to use graphics.h?
How can I continuously read input from the user without the need to wait for the return key to be pressed?
How to read backspace character?
Replies To: question: How do I implement a basic CUI in c++?
#2
Re: question: How do I implement a basic CUI in c++?
Posted 28 September 2012 - 10:33 PM
So, which OS and compiler are you using?
#3
Re: question: How do I implement a basic CUI in c++?
Posted 29 September 2012 - 01:58 AM
#4
Re: question: How do I implement a basic CUI in c++?
Posted 29 September 2012 - 02:40 AM
...
> Turbo c++
TC++ isn't even close to being compliant to C++98.
#5
Re: question: How do I implement a basic CUI in c++?
Posted 29 September 2012 - 01:29 PM
is this of any help?
http://www.programme...8/Download.aspx
#6
Re: question: How do I implement a basic CUI in c++?
Posted 29 September 2012 - 09:47 PM
Ticon, on 29 September 2012 - 01:29 PM, said:
is this of any help?
http://www.programme...8/Download.aspx
It'd be great if I could do that. The problem is the the program should run with turbo c++. I am using c free standard for all my needs, using a Borland c++ compiler. Graphics doesn't work with this. I also tried changing the text colour and the background, but it just simple does not work.
#7
Re: question: How do I implement a basic CUI in c++?
Posted 29 September 2012 - 10:13 PM
#include <windows.h>
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Code::Blocks Template Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
Regards
Snoopy.
#8
Re: question: How do I implement a basic CUI in c++?
Posted 30 September 2012 - 12:10 AM
Trust me, your tutor can't tell the difference between a language standard and a barrel of bricks. Unfortunately, it's you that will be feeling all the pain when you get out into the real world, and find that all the stuff you've been taught is useless (and all the years of wasted opportunity).
Download a modern compiler (visual studio, code::blocks, pelles-c) and get some decent books:
http://www.dreaminco...338-books-on-c/
Use this to learn something useful (in your own time).
The diploma at the end of your course is barely good enough to open the door for your first job. You'll need something else to be able to keep that job.
> How can I change the background of the output screen? Do i need to use graphics.h?
http://www.programmi...nio.h/textcolor
> How can I continuously read input from the user without the need to wait for the return key to be pressed?
Try getch();
> How to read backspace character?
Try getch();
Have you ever opened conio.h in your text editor and read through all the functions it offers?
#9
Re: question: How do I implement a basic CUI in c++?
Posted 01 October 2012 - 09:10 PM
Salem_c, on 30 September 2012 - 12:10 AM, said:
Trust me, your tutor can't tell the difference between a language standard and a barrel of bricks. Unfortunately, it's you that will be feeling all the pain when you get out into the real world, and find that all the stuff you've been taught is useless (and all the years of wasted opportunity).
Download a modern compiler (visual studio, code::blocks, pelles-c) and get some decent books:
http://www.dreaminco...338-books-on-c/
Use this to learn something useful (in your own time).
The diploma at the end of your course is barely good enough to open the door for your first job. You'll need something else to be able to keep that job.
> How can I change the background of the output screen? Do i need to use graphics.h?
http://www.programmi...nio.h/textcolor
> How can I continuously read input from the user without the need to wait for the return key to be pressed?
Try getch();
> How to read backspace character?
Try getch();
Have you ever opened conio.h in your text editor and read through all the functions it offers?
Actually I know about some of the functions in conio but not really found the need to use them till now.
#10
Re: question: How do I implement a basic CUI in c++?
Posted 01 October 2012 - 09:22 PM
#11
Re: question: How do I implement a basic CUI in c++?
Posted 01 October 2012 - 10:36 PM
#12
Re: question: How do I implement a basic CUI in c++?
Posted 01 October 2012 - 10:46 PM
#13
Re: question: How do I implement a basic CUI in c++?
Posted 01 October 2012 - 11:42 PM
I threw out my Turbo C manuals long ago, but as I recall, kbhit() will return non-zero as long as there is something in the keyboard buffer, including pending backspace keypresses.
This post has been edited by Skydiver: 01 October 2012 - 11:42 PM
#14
Re: question: How do I implement a basic CUI in c++?
Posted 01 October 2012 - 11:58 PM
Next is the backspace
#15
Re: question: How do I implement a basic CUI in c++?
Posted 02 October 2012 - 02:10 AM
And yes, kbhit() returns non-zero value if there is anything in the buffer to read.
|
|

New Topic/Question
Reply



MultiQuote





|