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
// Main.cpp : The main entrypoint for the application.
//
#include "DarkSDK.h"
#include "globstruct.h"
#include "resource.h"
#include "stdio.h"
#include "stdlib.h"
#include "io.h"
LRESULT APIENTRY MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK CommandProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam);
void PaintScreen();
//========================
// Global Variables
//========================
#ifdef STRICT
WNDPROC lpPrevWndProc;
#else
FARPROC lpPrevWndProc;
#endif
bool Exit = false;
bool textInput = true;
bool textWindow = false;
char cmdString[256];
HWND textBox = NULL;
void DarkSDK (void)
{
dbSyncOn();
dbSyncRate(0);
sprintf(cmdString,"This should display the text in the above box after hitting enter");
lpPrevWndProc = (WNDPROC) SetWindowLong(g_pGlob->hWnd, GWL_WNDPROC, (LONG)MainWndProc);
textBox = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_CMDDLG),
g_pGlob->hWnd, CommandProc);
if(textBox != NULL)
{
ShowWindow(textBox, SW_SHOW);
}
else
{
MessageBox(g_pGlob->hWnd, "CreateDialog returned NULL", "Warning!",
MB_OK | MB_ICONINFORMATION);
}
// loop until the escape key is pressed
while (LoopSDK())
{
if (dbEscapeKey())
{
break;
}
dbText(40, 40, cmdString);
dbSync();
}
}
//========================
// Window message handler
// For the menu.
//========================
LRESULT APIENTRY MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_PAINT:
//PaintScreen();
break;
default:
break;
}
return CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam);
}
BOOL CALLBACK CommandProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) {
int len;
switch (message) {
case WM_CHAR:
switch (wParam)
{
case 0x0D:// Process a carriage return.!!!!!!!!!!!!!!!!!
len = GetWindowTextLength(GetDlgItem(textBox, IDC_CMDEDIT));
if(len <255) {
GetDlgItemText(textBox, IDC_CMDEDIT, cmdString, len + 1);
SetDlgItemText(textBox, IDC_CMDEDIT,"");
}
//return true;
break;
default:// Process displayable characters.
break;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case WM_CLOSE:
DestroyWindow(textBox);
break;
case WM_DESTROY:
DestroyWindow(textBox);
break;
}
}
return false;
}
Here is the resource.h
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Main.rc
//
#define IDD_CMDDLG 101
#define IDS_APP_TITLE 103
#define IDC_CMDEDIT 1000
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Here is Main.rc
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Neutral resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
#ifdef _WIN32
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// String Table
//
STRINGTABLE
BEGIN
IDS_APP_TITLE "Main"
END
#endif // Neutral resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_CMDDLG DIALOGEX 0, 0, 313, 17
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_SYSMENU
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_CMDEDIT,2,2,309,13,ES_AUTOHSCROLL
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_CMDDLG, DIALOG
BEGIN
LEFTMARGIN, 2
RIGHTMARGIN, 311
TOPMARGIN, 2
BOTTOMMARGIN, 15
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.K.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x0L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "Comments", "Written by "
VALUE "FileDescription", "root"
VALUE "FileVersion", "1, 0, 0, 1"
VALUE "InternalName", "root"
VALUE "LegalCopyright", "Copyright ©2005"
VALUE "OriginalFilename", "root.rc"
VALUE "ProductName", " root"
VALUE "ProductVersion", "1, 0, 0, 1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END
#endif // English (U.K.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
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.