943,867 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 994
  • C++ RSS
Jul 16th, 2008
0

Interface in DOS

Expand Post »
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'.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rishabh2011 is offline Offline
8 posts
since Jun 2008
Jul 16th, 2008
0

Re: Interface in DOS

You mean like a win32 interface?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 16th, 2008
-1

Re: Interface in DOS

>>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
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005
Jul 16th, 2008
0

Re: Interface in DOS

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rishabh2011 is offline Offline
8 posts
since Jun 2008
Jul 16th, 2008
0

Re: Interface in DOS

AncientDragon wrote...

Quote ...
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.

  1. #include <windows.h>
  2. #define IDC_BUTTON WM_USER + 1
  3.  
  4. LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  5. {
  6. switch (msg)
  7. {
  8. case WM_CREATE:
  9. HINSTANCE hIns;
  10. HWND hButton;
  11. hIns=((LPCREATESTRUCT)lParam)->hInstance;
  12. hButton=
  13. CreateWindow
  14. (
  15. "button",
  16. "Click Me",
  17. WS_CHILD|WS_VISIBLE,
  18. 70,60,150,30,
  19. hwnd,
  20. (HMENU)IDC_BUTTON,hIns,
  21. 0
  22. );
  23. break;
  24. case WM_COMMAND:
  25. MessageBox(hwnd,"You Clicked The Button","Message",MB_OK);
  26. break;
  27. case WM_KEYDOWN:
  28. if(wParam==VK_DELETE)
  29. MessageBox(hwnd,"You Clicked The Delete Key!","Delete!",MB_OK);
  30. break;
  31. case WM_SYSKEYDOWN:
  32. if((lParam&0x20000000)&&wParam==VK_DELETE)
  33. MessageBox(hwnd,"Alt + Delete Key!","Delete!",MB_OK);
  34. break;
  35. case WM_DESTROY:
  36. PostQuitMessage (0);
  37. break;
  38. default:
  39. return DefWindowProc(hwnd,msg,wParam,lParam);
  40. }
  41.  
  42. return 0;
  43. }
  44.  
  45. int WINAPI WinMain(HINSTANCE hIns,HINSTANCE hPrevIns,LPSTR lpszArgument,int iShow)
  46. {
  47. char szClassName[]="WindowsApp";
  48. WNDCLASSEX wincl;
  49. MSG messages;
  50. HWND hWnd;
  51.  
  52. wincl.hInstance=hIns;
  53. wincl.lpszClassName=szClassName;
  54. wincl.lpfnWndProc=WndProc;
  55. wincl.style=CS_DBLCLKS;
  56. wincl.cbSize=sizeof (WNDCLASSEX);
  57. wincl.hIcon=LoadIcon(NULL,IDI_APPLICATION);
  58. wincl.hIconSm=LoadIcon(NULL, IDI_APPLICATION);
  59. wincl.hCursor=LoadCursor(NULL,IDC_ARROW);
  60. wincl.lpszMenuName=NULL;
  61. wincl.cbClsExtra=0;
  62. wincl.cbWndExtra=0;
  63. wincl.hbrBackground=(HBRUSH)COLOR_BACKGROUND;
  64. RegisterClassEx(&wincl);
  65. hWnd=
  66. CreateWindow
  67. (
  68. szClassName,
  69. "Windows App",
  70. WS_OVERLAPPEDWINDOW,
  71. 200,100,300,215,
  72. HWND_DESKTOP,
  73. 0,
  74. hIns,
  75. 0
  76. );
  77. ShowWindow(hWnd,iShow);
  78. while(GetMessage(&messages,NULL,0,0))
  79. {
  80. TranslateMessage(&messages);
  81. DispatchMessage(&messages);
  82. }
  83.  
  84. return messages.wParam;
  85. }
Reputation Points: 244
Solved Threads: 31
Posting Whiz
Frederick2 is offline Offline
330 posts
since Jul 2008
Jul 16th, 2008
0

Re: Interface in DOS

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!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rishabh2011 is offline Offline
8 posts
since Jun 2008
Jul 16th, 2008
0

Re: Interface in DOS

> 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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jul 16th, 2008
0

Re: Interface in DOS

Click to Expand / Collapse  Quote originally posted by Salem ...
> 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.....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rishabh2011 is offline Offline
8 posts
since Jun 2008
Jul 16th, 2008
0

