Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DialogBox() Edit control uppercase/lowercase

Status
Not open for further replies.

AAP

Programmer
May 8, 2000
93
GB
I am fairly new to C programming in a Windows environment.
At run-time, how can I force an Edit control in a DialogBox
to only accept uppercase or lowercase text?
 
Like just about everything in Windows UI developement, you want to start by looking at the messages that might be involved.

WM_KEYDOWN
WM_KEYUP

good luck
-pete
 
1.
Create a derived class from CEdit:
This you do with menu: 'Insert - New Class.."
Name: CMyEdit
FileName: CMyEdit.cpp
Base Class: CEdit


2.
you add to header-file CMyEdit.h:

public:
int upper_lower;


3.
Add to the constructor in cpp-file CMyEdit.cpp:


CMyEdit::CMyEdit()
{
upper_lower = 0;
}


4.
Start the Class-Wizzard and add the Message Map
PretranslateMessage to class CMyEdit,
and edit the function like this:

BOOL CMyEdit::preTranslateMessage(MSG* pMsg)
{
if ( pMsg->message == WM_CHAR )
{
if ( upper_lower == -1 )
{
if ( pMsg->wParam >= 65 && pMsg->wParam <= 95 )
{
pMsg->wParam += 32;
}
}
else if ( upper_lower == +1 )
{
if ( pMsg->wParam >= 97 && pMsg->wParam <= 122 )
{
pMsg->wParam -= 32;
}
}
}

return CEdit::preTranslateMessage(pMsg);
}


5.
Now connect the class CMyEdit to the controls in the dialog:
In the Class Wizzard select the dialog-class, tab: 'Member Variables',
select the edit-control, press button 'Add Variable'.
fill in:

Member variable name: m_ctrl_1 ( m_ctrl_2 etc.. )
Category: Control
Variable Type: CMyEdit


6.
Add to the header-file of the dialog:
#include &quot;CMyEdit.h&quot;


7.
Add to the the cpp-file of the dialog in 'OnInitDialog()':
m_ctrl_1.upper_lower = -1; // for lower_case;
m_ctrl_2.upper_lower = +1; // for upper_case;


8.
Be Happy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top