|
Hello
I am a beginner in c(win32 console). I want to define arrow keys in c in order to a character travels up, down, left and right.
PLEASE EXPLAIN AS COMPLETE AS POSSIBLE...
thanks all
|
|
|
|
|
See my answer to your other question.
It's time for a new signature.
|
|
|
|
|
hasani2007 wrote: I want to define arrow keys in c in order to a character travels up, down, left and right.
I could easily give you the numbers, but it would be of more benefit to you to create a little test program that uses getch() to get those keys (and others) and print their values to the screen. You can then use those values in your program.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
How to define arrow keys in c.
1. Define keys.
2. Put kbhit() in a function.
3. Create a loop.
4. Thats it.
Step 1.
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
Step 2.
void pumpKeyboardMessages(void)
{
if (kbhit())
{
ch=getch();
}
}
Step 3.
while (ch!=ESCAPE)
{
pumpKeyboardMessages( );
}
Step 4.
Here's an example of usage:
#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define SPACE 32
#define ENTER 13
#define ESCAPE 27
#define TAB 9
#define INSERT 82
#define F1 59
void pumpKeyboardMessages(void)
{
if (kbhit())
{
ch=getch();
switch (ch)
{
case LEFT:
break;
case RIGHT:
break;
case UP:
break;
case DOWN:
break;
case ENTER:
break;
case SPACE:
break;
case F1:
break;
case TAB:
break;
}
}
}
int main(void)
{
getReady();
initGame();
bas=time(0)+1;
while (ch!=ESCAPE)
{
pumpKeyboardMessages( );
}
return 0;
}
Also check out my articles about console applications.
How to create a Win32 Console Mode breakout brick game
How to create a Win32 Console Mode breakout brick game
How to create an object oriented Win32 Console application
How to create an object oriented Win32 Console application
How to handle mouse events in a Win32 Console in C++ with Random Joke Generator
How to handle mouse events in a Win32 Console in C++ with Random Joke Generator
|
|
|
|
|
Hi all friends;
I am a beginner in c(win32 console). I want to change the colour of characters & background in c. How to do it?
PLEASE EXPLAIN AS COMPLETE AS POSSIBLE...
Thanks all.
|
|
|
|
|
hasani2007 wrote: PLEASE EXPLAIN AS COMPLETE AS POSSIBLE...
1. Read the guidelines[^] before posting a question.
2. Do not use capitals to emphasise, it is considered bad manners.
3. Do not make demands for full explanations/code. People will give what they can without being prompted.
4. Learn to use Google, Bing and MSDN to do your own research first.
This link[^] has some suggestions to get what you want.
It's time for a new signature.
|
|
|
|
|
hasani2007 wrote: I want to change the colour of characters & background in c.
Check out SetConsoleTextAttribute() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
What about documentation: "Using Console (Windows)"?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hello all;
I'm a beginner in c. I should program a game(it's maze).
So I am dealing with this problem that can't get the walls from input.
because user should be able to put the walls by using an array.
Apologise me because bad English writing.
|
|
|
|
|
 For example, this code generates a random maze. Its a console application
