Hi
I am using Dev Cpp for dos programming. I want to know how we can add classic style user interface to programs. The interface like in which we control the menus etc. through arrow keys not mouse. The interface like when we press F2 button at the start of computer.

Secondly, I want to ask how add controls in a program. Like if we press any key 'r' ex. it should respond not after hitting return but just by pressing 'r'.

Member Avatar for iamthwee

You mean like a win32 interface?

>>I am using Dev Cpp for dos programming
No you are not. MS-DOS died 10 years ago. What you mean is that you are doing console programming.

If you want nice looking gui menus and mouse support something like what you have in your browser then you have to learn win32 api programming, or use some C wrapper classes such as wxWindows libraries.

You can use mouse in console programs if you use the Microsoft console api functions. Click here

commented: Indeed it is. +18

I don't want to do win32 API. Also I don't want to add mouse controls.
See, restart your computer, quickly press F2 continously and you will go to a system setup screen (in which system time and all that is... ). See that interface. I want that one.

Also tell me how to add keyboard controls like if press a particular key like 'a' then it responds to that but without hitting return.

AncientDragon wrote...

No you are not. MS-DOS died 10 years ago.

Every year the organization for which I work sells 30 to 45 million dollars worth of timber. This timber is inventoried and tallied using data recorders running my various DOS PowerBASIC, QuickBasic or C programs. So its a pretty healthy corpse I'd say.

Below is just a quick and dirty Win32 Api program for the Dev C++ user. It can be pasted into a new code window in Dev C++ and compiled with either a .c or .cpp extension, I believe (just tested it with .cpp). There should be a couple files of this nature under the Dev C++ installation. I see I must have been experimenting with capturing the delete and/or alt delete key at some point in the past with this program, as it put up a message box when you hit those keys.

#include <windows.h>
#define IDC_BUTTON   WM_USER + 1

LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
 switch (msg)
 {
  case WM_CREATE:
    HINSTANCE hIns;
    HWND hButton;
    hIns=((LPCREATESTRUCT)lParam)->hInstance;
    hButton=
    CreateWindow
    (
     "button",
     "Click Me",
     WS_CHILD|WS_VISIBLE,
     70,60,150,30,
     hwnd,
     (HMENU)IDC_BUTTON,hIns,
     0
    );
    break;
  case WM_COMMAND:
    MessageBox(hwnd,"You Clicked The Button","Message",MB_OK);
    break;
  case WM_KEYDOWN:
    if(wParam==VK_DELETE)
       MessageBox(hwnd,"You Clicked The Delete Key!","Delete!",MB_OK);
    break;
  case WM_SYSKEYDOWN:
    if((lParam&0x20000000)&&wParam==VK_DELETE)
        MessageBox(hwnd,"Alt + Delete Key!","Delete!",MB_OK);
    break;
  case WM_DESTROY:
    PostQuitMessage (0);
    break;
  default:
    return DefWindowProc(hwnd,msg,wParam,lParam);
 }

 return 0;
}

int WINAPI WinMain(HINSTANCE hIns,HINSTANCE hPrevIns,LPSTR lpszArgument,int iShow)
{
 char szClassName[]="WindowsApp";
 WNDCLASSEX wincl; 
 MSG messages;
 HWND hWnd; 

 wincl.hInstance=hIns;
 wincl.lpszClassName=szClassName;
 wincl.lpfnWndProc=WndProc;
 wincl.style=CS_DBLCLKS;
 wincl.cbSize=sizeof (WNDCLASSEX);
 wincl.hIcon=LoadIcon(NULL,IDI_APPLICATION);
 wincl.hIconSm=LoadIcon(NULL, IDI_APPLICATION);
 wincl.hCursor=LoadCursor(NULL,IDC_ARROW);
 wincl.lpszMenuName=NULL;
 wincl.cbClsExtra=0;
 wincl.cbWndExtra=0;
 wincl.hbrBackground=(HBRUSH)COLOR_BACKGROUND;
 RegisterClassEx(&wincl);
 hWnd=
 CreateWindow
 (
  szClassName,
  "Windows App",
  WS_OVERLAPPEDWINDOW,
  200,100,300,215,
  HWND_DESKTOP,
  0,
  hIns,
  0
 );
 ShowWindow(hWnd,iShow);
 while(GetMessage(&messages,NULL,0,0))
 {
  TranslateMessage(&messages);
  DispatchMessage(&messages);
 }

 return messages.wParam;
}