Re: Interface in DOS

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.

  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4.  
  5. void cls(HANDLE hConsole)
  6. {
  7. CONSOLE_SCREEN_BUFFER_INFO csbi;
  8. COORD coordScreen = {0,0};
  9. DWORD cCharsWritten;
  10. DWORD dwConSize;
  11. BOOL bSuccess;
  12.  
  13. GetConsoleScreenBufferInfo(hConsole,&csbi);
  14. dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
  15. FillConsoleOutputCharacter
  16. (
  17. hConsole,
  18. (TCHAR)' ',
  19. dwConSize,
  20. coordScreen,
  21. &cCharsWritten
  22. );
  23. GetConsoleScreenBufferInfo(hConsole,&csbi);
  24. FillConsoleOutputAttribute
  25. (
  26. hConsole,
  27. csbi.wAttributes,
  28. dwConSize,
  29. coordScreen,
  30. &cCharsWritten
  31. );
  32. SetConsoleCursorPosition(hConsole,coordScreen);
  33.  
  34. return;
  35. }
  36.  
  37.  
  38. int main(void)
  39. {
  40. COORD xy,hv;
  41. BOOL bContinue=TRUE;
  42. DWORD dwInputEvents;
  43. HANDLE hStdOutput,hStdIn;
  44. INPUT_RECORD ir;
  45.  
  46. hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  47. hStdIn = GetStdHandle(STD_INPUT_HANDLE);
  48. cls(hStdOutput);
  49. xy.X=0;xy.Y=0;
  50. hv.X=0;hv.Y=0;
  51. SetConsoleCursorPosition(hStdOutput,xy);
  52. do
  53. {
  54. ReadConsoleInput(hStdIn,&ir,1,&dwInputEvents);
  55. switch(ir.EventType)
  56. {
  57. case KEY_EVENT:
  58. if(ir.Event.KeyEvent.wVirtualKeyCode==VK_ESCAPE)
  59. {
  60. cls(hStdOutput);
  61. bContinue=FALSE;
  62. }
  63. else
  64. {
  65. if(ir.Event.KeyEvent.bKeyDown==TRUE)
  66. {
  67. SetConsoleCursorPosition(hStdOutput,hv);
  68. printf
  69. (
  70. "Key Event: char=%c\tasci code=%u",
  71. ir.Event.KeyEvent.uChar.AsciiChar,
  72. ir.Event.KeyEvent.uChar.AsciiChar
  73. );
  74. hv.X=0, hv.Y=0;
  75. }
  76. }
  77. break;
  78. case MOUSE_EVENT:
  79. xy.X=0;xy.Y=1;
  80. SetConsoleCursorPosition(hStdOutput,xy);
  81. printf
  82. (
  83. "Mouse X = %.3d: Mouse Y = %.3d",
  84. ir.Event.MouseEvent.dwMousePosition.X,
  85. ir.Event.MouseEvent.dwMousePosition.Y
  86. );
  87. break;
  88. default:
  89. break;
  90. }
  91. }while(bContinue==TRUE);
  92.  
  93. return 0;
  94. }

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.
Last edited by Frederick2; Jul 16th, 2008 at 2:09 pm.
Reputation Points: 244
Solved Threads: 31
Posting Whiz
Frederick2 is offline Offline
330 posts
since Jul 2008
Jul 16th, 2008
0