#include <iostream.h>
#include <conio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
system("color 1F");
int rows,columns,r,k;
int center,c;
int random_it;
char someCharacter;
char lgt1='\xB3';
char lgt3='\xBF';
char lgt10='\xD9';
srand(time(0));
cout<<"Maze generator ver 0.000000000001 beta \n\n";
cout<<"Input columns (x) > ";
cin>>columns;
cout<<"Input rows (y) > ";
cin>>rows;
center=38-(columns/2);
cout<<'\n';
for (r=0;r<rows;r++)
{
for (c=0;c<center;c++) cout<<" ";
for(k=0;k<columns;k++)
{
random_it=rand() % 20;
if (random_it==0) someCharacter=random_it+lgt1;
if (random_it==1) someCharacter=random_it+lgt1;
if (random_it==2) someCharacter=random_it+lgt3-2;
if (random_it==3) someCharacter=random_it+lgt3-2;
if (random_it==4) someCharacter=random_it+lgt3-2;
if (random_it==5) someCharacter=random_it+lgt3-2;
if (random_it==6) someCharacter=random_it+lgt3-2;
if (random_it==7) someCharacter=random_it+lgt3-2;
if (random_it==8) someCharacter=random_it+lgt3-2;
if (random_it==9) someCharacter=random_it+lgt10-9;
if (random_it==10) someCharacter=random_it+lgt10-9;
if (random_it>10) someCharacter='\x20';
cout<<(char)someCharacter;
}
cout<<"\n";
}
cout<<"\n";
return 0;
}
...
|
|
|
|
|
First, I am writing everything in C using Visual C++ 6.0
Second, I have created a dialog box that contains an edit box located inside a dialog box and I cannot seem to find a way to change the font size of the edit (text) box. It's basically a user id window, but it's defaulting to a small font.
I can set the text inside of the box just fine:
SetWindowText ( GetDlgItem ( window, IDC_ID_WINDOW ), (char)current_id_string_g ) ;
but the font is small =(
any ideas of how to change the font size of a particular edit box?
Thanks
|
|
|
|
|
pjdriverdude wrote: any ideas of how to change the font size of a particular edit box?
Send it a WM_SETFONT message, perhaps?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Huzzah! You led me down the right path. Here's the code to changes an edit box font (at least, this works fine for me).
HFONT hFont ;
HWND x = GetDlgItem(window, IDC_ID_WINDOW) ;
HDC hdc = GetDC ( x ) ;
hFont = CreateFont(48,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, VARIABLE_PITCH,TEXT("Impact"));
SelectObject(hdc, hFont);
SendMessage( x, WM_SETFONT, (WPARAM) hFont, MAKELPARAM(0, 0) );
(void) UpdateWindow(window) ;
|
|
|
|
|
I an handling the CTLCOLOR_EDIT message in the OnCtlColor() to change the background color of Edit Box.But I am having two edit boxes IDC_EDIT1 and IDC_EDIT2.I want edit1 to be blue and edit2 to be red. How I will know the source of the CTLCOLOR_EDIT message?
|
|
|
|
|
chikach wrote: How I will know the source of the CTLCOLOR_EDIT message?
The second parameter.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
thank you 
|
|
|
|
|
Hi ,
I need to insert PNG image in MFC dialog . I tried with picture box not helpful , as you know BMP can be achieved , but PNG I am difficulty to insert . Googled , not able to screw it . Kindly give your suggestion .
Thanks,
Tam
www.tamilselvan.zoomshare.com
|
|
|
|
|
Maybe some the the replies in this[^] thread will help.
|
|
|
|
|
hi,
below is the code , picture is not getting displayed .
CPic::CPic(CWnd* pParent /*=NULL*/)
: CDialog(CPic::IDD, pParent)
{
/*CString csfilename;
csfilename.Format("C:\\warningIcon.png");*/
image.Load(_T("C:\\warningIcon"));
}
CPic::~CPic()
{
}
void CPic::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
void CPic::OnPaint()
{
image.Load(_T("C:\\warningIcon"));
/*PAINTSTRUCT ps;
CDC * drawDC = BeginPaint(&ps);
CRect rcClient;
GetClientRect(&rcClient);
image_.TransparentBlt(*drawDC, rcClient, CRect(0, 0, image_.GetWidth(), image_.GetHeight()), image_.GetPixel(0, 0));
EndPaint(&ps);*/
}
www.tamilselvan.zoomshare.com
|
|
|
|
|
Hi
I'm trying to write my own debugger I have
most the kinks squared away with the exception
of a few namely I am trying to re-create the
yellow arrow which follows you along when you step
through code
1) I was not quite sure if it's a function of a cursor
or a owner draw control
I had code to manipulate the cursor ::onsetcursor
which I had gotten to position the cursor
however when I added code for a custom
cursor LoadCursor(..... ".cur")
I followed all the steps putting in my resource file
then Setcursor after Load got all good return codes
but my new yellow cursor failed to appear
I am looking for some insight if I am on the correct path
Rhankx
|
|
|
|
|
if i had to guess, i'd say it's just a bitmap they draw on the editor window at the appropriate spot - neither cursor nor custom control.
|
|
|
|
|
Yeah you are probably right doesn't fit into any of the predefined windows class
I guess if you have a white rectangular background for the arrow you van use bitblt to move it along
|
|
|
|
|
This is a tough one. I have a process running in a console that sometimes "freezes" when trying to read data from serial port (or USB).
The issue only happens if the console does not have focus. If i click on the console so it has focus, the serial data starts coming in again. If the console has focus all the time, the issue never occurs.
It doesn't look like console focus can be detected with SetConsoleCtrlHandler or SetConsoleMode so the question is...
How can a console having focus effect serial port I/O? It doesn't look like a timing issue with console output messages.
|
|
|
|
|
Hi,
No idea if any of this lot is any good, but here are some things I'd try in the same situation:
- Does the slowdown happen with a /subsystem:windows application as well as a console one? If it does then it might be due to threads changing priority when an application is minimised.
- Is your serial I/O code in it's own thread? Normally I wouldn't advocate spinning off threads wily nilly but if the I/O is in it's own thread you don't have to worry about the UI thread being blocked in a message loop somewhere and not able to read from the serial port.
- Does the same thing happen if you run the app as an administrator or ordinary user? If it does there might be a security problem.
- Is there anything else that might be interfering with the serial I/O? Is the COMM port used for anything else or have you several devices on the same USB hub?
Anyway, hope that's not a complete waste of time and there's something in there that might help you resolve your problem,
Cheers,
Ash
|
|
|
|
|
Thanks for the tips. The process is run as Administrator and I just confirmed all reads and writes are from same thread. Not sure about the interals of the USB hub... its an embedded system and serial ports and USB are not standard.
Any more ideas? This is a tough one and has me baffled. Maybe its something in the Windows kernel having to do with handling IO since I don't see a public API to listen to focus events for a console.
|
|
|
|