Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Command Line

Author
Message
Mr Squishy
18
Years of Service
User Offline
Joined: 25th Feb 2006
Location:
Posted: 8th Mar 2006 06:00 Edited at: 8th Mar 2006 06:08
Hey, its me agian. First off i would just like to say thanks to all those of you who helped me in my former posts(everyone was incredibly nice and helpfull), and er keep it coming boys with your help im'a gonna learn me to program and make me one of those there MMORPGs ive heard so much about (just kidding.

Anyway, so ive been trying to make a command line box thingy (a box into which one can enter text and then hit enter, and then something happens,) and after three or four false starts i believe i have finally hit a snag which no amount of googleing can solve.

Heres the back story: I started out by "M$ paint"ing nine little squares that each had a part of the border for my edit box, and then loading them and turning them into spites and then making a new bitmap and then writing Sephnroth's text to that, and then making that into a sprite and then displaying the whole thing like one big happy family. I dont remember how i captured the input (as this was a few days ago,) but it had problems and in general the whole thing was crap, so i scrapped it.

After that i moped for a bit, until, as if by devine providance i chanced across Sephnroth's Menu's and Dialogs - DarkSDK Tutorial, (Sephnroth you Rock, by the way) which opened up a whole new world for me. Really. It did. And i have been simply head-over-heels about the Windows API ever since. Not really, but i do need to get this thing to work so here is the down and dirty.

An edit box is perfect for my needs, but i cant figure out how to know when the enter key is pressed. I figured it was something like:
case: WM_CHAR
case: WTF_THE_ENTER_KEY
in my dialog's procedure thingy, but i aparently have done something incorectly because it dont work. Any help would be greatly appreciated. Thanks.

I created a new DGSDK project in VS 2003 which i named Main.
Here is Main.cpp


Here is the resource.h


Here is Main.rc


Some days the cascading moments which constitute my experience dissolve to reveal a sense of clarity which transcends reasoning.
And then there are days like today.
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 8th Mar 2006 09:56
To detect keys, you need a WM_KEYDOWN. The virual key codes for the ENTER key (as well as others) start with VK_x and are stored in a header file.

Mr Squishy
18
Years of Service
User Offline
Joined: 25th Feb 2006
Location:
Posted: 8th Mar 2006 17:30
Im sorta new to this, but MSDN says:
The WM_CHAR message is posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function. The WM_CHAR message contains the character code of the key that was pressed.

So in the code above it did


I tried it with WM_KEYDOWN and got the the same problem. When i hit enter nothing happens but an "error ding."

Some days the cascading moments which constitute my experience dissolve to reveal a sense of clarity which transcends reasoning.
And then there are days like today.
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 8th Mar 2006 17:49 Edited at: 8th Mar 2006 17:50
Are you checking for VK_ENTER/VK_RETURN ?

Note - You should NOT check for ASCII codes, but for virtual key codes (has held by the VK_x constants).

Mr Squishy
18
Years of Service
User Offline
Joined: 25th Feb 2006
Location:
Posted: 8th Mar 2006 19:10
Yes i am checking for VK_RETURN. really i was checking for 0x0D, but i looked it up in WinUser.h, and VK_RETURN==0x0D. I am doing it in the message handler for my dialog window which is why i thought i should use WM_CHAR instead of WM_KEYDOWN.

I posted the entire code above.

Some days the cascading moments which constitute my experience dissolve to reveal a sense of clarity which transcends reasoning.
And then there are days like today.
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 9th Mar 2006 00:28 Edited at: 9th Mar 2006 00:30
WM_KEYDOWN is the best place for dealing with keyboard presses.

The edit box properties may need changing too

Mr Squishy
18
Years of Service
User Offline
Joined: 25th Feb 2006
Location:
Posted: 9th Mar 2006 01:30
I changed the "Want Return" property of the edit box to true, but i see no difference. also ive tried adding a case for VK_ESCAPE and added PostQuitMessage(0);, but that dosent work either. I even added a message box to case WM_KEYDOWN just to see if i ever actually got there and the messageBox never showed so maybe you just cant handle keydown messages from inside a dialogs message handler. this thing is driving me crazy.
next im gonna try handling the the messages in my main message handler and using SendMessage() or SendDlgItemMessage() to communicate with my child dialog and if that dosent work maybe:
HWND hEdit;
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
WS_CHILD | WS_VISIBLE , 0, 0, 100, 100, hwnd,
(HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
to create my edit window on the fly instead of using the dailog i have created in Visual Studio.

Some days the cascading moments which constitute my experience dissolve to reveal a sense of clarity which transcends reasoning.
And then there are days like today.
Mr Squishy
18
Years of Service
User Offline
Joined: 25th Feb 2006
Location:
Posted: 9th Mar 2006 23:10
So i figured it out. Sorta. The problem was i was looking for the keydown message in the dialogs procedure, when i should of been looking for it in the procedure for the edit box itself. Well how the heck do you make a procedure for a control you may ask? You got to use GetDlgItem to get the HWND for the edit control, then use the trusty old SetWindowLong to associate your procedure you made with it and whala.

The thing is in case VK_ESCAPE: i put PostQuitMessage(0) thinking that that would kill everything for me nicely, but of course it dont, i just lose control of the window, the dialog and pretty much every thing, but im closer than i was yesterday and progress is progress so...

anyway thanks for the help. If anyone is interested i'll post some code when i get it running.

Some days the cascading moments which constitute my experience dissolve to reveal a sense of clarity which transcends reasoning.
And then there are days like today.

Login to post a reply

Server time is: 2024-05-06 05:11:54
Your offset time is: 2024-05-06 05:11:54