Re: Interface in DOS

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.

  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. void cls( HANDLE hConsole )
  5. {
  6. COORD coordScreen = {0,0};
  7. DWORD cCharsWritten;
  8. CONSOLE_SCREEN_BUFFER_INFO csbi;
  9. DWORD dwConSize;
  10.  
  11. GetConsoleScreenBufferInfo(hConsole, &csbi);
  12. dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
  13. FillConsoleOutputCharacter(hConsole,(TCHAR)' ',
  14. dwConSize,coordScreen,&cCharsWritten);
  15. GetConsoleScreenBufferInfo( hConsole, &csbi);
  16. FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
  17. dwConSize, coordScreen, &cCharsWritten );
  18. SetConsoleCursorPosition( hConsole, coordScreen );
  19.  
  20. return;
  21. }
  22.  
  23. int main(void)
  24. {
  25. COORD xy,hv;
  26. BOOL bContinue=TRUE;
  27. DWORD dwInputEvents;
  28. HANDLE hStdOutput,hStdIn;
  29. INPUT_RECORD ir;
  30.  
  31. hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  32. hStdIn = GetStdHandle(STD_INPUT_HANDLE);
  33. cls(hStdOutput);
  34. xy.X=0;xy.Y=0;
  35. hv.X=0;hv.Y=1;
  36. SetConsoleCursorPosition(hStdOutput,xy);
  37. do
  38. {
  39. ReadConsoleInput(hStdIn,&ir,1,&dwInputEvents);
  40. if(ir.EventType == KEY_EVENT)
  41. {
  42. if(ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)
  43. {
  44. printf("%u\t%u\n",VK_ESCAPE,ir.Event.KeyEvent.uChar.AsciiChar);
  45. break;
  46. }
  47. else
  48. {
  49. if(ir.Event.KeyEvent.bKeyDown==TRUE)
  50. {
  51. if(ir.Event.KeyEvent.dwControlKeyState & RIGHT_CTRL_PRESSED)
  52. printf("Right Control Key Pressed!\n");
  53. else
  54. {
  55. switch(ir.Event.KeyEvent.wVirtualKeyCode)
  56. {
  57. case VK_DELETE:
  58. printf("%u\tYou Hit Delete!\n",ir.Event.KeyEvent.wVirtualKeyCode);
  59. break;
  60. case VK_INSERT:
  61. printf("%u\tYou Hit Insert!\n",ir.Event.KeyEvent.wVirtualKeyCode);
  62. break;
  63. case VK_LEFT:
  64. printf("%u\tYou Hit The Left Cursor Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
  65. break;
  66. case VK_RIGHT:
  67. printf("%u\tYou Hit The Right Cursor Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
  68. break;
  69. case VK_UP:
  70. printf("%u\tYou Hit The Up Cursor Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
  71. break;
  72. case VK_DOWN:
  73. printf("%u\tYou Hit The Down Cursor Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
  74. break;
  75. case VK_NEXT:
  76. printf("%u\tYou Hit The Page Down Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
  77. break;
  78. case VK_PRIOR:
  79. printf("%u\tYou Hit The Page Up Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
  80. break;
  81. case VK_HOME:
  82. printf("%u\tYou Hit The Home Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
  83. break;
  84. case VK_END:
  85. printf("%u\tYou Hit The End Key!\n",ir.Event.KeyEvent.wVirtualKeyCode);
  86. break;
  87. case VK_F1:
  88. printf("%u\tYou Hit F1\n",ir.Event.KeyEvent.wVirtualKeyCode);
  89. break;
  90. case VK_F2:
  91. printf("%u\tYou Hit F2\n",ir.Event.KeyEvent.wVirtualKeyCode);
  92. break;
  93. case VK_F3:
  94. printf("%u\tYou Hit F3\n",ir.Event.KeyEvent.wVirtualKeyCode);
  95. break;
  96. case VK_F4:
  97. printf("%u\tYou Hit F4\n",ir.Event.KeyEvent.wVirtualKeyCode);
  98. break;
  99. case VK_F5:
  100. printf("%u\tYou Hit F5\n",ir.Event.KeyEvent.wVirtualKeyCode);
  101. break;
  102. case VK_F6:
  103. printf("%u\tYou Hit F6\n",ir.Event.KeyEvent.wVirtualKeyCode);
  104. break;
  105. case VK_F7:
  106. printf("%u\tYou Hit F7\n",ir.Event.KeyEvent.wVirtualKeyCode);
  107. break;
  108. case VK_F8:
  109. printf("%u\tYou Hit F8\n",ir.Event.KeyEvent.wVirtualKeyCode);
  110. break;
  111. case VK_F9:
  112. printf("%u\tYou Hit F9\n",ir.Event.KeyEvent.wVirtualKeyCode);
  113. break;
  114. case VK_F10:
  115. printf("%u\tYou Hit F10\n",ir.Event.KeyEvent.wVirtualKeyCode);
  116. break;
  117. case VK_F11:
  118. printf("%u\tYou Hit F11\n",ir.Event.KeyEvent.wVirtualKeyCode);
  119. break;
  120. case VK_F12:
  121. printf("%u\tYou Hit F12\n",ir.Event.KeyEvent.wVirtualKeyCode);
  122. break;
  123. default:
  124. printf("%u\t%c\t%u\n",ir.Event.KeyEvent.uChar.AsciiChar,ir.Event.KeyEvent.uChar.AsciiChar,ir.Event.KeyEvent.wVirtualKeyCode);
  125.  
  126. }
  127. }
  128.  
  129. }
  130. }
  131. }
  132. }while(TRUE);
  133.  
  134. return 0;
  135. }
Reputation Points: 244
Solved Threads: 31
Posting Whiz
Frederick2 is offline Offline
330 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to optimize this function(about pattern match,A problem in a Interview)
Next Thread in C++ Forum Timeline: Arrays and Bitwise





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC