关于VC的一个消息循环问题
以下这段代码实现的是在窗口标题显示按下的键.并且"上下左右"方向键可以控制窗口的走向.问题是代码中的str是怎么变化的?比如一个组合键"SHIFT+CTRL+A"下去后,...
以下这段代码实现的是在窗口标题显示按下的键.并且"上下左右"方向键可以控制窗口的走向.问题是代码中的str是怎么变化的?比如一个组合键"SHIFT+CTRL+A"下去后,代码的走向.
------------------
private: System::Void On_KeyDown(System::Object * sender, System::Windows::Forms::KeyEventArgs * e)
{
int nXStep = 0, nYStep = 0;
String *str,*strShift,*strCtrl,*strAlt;
System::Drawing::Point pt = this->Location;
switch(e->KeyData) {
case System::Windows::Forms::Keys::Up: nYStep = -10; break;
case System::Windows::Forms::Keys::Down: nYStep = 10; break;
case System::Windows::Forms::Keys::Left: nXStep = -10; break;
case System::Windows::Forms::Keys::Right: nXStep = +10; break;
default: if (e->Control) strCtrl = S"Ctrl +";
else strCtrl = "";
if (e->Alt) strAlt = S"Alt +";
else strAlt = "";
if (e->Shift) strShift = S"Shift +";
else strShift = "";
str = String::Concat( S"KeyDow:",strShift,strCtrl,strAlt,__box(e->KeyCode));
this->Text = str;
break;
}
if ((nXStep!=0) || (nYStep!=0)) {
pt.X += nXStep;
pt.Y += nYStep;
this->StartPosition = FormStartPosition::Manual;
this->Location = pt;
}
晕,看是问题描述部太清楚..
按下SHIFT不放后str为[KeyDow的值是:Shift+shiftkey]在接着按下CTRL后,就应该重新执行一次On_KeyDow了.按理来来说这时的str应该是[KeyDow的值是:Ctrl+Controlkey]才对呀.但实际出现的是[KeyDow的值是:Shift+Ctrl+Controlkey].这就意味着str没有重置..为什么会这样? 展开
------------------
private: System::Void On_KeyDown(System::Object * sender, System::Windows::Forms::KeyEventArgs * e)
{
int nXStep = 0, nYStep = 0;
String *str,*strShift,*strCtrl,*strAlt;
System::Drawing::Point pt = this->Location;
switch(e->KeyData) {
case System::Windows::Forms::Keys::Up: nYStep = -10; break;
case System::Windows::Forms::Keys::Down: nYStep = 10; break;
case System::Windows::Forms::Keys::Left: nXStep = -10; break;
case System::Windows::Forms::Keys::Right: nXStep = +10; break;
default: if (e->Control) strCtrl = S"Ctrl +";
else strCtrl = "";
if (e->Alt) strAlt = S"Alt +";
else strAlt = "";
if (e->Shift) strShift = S"Shift +";
else strShift = "";
str = String::Concat( S"KeyDow:",strShift,strCtrl,strAlt,__box(e->KeyCode));
this->Text = str;
break;
}
if ((nXStep!=0) || (nYStep!=0)) {
pt.X += nXStep;
pt.Y += nYStep;
this->StartPosition = FormStartPosition::Manual;
this->Location = pt;
}
晕,看是问题描述部太清楚..
按下SHIFT不放后str为[KeyDow的值是:Shift+shiftkey]在接着按下CTRL后,就应该重新执行一次On_KeyDow了.按理来来说这时的str应该是[KeyDow的值是:Ctrl+Controlkey]才对呀.但实际出现的是[KeyDow的值是:Shift+Ctrl+Controlkey].这就意味着str没有重置..为什么会这样? 展开
2个回答
展开全部
default:
if (e->Control) strCtrl = S"Ctrl +";
else strCtrl = "";
if (e->Alt) strAlt = S"Alt +";
else strAlt = "";
if (e->Shift) strShift = S"Shift +";
else strShift = "";
str = String::Concat( S"KeyDow:",strShift,strCtrl,strAlt,__box(e->KeyCode));
this->Text = str;
break;
这里面写的很清楚
假如按下的不是向上下左右
就会到这步:(前面获取值)
str = String::Concat( S"KeyDow:",strShift,strCtrl,strAlt,__box(e->KeyCode));
this->Text = str
KeyDow的值是:Shift+Ctrl+A
if (e->Control) strCtrl = S"Ctrl +";
else strCtrl = "";
if (e->Alt) strAlt = S"Alt +";
else strAlt = "";
if (e->Shift) strShift = S"Shift +";
else strShift = "";
str = String::Concat( S"KeyDow:",strShift,strCtrl,strAlt,__box(e->KeyCode));
this->Text = str;
break;
这里面写的很清楚
假如按下的不是向上下左右
就会到这步:(前面获取值)
str = String::Concat( S"KeyDow:",strShift,strCtrl,strAlt,__box(e->KeyCode));
this->Text = str
KeyDow的值是:Shift+Ctrl+A
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询