Hye guys how many times I should tell that I don't want to add mouse controls or do Win 32 API. Plz!!!!!!!!!! help me.
Ancient Dragon can't you help me. I am expecting from you since you have nice reputation on this site.
Let me clear again I want an interface in which we navigate through options through arrow keys. Press F2 while restarting your PC and you will get me.
Dani Web is no.1 community on net, so do I have the right to expect to the point replies?
Help me!!!

> Every year the organization for which I work sells 30 to 45 million dollars worth of timber.
> This timber is inventoried and tallied using data recorders running my various DOS
> PowerBASIC, QuickBasic or C programs. So its a pretty healthy corpse I'd say.
Maybe so, but are you seriously suggesting that newbies learn this stuff, or that any new development would start from DOS?


@OP
If you want a terminal interface, then I suggest you look at ncurses
You might not be calling win32 directly, but if you use dev-c++ to compile your program, it will be a win32 console program, no matter what interface you choose to put between yourself and the OS.

If you're trying to write some boot-time code (and not just quoting the F2 thing as an example), then you'll need a different compiler.

> Every year the organization for which I work sells 30 to 45 million dollars worth of timber.
> This timber is inventoried and tallied using data recorders running my various DOS
> PowerBASIC, QuickBasic or C programs. So its a pretty healthy corpse I'd say.
Maybe so, but are you seriously suggesting that newbies learn this stuff, or that any new development would start from DOS?


@OP
If you want a terminal interface, then I suggest you look at ncurses
You might not be calling win32 directly, but if you use dev-c++ to compile your program, it will be a win32 console program, no matter what interface you choose to put between yourself and the OS.

If you're trying to write some boot-time code (and not just quoting the F2 thing as an example), then you'll need a different compiler.

Yes, this is exactly what I wanted. Thank you.....

The code below is a Win32 Console program I dug up for you. When it runs it displays the mouse x and mouse y positions on the 2nd line, and the ascii key codes on the 1st line. Run this once and see if it represents progress in the right direction. Note that it is possible to write full fledged 32 bit console programs that do many useful things, but it is a bit unusual. To do it you will have to study the console Api in great detail.

#include <windows.h>
#include <stdio.h>


void cls(HANDLE hConsole)
{
 CONSOLE_SCREEN_BUFFER_INFO csbi;
 COORD coordScreen = {0,0};
 DWORD cCharsWritten;
 DWORD dwConSize;
 BOOL bSuccess;

 GetConsoleScreenBufferInfo(hConsole,&csbi);
 dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
 FillConsoleOutputCharacter
 (
  hConsole,
  (TCHAR)' ',
  dwConSize,
  coordScreen,
  &cCharsWritten
 );
 GetConsoleScreenBufferInfo(hConsole,&csbi);
 FillConsoleOutputAttribute
 (
  hConsole, 
  csbi.wAttributes,
  dwConSize,
  coordScreen,
  &cCharsWritten
 );
 SetConsoleCursorPosition(hConsole,coordScreen);
 
 return;
}


int main(void)
{
 COORD xy,hv;
 BOOL bContinue=TRUE;
 DWORD dwInputEvents;
 HANDLE hStdOutput,hStdIn;
 INPUT_RECORD ir;

 hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
 hStdIn = GetStdHandle(STD_INPUT_HANDLE);
 cls(hStdOutput);
 xy.X=0;xy.Y=0;
 hv.X=0;hv.Y=0;
 SetConsoleCursorPosition(hStdOutput,xy);
 do
 {
   ReadConsoleInput(hStdIn,&ir,1,&dwInputEvents);
   switch(ir.EventType)
   {
    case KEY_EVENT:
      if(ir.Event.KeyEvent.wVirtualKeyCode==VK_ESCAPE)
      {
         cls(hStdOutput);
         bContinue=FALSE;
      }
      else
      {
        if(ir.Event.KeyEvent.bKeyDown==TRUE)
        {
           SetConsoleCursorPosition(hStdOutput,hv);
           printf
           (
            "Key Event: char=%c\tasci code=%u",
            ir.Event.KeyEvent.uChar.AsciiChar,
            ir.Event.KeyEvent.uChar.AsciiChar
           );
           hv.X=0,  hv.Y=0;
        }
      }
      break;
    case MOUSE_EVENT:
      xy.X=0;xy.Y=1;
      SetConsoleCursorPosition(hStdOutput,xy);
      printf
      (
       "Mouse X = %.3d: Mouse Y = %.3d", 
       ir.Event.MouseEvent.dwMousePosition.X,
       ir.Event.MouseEvent.dwMousePosition.Y
      );
      break;
    default:
      break;
   } 
 }while(bContinue==TRUE);
 
 return 0;
}

