DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Cellphone Text (SMS) Editor part 1

  1. #1
    Join Date
    Dec 2007
    Posts
    16

    Cellphone Text (SMS) Editor part 1

    Hi ya'll.

    I have a big problem with this cell phone text editor program. It works, sometimes. I can't seem to get the output of the text correctly. I wonder if someone could point out what's wrong. If you don't have a direct answer, please do not reply because I just need a straightforward solution. Sorry, I'm too beat up already so I figured that I gave this forum a shot. Thanks.




    CELLPHONEKEYBOARD.H

    Code:
    #pragma once
    
    #include "resource.h"
    
    
    #define MAX_LOADSTRING 100
    
    typedef struct _STGLOBAL
    {
    	HINSTANCE		hInst;
    	HWND			hWnd;
    
    	TCHAR			szTitle[MAX_LOADSTRING];					// The title bar text
    	TCHAR			szWindowClass[MAX_LOADSTRING];			// the main window class name
    
    	TCHAR			szInputStr[1024];
    
    	HWND			hEdit;
    
    	_STGLOBAL()
    	{
    		ZeroMemory(szInputStr, sizeof(TCHAR)* 1024);
    	}
    
    }STGLOBAL;
    
    
    
    #define		ID_NUMBER0			(1000 + 0)
    #define		ID_NUMBER1			(1000 + 1)
    #define		ID_NUMBER2			(1000 + 2)
    #define		ID_NUMBER3			(1000 + 3)
    #define		ID_NUMBER4			(1000 + 4)
    #define		ID_NUMBER5			(1000 + 5)
    #define		ID_NUMBER6			(1000 + 6)
    #define		ID_NUMBER7			(1000 + 7)
    #define		ID_NUMBER8			(1000 + 8)
    #define		ID_NUMBER9			(1000 + 9)
    #define		ID_NUMBER_AS			(1000 + 10)
    #define		ID_NUMBER_SH			(1000 + 11)
    
    #define		ID_INPUT_SCREEN			(1000 + 15)
    
    #define		ID_INPUT_UPPERCASE		(1000 + 16)
    #define		ID_INPUT_LOWERCASE		(1000 + 17)
    #define		ID_INPUT_NUMERIC		(1000 + 18)
    #define		ID_INPUT_SYMBOLS		(1000 + 19)
    
    #define		ID_INPUT_UP				(1000 + 20)
    #define		ID_INPUT_DOWN			(1000 + 21)
    #define		ID_INPUT_LEFT			(1000 + 22)
    #define		ID_INPUT_RIGHT			(1000 + 23)
    
    
    extern STGLOBAL g_stGlobal;

    CMOBILEEDITOR.H

    Code:
    #ifndef __CMOBILEEDITBOX_H__
    #define __CMOBILEEDITBOX_H__
    
    /******************************************************************************
    Name : CMobileEditbox.h  (CB:Black)
    Desc : ...
    
    
    -Writed By Uranus at 2008-03-07  11:25:59
    ******************************************************************************/
    #pragma once
    
    
    
    #define		ID_CARET_SHIFT_TIMER		1000
    
    typedef enum _eInInputType
    {
    	eInLowerCase = 0, eInUpperCase , eInNumeric, eInSymbols
    }eInInputType;
    
    class CMobileEditbox
    {
    
    ///////////////////////////////////////////////////////////////////////////////////////
    // Method
    public:
    	bool Create(HWND hWnd);
    	int	GetLength(TCHAR* lpszStr, int nLen, SIZE& sz);		// calculate caret.
    	void RenderString();									// draw string.
    
    	void InputChar(BYTE nInput);						// input character
    	void SetCaretPostion();								// set position of pixel.
    	void SetInputType(eInInputType eType);					// set input type (uppercase, lowercase, number.symbols)
    
    	void MoveCaretUP();								// caret's position move line up.
    	void MoveCaretDown();								// caret's position move line down.
    	void MoveCaretLeft();								// caret's position move left.
    	void MoveCaretRight();								// caret's position move right.
    	void MoveCaretHome();								// caret's position move 0.
    	void MoveCaretEnd();								// caret's position move end.
    
    	int  GetLinePositionFromCurrentLine();
    
    
    	BOOL WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);			// windows message process 
    
    	inline void SetHwnd(HWND hWnd) { m_hWnd = hWnd;}
    
    protected:
    private:
    
    ///////////////////////////////////////////////////////////////////////////////////////
    // Attribute
    public:
    	HWND				m_hWnd;
    	TCHAR				m_szEdit[1024];
    	RECT				m_rtDest;
    					
    	int					m_nCaretPosX;				// Caret coordination, X
    	int					m_nCaretPosY;				// Caret coordination, Y
    	int					m_nLineCount;				// current line 
    					
    
    	int					m_nInputPosition;				// current character point;
    	eInInputType			m_eInType;					// input types
    	BYTE				m_cInputKind;				// it's able to input 1 character of 3 character.(ex, a,b,c)
    	BYTE				m_cPreviousInput;				// the previous input value.
    	int					m_nTickTime;					// tick time. for shift caret
    	bool					m_bIsShifted;					// states if a character has been set with the timer
    
    
    
    protected:
    private:
    	
    
    	
    
    ///////////////////////////////////////////////////////////////////////////////////////
    // Constructor & Destructor
    public:
    	CMobileEditbox();
    	virtual ~CMobileEditbox();
    
    	void Initialize();
    	void ReleaseAll();
    
    };
    
    
    
    #endif //__CMOBILEEDITBOX_H__
    RESOURCE.H

    Code:
    //{{NO_DEPENDENCIES}}
    // Microsoft Visual C++ generated include file.
    // Used by CellPhoneKeyboard.rc
    //
    
    #define IDS_APP_TITLE			103
    
    #define IDR_MAINFRAME			128
    #define IDD_CELLPHONEKEYBOARD_DIALOG	102
    #define IDD_ABOUTBOX			103
    #define IDM_ABOUT				104
    #define IDM_EXIT				105
    #define IDI_CELLPHONEKEYBOARD			107
    #define IDI_SMALL				108
    #define IDC_CELLPHONEKEYBOARD			109
    #define IDC_MYICON				2
    #ifndef IDC_STATIC
    #define IDC_STATIC				-1
    #endif
    // Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    
    #define _APS_NO_MFC					130
    #define _APS_NEXT_RESOURCE_VALUE	129
    #define _APS_NEXT_COMMAND_VALUE		32771
    #define _APS_NEXT_CONTROL_VALUE		1000
    #define _APS_NEXT_SYMED_VALUE		110
    #endif
    #endif
    STDAFX.H

    Code:
    // stdafx.h : include file for standard system include files,
    // or project specific include files that are used frequently, but
    // are changed infrequently
    //
    
    #pragma once
    
    // Modify the following defines if you have to target a platform prior to the ones specified below.
    // Refer to MSDN for the latest info on corresponding values for different platforms.
    #ifndef WINVER				// Allow use of features specific to Windows XP or later.
    #define WINVER 0x0501		// Change this to the appropriate value to target other versions of Windows.
    #endif
    
    #ifndef _WIN32_WINNT		// Allow use of features specific to Windows XP or later.                   
    #define _WIN32_WINNT 0x0501	// Change this to the appropriate value to target other versions of Windows.
    #endif						
    
    #ifndef _WIN32_WINDOWS		// Allow use of features specific to Windows 98 or later.
    #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
    #endif
    
    #ifndef _WIN32_IE			// Allow use of features specific to IE 6.0 or later.
    #define _WIN32_IE 0x0600	// Change this to the appropriate value to target other versions of IE.
    #endif
    
    #define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
    // Windows Header Files:
    #include <windows.h>
    
    // C RunTime Header Files
    #include <stdlib.h>
    #include <malloc.h>
    #include <memory.h>
    #include <tchar.h>
    
    #include <stdio.h>
    #include <stdlib.h>
    
    // TODO: reference additional headers your program requires here
    continued...

  2. #2
    Join Date
    Dec 2007
    Posts
    16

    Cellphone Text (SMS) Editor part 2

    CELLPHONEKEYBOARD.CPP

    [CODE]// CellPhoneKeyboard.cpp : Defines the entry point for the application.
    //

    #include "stdafx.h"
    #include "CellPhoneKeyboard.h"
    #include "CMobileEditbox.h"

    /////////////////////////////////////////////////////////
    // declare global variables
    STGLOBAL g_stGlobal;

    #define z {Beep(2500,25);}

    CMobileEditbox g_clsMobileEditBox;


    /////////////////////////////////////////////////////////
    // Forward declarations of functions included in this code module:

    ATOM MyRegisterClass(HINSTANCE hInstance);
    HWND InitInstance(HINSTANCE, int);
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


    BOOL InitializeApplication(HWND hWnd);
    void ReleaseAllApplication();

    BOOL OnCreate();
    void OnButtonClick(BYTE nInput);
    void Justify(HDC pdc, PTSTR pText, RECT *pRc);


    int APIENTRY _tWinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine,
    int nCmdShow)
    {
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: Place code here.
    MSG msg;
    HACCEL hAccelTable;

    // Initialize global strings
    LoadString(hInstance, IDS_APP_TITLE, g_stGlobal.szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_CELLPHONEKEYBOARD, g_stGlobal.szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    HWND hWnd = InitInstance (hInstance, nCmdShow);
    // Perform application initialization:
    if (!hWnd )
    {
    return FALSE;
    }

    g_stGlobal.hWnd = hWnd;
    g_stGlobal.hInst = hInstance;

    if(InitializeApplication(hWnd) == FALSE)
    {
    return FALSE;
    }



    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CELLPHONEKEYBOARD));

    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0))
    {
    if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }

    ReleaseAllApplication();

    return (int) msg.wParam;
    }



    //
    // FUNCTION: MyRegisterClass()
    //
    // PURPOSE: Registers the window class.
    //
    // COMMENTS:
    //
    // This function and its usage are only necessary if you want this code
    // to be compatible with Win32 systems prior to the 'RegisterClassEx'
    // function that was added to Windows 95. It is important to call this function
    // so that the application will get 'well formed' small icons associated
    // with it.
    //
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = WndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CELLPHONEKEYBOARD));
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName = MAKEINTRESOURCE(IDC_CELLPHONEKEYBOARD);
    wcex.lpszClassName = g_stGlobal.szWindowClass;
    wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassEx(&wcex);
    }

    //
    // FUNCTION: InitInstance(HINSTANCE, int)
    //
    // PURPOSE: Saves instance handle and creates main window
    //
    // COMMENTS:
    //
    // In this function, we save the instance handle in a global variable and
    // create and display the main program window.
    //
    HWND InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
    HWND hWnd;
    hWnd = CreateWindow(g_stGlobal.szWindowClass, g_stGlobal.szTitle, WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

    if (!hWnd)
    {
    return hWnd;
    }

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    return hWnd;
    }

    //
    // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
    //
    // PURPOSE: Processes messages for the main window.
    //
    // WM_COMMAND - process the application menu
    // WM_PAINT - Paint the main window
    // WM_DESTROY - post a quit message and return
    //
    //]


    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {

    TCHAR szInput[2];
    switch (message)
    {

    case WM_TIMER:
    {
    g_clsMobileEditBox.WndProc(hWnd, message, wParam, lParam);
    }
    break;

    case WM_COMMAND:
    {
    switch(LOWORD(wParam))
    {
    case ID_NUMBER0:
    {
    wsprintf(szInput,"%c", '0');
    OnButtonClick(0);
    }
    break;

    case ID_NUMBER1:
    {
    wsprintf(szInput,"%c", '1');
    OnButtonClick(1);
    }
    break;

    case ID_NUMBER2:
    {
    wsprintf(szInput,"%c", '2');
    OnButtonClick(2);
    }
    break;

    case ID_NUMBER3:
    {
    wsprintf(szInput,"%c", '3');
    OnButtonClick(3);
    }
    break;

    case ID_NUMBER4:
    {
    wsprintf(szInput,"%c", '4');
    OnButtonClick(4);
    }
    break;

    case ID_NUMBER5:
    {
    wsprintf(szInput,"%c", '5');
    OnButtonClick(5);
    }
    break;

    case ID_NUMBER6:
    {
    wsprintf(szInput,"%c", '6');
    OnButtonClick(6);
    }
    break;

    case ID_NUMBER7:
    {
    wsprintf(szInput, "%c",'7');
    OnButtonClick(7);
    }
    break;

    case ID_NUMBER8:
    {
    wsprintf(szInput, "%c",'8');
    OnButtonClick(8);
    }
    break;

    case ID_NUMBER9:
    {
    wsprintf(szInput,"%c", '9');
    OnButtonClick(9);
    }
    break;

    case ID_NUMBER_AS:
    {
    wsprintf(szInput,"%c", '*');
    OnButtonClick(10);
    }
    break;

    case ID_NUMBER_SH:
    {
    wsprintf(szInput,"%c", '#');
    OnButtonClick(11);
    }
    break;

    case ID_INPUT_UPPERCASE:
    {
    g_clsMobileEditBox.SetInputType(eInUpperCase);
    }
    break;

    case ID_INPUT_LOWERCASE:
    {
    g_clsMobileEditBox.SetInputType(eInLowerCase);
    }
    break;

    case ID_INPUT_NUMERIC:
    {
    g_clsMobileEditBox.SetInputType(eInNumeric);
    }
    break;

    case ID_INPUT_SYMBOLS:
    {
    g_clsMobileEditBox.SetInputType(eInSymbols);
    }
    break;

    case ID_INPUT_LEFT:
    {
    g_clsMobileEditBox.MoveCaretLeft();
    }
    break;

    case ID_INPUT_RIGHT:
    {
    g_clsMobileEditBox.MoveCaretRight();
    }
    break;

    case ID_INPUT_UP:
    {
    g_clsMobileEditBox.MoveCaretUP();
    }
    break;

    case ID_INPUT_DOWN:
    {
    g_clsMobileEditBox.MoveCaretDown();
    }
    break;

    }
    }
    break;

    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
    }

    BOOL InitializeApplication(HWND hWnd)
    {
    g_clsMobileEditBox.Create(hWnd);
    OnCreate();

    return TRUE;
    }

    void ReleaseAllApplication()
    {
    return;
    }

    BOOL OnCreate()
    {
    const int nBtnWidth = 80;
    const int nBtnHeight = 25;

    char szTemp[100];


    HWND hWnd[20];
    int i = 0, j = 0;
    int nLoop = 0;
    for( i = 0; i < 3; ++i)
    {
    for( j = 0; j < 3; ++j)
    {

    wsprintf(szTemp, "%d", ((i* 3) + j + 1) % 10);
    hWnd[(i* 3) + j] = CreateWindow("button", szTemp,
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (j * nBtnWidth) + 5, (i * nBtnHeight) + 5,
    nBtnWidth, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)(ID_NUMBER1 + (i* 3) + j ),
    g_stGlobal.hInst,
    0
    );

    ++nLoop;
    }
    }


    wsprintf(szTemp, "%d", 0);
    hWnd[9] = CreateWindow("button", szTemp,
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (1 * nBtnWidth) + 5, (i * nBtnHeight) + 5,
    nBtnWidth, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)ID_NUMBER0,
    g_stGlobal.hInst, 0
    );


    hWnd[10] = CreateWindow("button", "*",
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (0 * nBtnWidth) + 5, (i * nBtnHeight) + 5,
    nBtnWidth, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)ID_NUMBER_AS,
    g_stGlobal.hInst, 0
    );


    hWnd[11] = CreateWindow("button", "#",
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (2 * nBtnWidth) + 5, (i * nBtnHeight) + 5,
    nBtnWidth, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)ID_NUMBER_SH,
    g_stGlobal.hInst, 0
    );


    hWnd[12] = CreateWindow("button", "Uppercase",
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (0 * nBtnWidth) + 5, ((i + 1) * nBtnHeight) + 5,
    100, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)ID_INPUT_UPPERCASE,
    g_stGlobal.hInst, 0
    );


    hWnd[13] = CreateWindow("button", "Lowercase",
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (0 * nBtnWidth) + 5, ((i + 2) * nBtnHeight) + 5,
    100, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)ID_INPUT_LOWERCASE,
    g_stGlobal.hInst, 0
    );


    hWnd[14] = CreateWindow("button", "Numeric",
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (0 * nBtnWidth) + 5, ((i + 3) * nBtnHeight) + 5,
    100, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)ID_INPUT_NUMERIC,
    g_stGlobal.hInst, 0
    );


    hWnd[15] = CreateWindow("button", "Symbols",
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (0 * nBtnWidth) + 5, ((i + 4) * nBtnHeight) + 5,
    100, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)ID_INPUT_SYMBOLS,
    g_stGlobal.hInst, 0
    );

    hWnd[16] = CreateWindow("button", "up",
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (0 * 50) + 5, ((i + 5) * nBtnHeight) + 5,
    50, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)ID_INPUT_UP,
    g_stGlobal.hInst, 0
    );

    continued...

  3. #3
    Join Date
    Dec 2007
    Posts
    16

    Cellphone Text (SMS) Editor part 3

    hWnd[17] = CreateWindow("button", "down",
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (1 * 50) + 5, ((i + 5) * nBtnHeight) + 5,
    50, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)ID_INPUT_DOWN,
    g_stGlobal.hInst, 0
    );

    hWnd[18] = CreateWindow("button", "left",
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (2 * 50) + 5, ((i + 5) * nBtnHeight) + 5,
    50, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)ID_INPUT_LEFT,
    g_stGlobal.hInst, 0
    );

    hWnd[19] = CreateWindow("button", "right",
    WS_BORDER|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
    (3 * 50) + 5, ((i + 5) * nBtnHeight) + 5,
    50, nBtnHeight,
    g_stGlobal.hWnd, (HMENU)ID_INPUT_RIGHT,
    g_stGlobal.hInst, 0
    );

    return TRUE;
    }



    void OnButtonClick(BYTE nInput)
    {
    g_clsMobileEditBox.m_hWnd = g_stGlobal.hWnd;
    SetRect(&g_clsMobileEditBox.m_rtDest, 400, 10, 400 + 100, 10 + 25);

    g_clsMobileEditBox.InputChar(nInput);
    g_clsMobileEditBox.RenderString();

    TCHAR szOutput[100];
    wsprintf(szOutput, "Caret Pos X = %d, Y = %d", g_clsMobileEditBox.m_nCaretPosX, g_clsMobileEditBox.m_nCaretPosY);

    HDC hDC = GetDC(g_stGlobal.hWnd);

    // caret pos x, y
    TextOut(hDC, 400, 200,szOutput, strlen(szOutput));

    wsprintf(szOutput, "Input Pos = %d", g_clsMobileEditBox.m_nInputPosition);
    // caret input position
    TextOut(hDC, 400, 250,szOutput, strlen(szOutput));

    wsprintf(szOutput, "Line Pos = %d", g_clsMobileEditBox.m_nLineCount);
    // caret line position
    TextOut(hDC, 400, 265,szOutput, strlen(szOutput));

    wsprintf(szOutput, "m_eInType = %d", g_clsMobileEditBox.m_eInType);
    // m_eInType
    TextOut(hDC, 400, 280, szOutput, strlen(szOutput));

    wsprintf(szOutput, "m_cInputKind = %d", g_clsMobileEditBox.m_cInputKind);
    // m_eInType
    TextOut(hDC, 400, 295, szOutput, strlen(szOutput));

    ReleaseDC(g_stGlobal.hWnd,hDC);
    }

    [/CODE]

    CMOBILEEDITBOX.CPP

    [CODE]#include "StdAfx.h"
    #include "CMobileEditbox.h"



    const char s_szInputSet[4][10][5] =
    {
    {
    " \0",
    "\0\0\0\0",
    "abc",
    "def",
    "ghi",
    "jkl",
    "mno",
    "pqrs",
    "tuv",
    "wxyz"
    },
    {
    " \0",
    "\0\0\0\0",
    "ABC",
    "DEF",
    "GHI",
    "JKL",
    "MNO",
    "PQRS",
    "TUV",
    "WXYZ"
    },
    {
    "0\0",
    "1\0",
    "2\0",
    "3\0",
    "4\0",
    "5\0",
    "6\0",
    "7\0",
    "8\0",
    "9\0"
    },
    {
    ".,'",
    "?!\"",
    "-()",
    "@/:",
    "_;+",
    "&%*",
    "=<>",
    "$[",
    "]{}~",
    "^`#|"
    }
    };

    const BYTE s_MaxInput[4][10] =
    {
    {1,0,3,3,3,3,3,4,3,4},
    {1,0,3,3,3,3,3,4,3,4},
    {1,1,1,1,1,1,1,1,1,1},
    {3,3,3,3,3,3,4,4,4,4}
    };

    CMobileEditbox::CMobileEditbox(void)
    {

    ::ZeroMemory(m_szEdit, sizeof(TCHAR) * 1024);
    m_nCaretPosX = 0;
    m_nCaretPosY = 0;

    m_nLineCount = 0;
    m_nInputPosition = -1;

    m_eInType = eInLowerCase;
    m_cInputKind = 0;
    m_cPreviousInput=0xFF;

    m_nTickTime = 0; // for shift Caret
    m_bIsShifted = true;

    Initialize();
    }

    CMobileEditbox::~CMobileEditbox(void)
    {
    ReleaseAll();
    }


    void CMobileEditbox::Initialize()
    {
    return;
    }

    void CMobileEditbox::ReleaseAll()
    {
    KillTimer(m_hWnd, ID_CARET_SHIFT_TIMER);
    }


    bool CMobileEditbox::Create(HWND hWnd)
    {
    m_hWnd = hWnd;
    SetTimer(m_hWnd, ID_CARET_SHIFT_TIMER, 100, 0);

    return true;
    }

    int CMobileEditbox::GetLength(TCHAR* lpszStr, int nLen, SIZE& sz)
    {
    HDC hDC = GetDC(m_hWnd);

    ::GetTextExtentPoint32(hDC, lpszStr, nLen, &sz);

    ReleaseDC(m_hWnd, hDC);

    return sz.cx;
    }
    // end of GetTotalLength(lpszStr, nLen);

    void CMobileEditbox::InputChar(BYTE nInput)
    {
    if(s_MaxInput[m_eInType][nInput] == 0)
    return;

    // another button was pressed
    if(m_cPreviousInput != nInput)
    {
    ++m_nInputPosition;
    m_cInputKind = 0;
    }

    m_cPreviousInput = nInput;
    m_cInputKind = (m_cInputKind) % s_MaxInput[m_eInType][nInput];

    //~char* p = m_szEdit;
    //~memmove((char *)(p + m_nInputPosition + 1), (char *)(p + m_nInputPosition), 1024-m_nInputPosition - 1);

    m_szEdit[m_nInputPosition] = s_szInputSet[m_eInType][nInput][m_cInputKind];

    m_szEdit[strlen(m_szEdit) + 1] ='\0';
    ++m_cInputKind;

    SIZE sz;
    GetLength(m_szEdit, strlen(m_szEdit), sz);

    m_nTickTime = 0;
    m_bIsShifted = false;
    }
    // end of InputChar(BYTE nInput)


    void CMobileEditbox::RenderString()
    {
    SIZE sz;
    HDC hDC = GetDC(m_hWnd);

    int nLenLine = 0;
    TCHAR* p = m_szEdit, *pStart = m_szEdit;

    int nX = m_rtDest.left, nY= m_rtDest.top;

    int iCharPos = 0;
    int nLineCount = 0;
    m_nCaretPosX = 402;

    for(int i = 0; i < strlen(m_szEdit); ++i)
    {
    nLenLine += GetLength(++p, 1, sz);

    int nWidth = m_rtDest.right - m_rtDest.left;

    // caret positioning
    if (i <= m_nInputPosition)
    {
    switch(m_szEdit[i])
    {
    // 2 pixels
    case'i':case'j':case'l':case'.':case'\'':case'!':case':':case';':case'|':
    m_nCaretPosX+=2+1;
    break;
    // 4 pixels
    case'f':case'r':case't':case'-':case'/':case'{':case'}':case'\\':case'`':
    m_nCaretPosX+=4+1;
    break;
    // 5 pixels
    case'~':case'^':
    m_nCaretPosX+=5+1;
    break;
    // 7 pixels
    case'&':
    m_nCaretPosX+=7+1;
    break;
    // 8 pixels
    case'v':case'x':case'y':case'_':case'#':
    m_nCaretPosX+=8+1;
    break;
    // 10 pixels
    case'm':case'w':
    m_nCaretPosX+=10+1;
    break;
    // 11 pixels
    case'%':
    m_nCaretPosX+=11+1;
    break;
    // 12 pixels
    case'@':
    m_nCaretPosX+=12;
    break;
    // 6 pixels
    default:
    m_nCaretPosX+=6+1;
    }
    }

    if(nWidth >= nLenLine)
    {
    TextOut (hDC, nX, nY, pStart, p - pStart);
    //~m_nCaretPosX = GetLength(pStart, p - pStart, sz);
    //~m_nCaretPosY = nLineCount * sz.cy;
    }
    else
    {
    TextOut (hDC, nX, nY, pStart, p - pStart);

    m_nCaretPosX = 402;
    //~m_nCaretPosY = (nLineCount+1) * sz.cy;

    pStart = p;
    nLenLine = 0;
    nX = m_rtDest.left;
    nY += sz.cy;

    ++nLineCount;
    }
    // end of if(nWidth >= nLenLine){
    }
    // end of for(i)

    // draw the caret
    m_nCaretPosY = 7 + (nLineCount * sz.cy);
    TextOut(hDC, m_nCaretPosX, m_nCaretPosY, "_", 1);

    //~m_nLineCount = nLineCount;

    ReleaseDC(m_hWnd, hDC);
    }



    int CMobileEditbox::GetLinePositionFromCurrentLine()
    {
    SIZE sz;
    HDC hDC = GetDC(m_hWnd);

    int nLenLine = 0;
    TCHAR* p = m_szEdit, *pStart = m_szEdit;

    int nX = m_rtDest.left, nY = m_rtDest.top;
    int nCaretPosX = 0, nCaretPosY = 0;
    int iCharPos = 0, nLineCount = 0, nCurrentPosLine = 0;
    for(int i = 0; i < m_nInputPosition; ++i)
    {
    nLenLine += GetLength(++p, 1, sz);

    int nWidth = m_rtDest.right - m_rtDest.left;
    if(nWidth >= nLenLine)
    {
    //~TextOut (hDC, nX, nY, pStart, p - pStart);
    nCaretPosX = GetLength(pStart, p - pStart, sz);
    nCaretPosY = nLineCount * sz.cy;
    ++nCurrentPosLine;
    }
    else
    {
    //~TextOut (hDC, nX, nY, pStart, p - pStart);
    nCaretPosX = 0;
    nCaretPosY = nLineCount * sz.cy;

    pStart = p;
    nLenLine = 0;
    nX = m_rtDest.left;
    nY += sz.cy;

    ++nLineCount;

    nCurrentPosLine = 0;
    }
    // end of if(nWidth >= nLenLine){
    }
    // end of for(i)

    // m_nLineCount = nLineCount;

    ReleaseDC(m_hWnd, hDC);

    return nCurrentPosLine;
    }
    // end of GetLinePositionFromCurrentLine()

    void CMobileEditbox::SetCaretPostion()
    {
    return;
    }

    continued...

  4. #4
    Join Date
    Dec 2007
    Posts
    16

    Cellphone Text (SMS) Editor part 4

    BOOL CMobileEditbox::WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
    {
    switch(iMessage)
    {
    case WM_TIMER:
    {
    if(wParam == ID_CARET_SHIFT_TIMER)
    {
    ++m_nTickTime;

    if(m_nTickTime > 10 && !m_bIsShifted)
    {
    if(m_szEdit[m_nInputPosition] != '\0')
    {
    ++m_nInputPosition;
    m_cInputKind = 0;
    //~m_cPreviousInput = 0xFF;
    }
    m_nTickTime = 0;
    m_bIsShifted = true;
    }
    }
    }

    break;
    }

    return TRUE;
    }

    void CMobileEditbox::SetInputType(eInInputType eType)
    {
    // change button text;
    m_eInType = eType;
    }

    void CMobileEditbox::MoveCaretUP()
    {
    (--m_nLineCount<0)?m_nLineCount=0:0;
    }
    // end of MoveUP()

    void CMobileEditbox::MoveCaretDown()
    {
    int nTemp = GetLinePositionFromCurrentLine();
    (++m_nLineCount>nTemp)?m_nLineCount=nTemp:0;
    }
    // end of MoveDown()

    void CMobileEditbox::MoveCaretLeft()
    {
    (--m_nInputPosition<0)?m_nInputPosition=0:0;
    }
    // end of MoveLeft()

    void CMobileEditbox::MoveCaretRight()
    {
    if(strlen(m_szEdit) >= m_nInputPosition)
    return ;

    ++m_nInputPosition;
    }
    // end of MoveRight()

    void CMobileEditbox::MoveCaretHome()
    {
    m_nInputPosition = 0;
    }
    // end of MoveCaretHome();

    void CMobileEditbox::MoveCaretEnd()
    {
    m_nInputPosition = strlen(m_szEdit);
    }
    // end of MoveCaretEnd()

    [/CODE]

    STDAFX.CPP

    Code:
    // stdafx.cpp : source file that includes just the standard includes
    // CellPhoneKeyboard.pch will be the pre-compiled header
    // stdafx.obj will contain the pre-compiled type information
    
    #include "stdafx.h"
    
    // TODO: reference any additional headers you need in STDAFX.H
    // and not in this file

  5. #5
    Join Date
    Nov 2003
    Posts
    4,118
    I don't like this flooding-style of posting huge tons of code without even bothering to explain what exactly the problem is and restricting it to a well-defined code area. I also don't like the idea of posting 4 different messages for the same issue. If the code listing limit is a problem, please use file attachments instead. However, I decided to be exceptionally generous and tolerant this time. If there are kind people who'd bother to wade through your code and spot out any problems, they're welcome to do so.
    Last edited by Danny; 03-12-2008 at 07:19 AM.
    Danny Kalev

  6. #6
    Join Date
    Dec 2007
    Posts
    16

    one code

    thanks

Similar Threads

  1. Replies: 1
    Last Post: 10-24-2007, 02:12 AM
  2. Importing text file using schema.ini
    By Kevin in forum VB Classic
    Replies: 3
    Last Post: 12-05-2005, 07:25 PM
  3. Text
    By Mus in forum Java
    Replies: 2
    Last Post: 04-05-2002, 02:39 AM
  4. Script for scrolling
    By Mark in forum Web
    Replies: 3
    Last Post: 08-30-2001, 11:45 AM
  5. Double Text 1.0
    By George Gilbert in forum vb.announcements
    Replies: 0
    Last Post: 08-19-2001, 11:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center