我做一个控件,别的什么都不加,只处理它的消息,在WindowProc中加入
switch (message)
{case WM_SETFOCUS:
{
::SendMessage(hwnd,WM_KILLFOCUS,0,0);
::AfxGetMainWnd()->SetFocus();
}
}
当然,有多种表示办法!一旦在win98,VB中加载运行后就出错,请问是什么原因呢?
我要实现的功能是不让当前控件能获得焦点,上边代码在WIN2000中实现了功能
,请大家帮帮忙,不会也请UP一下!
原因是:
提示程序执行非法错误,VB6 在 0167:3721e0aa 的模块 CNSMIN.DLL 中导致堆栈错误。
Registers:
EAX=00000001 CS=0167 EIP=3721e0aa EFLGS=00010216
EBX=00702182 SS=016f ESP=00701ffc EBP=00702100
ECX=d1d55f10 DS=016f ESI=007021a6 FS=6597
EDX=00019e04 ES=016f EDI=00000000 GS=0000
Bytes at CS:EIP:
53 8b 5d 08 48 3b d8 56 7d 0b ff 75 14 ff 75 10
Stack dump:
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
和
VB6 在 0167:60567702 的模块
SSSCC.DLL 中导致无效页错误。
Registers:
EAX=00000000 CS=0167 EIP=60567702 EFLGS=00010246
EBX=60480000 SS=016f ESP=03e2fbe4 EBP=03e2fc14
ECX=00000000 DS=016f ESI=03920540 FS=7817
EDX=817b9278 ES=016f EDI=00000001 GS=65ee
Bytes at CS:EIP:
8b 71 04 85 f6 57 74 23 8b 7c 24 0c 33 d2 8b c7
Stack dump:
03920540 6056b2c9 00000a84 60480000 00000001 03920540 6056b12b 03920540 03920540 03e2fc24 6058d804 00000000 03e2fc30 6057bcd9 03920540 03920540
switch (message)
{case WM_SETFOCUS:
{
::SendMessage(hwnd,WM_KILLFOCUS,0,0);
::AfxGetMainWnd()->SetFocus();
}
}
当然,有多种表示办法!一旦在win98,VB中加载运行后就出错,请问是什么原因呢?
我要实现的功能是不让当前控件能获得焦点,上边代码在WIN2000中实现了功能
,请大家帮帮忙,不会也请UP一下!
原因是:
提示程序执行非法错误,VB6 在 0167:3721e0aa 的模块 CNSMIN.DLL 中导致堆栈错误。
Registers:
EAX=00000001 CS=0167 EIP=3721e0aa EFLGS=00010216
EBX=00702182 SS=016f ESP=00701ffc EBP=00702100
ECX=d1d55f10 DS=016f ESI=007021a6 FS=6597
EDX=00019e04 ES=016f EDI=00000000 GS=0000
Bytes at CS:EIP:
53 8b 5d 08 48 3b d8 56 7d 0b ff 75 14 ff 75 10
Stack dump:
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
和
VB6 在 0167:60567702 的模块
SSSCC.DLL 中导致无效页错误。
Registers:
EAX=00000000 CS=0167 EIP=60567702 EFLGS=00010246
EBX=60480000 SS=016f ESP=03e2fbe4 EBP=03e2fc14
ECX=00000000 DS=016f ESI=03920540 FS=7817
EDX=817b9278 ES=016f EDI=00000001 GS=65ee
Bytes at CS:EIP:
8b 71 04 85 f6 57 74 23 8b 7c 24 0c 33 d2 8b c7
Stack dump:
03920540 6056b2c9 00000a84 60480000 00000001 03920540 6056b12b 03920540 03920540 03e2fc24 6058d804 00000000 03e2fc30 6057bcd9 03920540 03920540
return 0;//不处理就得了。别调用基类的哈。
break;
}
up up up up
up up up up
up up upup
up up up upup up
up
把当前控件能获得焦点的消息屏蔽掉,是否可以用钩子函数?
VB下调用AfxGetMainWnd应该出错或返回错误的结果。你可以试试GetParent()->SetFocus();
{
case WM_SETFOCUS:
{
PostMessage(WM_KILLFOCUS,0,0);
::AfxGetMainWnd()->SetFocus();
break;
}
}
switch (message)
{case WM_SETFOCUS:
{
hParentWnd= GetParent(this);
SendMessage(hParentWnd, WM_KILLFOCUS, 0, 0); }
}
是这个
switch (message)
{case WM_SETFOCUS:
{
hParentWnd= GetParent(this);
SendMessage(hParentWnd, WM_NEXTDLGCTL, 0, 0); }
}
前面我写的hParentWnd= GetParent(this);这句只是个大概,具体是不是这么个调用方法要根据你的程序,总之不要用AfxGetMainWnd()
或者
2.使用postmessage代替sendmessage和::AfxGetMainWnd()->SetFocus()处理所有操作,因postmessage只是把消息投递之后即刻返回而sendmessage的行为则好像调用一个函数----这样若程序处理你post的消息是setfocus事件处理结束之后(大概如此)就能避免出错。但显然不如第一个方法安全。
往往会造成无限循环,引起堆栈溢出.
可以定义一个你自己的消息,My_SetFocus,然后PostMessage出去,在mY_SETFOCUS里面处理.