I know clearly what you want now. I'll dig up another example for you that is exactly what you want. I actually have a program just like that that creates a button with the asciiz character set with shadows and all, and when you push the button in with the mouse it 'clicks', etc. I know, Iknow, you don't want the mouse (but it isn't hard to add it). I'll find it somewhere.

I dug up this. Try a bunch of different keys. It prints a message for quite a lot of them. I didn't test it with Dev C++, cuz it appears I wrote it with MS Visual C++ 6.0. If it doesn't work I'll see what's wrong with it. I believe you end the program by either hitting [ESCAPE] or x'ing out.

#include <windows.h>
#include <stdio.h>

void cls( HANDLE hConsole )
{
 COORD coordScreen = {0,0};
 DWORD cCharsWritten;
 CONSOLE_SCREEN_BUFFER_INFO csbi;
 DWORD dwConSize;
 
 GetConsoleScreenBufferInfo(hConsole, &csbi);
 dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
 FillConsoleOutputCharacter(hConsole,(TCHAR)' ',
 dwConSize,coordScreen,&cCharsWritten);
 GetConsoleScreenBufferInfo( hConsole, &csbi);
 FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
 dwConSize, coordScreen, &cCharsWritten );
 SetConsoleCursorPosition( hConsole, coordScreen );
 
 return;
}

int main(void)
{
 COORD xy,hv;
 BOOL bContinue=TRUE;
 DWORD dwInputEvents;
 HANDLE hStdOutput,hStdIn;
 INPUT_RECORD ir;

 hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
 hStdIn = GetStdHandle(STD_INPUT_HANDLE);
 cls(hStdOutput);
 xy.X=0;xy.Y=0;
 hv.X=0;hv.Y=1;
 SetConsoleCursorPosition(hStdOutput,xy);
 do
 {
   ReadConsoleInput(hStdIn,&ir,1,&dwInputEvents);
   if(ir.EventType == KEY_EVENT)
   {
      if(ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)
      {
         printf("%u\t%u\n",VK_ESCAPE,ir.Event.KeyEvent.uChar.AsciiChar);
         break;
      }
      else
      {
         if(ir.Event.KeyEvent.bKeyDown==TRUE)
         {
            if(ir.Event.KeyEvent.dwControlKeyState & RIGHT_CTRL_PRESSED)
               printf("Right Control Key Pressed!\n");
            else
            { 
               switch(ir.Event.KeyEvent.wVirtualKeyCode)
               {
                  case VK_DELETE:
                    printf("%u\tYou Hit Delete!\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_INSERT:
                    printf("%u\tYou Hit Insert!\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_LEFT:
                    printf("%u\tYou Hit The Left Cursor Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_RIGHT:
                    printf("%u\tYou Hit The Right Cursor Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_UP:
                    printf("%u\tYou Hit The Up Cursor Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_DOWN:
                    printf("%u\tYou Hit The Down Cursor Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_NEXT:
                    printf("%u\tYou Hit The Page Down Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_PRIOR:
                    printf("%u\tYou Hit The Page Up Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_HOME:
                    printf("%u\tYou Hit The Home Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_END:
                    printf("%u\tYou Hit The End Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_F1:
                    printf("%u\tYou Hit F1\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_F2:
                    printf("%u\tYou Hit F2\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break; 
                  case VK_F3:
                    printf("%u\tYou Hit F3\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_F4:
                    printf("%u\tYou Hit F4\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;     
                  case VK_F5:
                    printf("%u\tYou Hit F5\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_F6:
                    printf("%u\tYou Hit F6\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break; 
                  case VK_F7:
                    printf("%u\tYou Hit F7\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_F8:
                    printf("%u\tYou Hit F8\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;  
                  case VK_F9:
                    printf("%u\tYou Hit F9\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_F10:
                    printf("%u\tYou Hit F10\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break; 
                  case VK_F11:
                    printf("%u\tYou Hit F11\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  case VK_F12:
                    printf("%u\tYou Hit F12\n",ir.Event.KeyEvent.wVirtualKeyCode);
                    break;
                  default:
                    printf("%u\t%c\t%u\n",ir.Event.KeyEvent.uChar.AsciiChar,ir.Event.KeyEvent.uChar.AsciiChar,ir.Event.KeyEvent.wVirtualKeyCode);
            
               }
            } 

         }
      }   
   }
 }while(TRUE);
 
 return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.