1

我有一个通用颜色对话框,我想在菜单按下时激活它。不幸的是,每次我按下该项目时,窗口都会失去焦点,就好像一个对话框即将出现,但该对话框从未出现。

我现在使用的代码如下:

case ID_TOOL_CHOOSECOLOR:
//show colour dialog
ChooseColor(&cc);

我已经像这样初始化了我的 CHOOSECOLOR 结构:

 cc.lStructSize    = sizeof (CHOOSECOLOR) ;
 cc.hwndOwner      = NULL ;
 cc.hInstance      = NULL ;
 cc.rgbResult      = RGB (0x80, 0x80, 0x80) ;
 cc.lpCustColors   = crCustColor ;
 cc.Flags          = CC_RGBINIT | CC_FULLOPEN ;
 cc.lCustData      = 0 ;
 cc.lpfnHook       = NULL ;
 cc.lpTemplateName = NULL ;

奇怪的是,对话框仅在我按下“ALT”键(并且只有 alt 键)后才会出现。有小费吗?

顺便说一句,我正在尝试在 MDI 文档中执行此操作。

谢谢

4

3 回答 3

5

我能看到的唯一问题是您没有为对话框指定所有者。这可能会导致对话框显示在主窗口后面。将主窗口的句柄指定为对话框的所有者。

在 MSDN 上的窗口功能页面上阅读有关窗口所有权的更多信息。

于 2013-04-10T00:10:43.217 回答
0

Fixed it!

Turns out, the issue I had was in the main window's WndProc.

I had set my WM_PAINT command to return 0; instead of break;.

Changing my return 0 to break solved everything! I think this is cause my return would exit the wndproc, whereas break would allow me to continue to the return MDIFrameProc(hwnd, message, wparam, lparam) .

I maybe wrong, but that's the best explanation that I can come up with that explains why break works but return 0 doesn't.

于 2013-04-10T05:59:32.400 回答
0

画完后一定要打电话ValidateRect(HWND,CONST RECT*);

于 2013-05-17T01:21:05.583 回答