什么会导致工具栏被完全剪掉? [英] What would cause a toolbar to be totally clipped out?

查看:62
本文介绍了什么会导致工具栏被完全剪掉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我盯着这看了好几个小时。我试图让一个简单的工具栏使用钢筋控制。该项目是MDI,但我不相信(但不能保证)这不是问题的一部分。螺纹钢出现了。但是工具栏应该在哪里,除了按钮面颜色之外没有任何东西变成blitting,显然是对钢筋的WM_ERASEBKGND消息的响应。



深入挖掘它,我遇到的根本问题是,即使工具栏显示的宽度为> 1000,高度为22,DC上的GetClipBox显示DC设置为0,0,0,0。这是响应CDDS_PREPAINT部分上的反映通知消息。除了工具栏之外,钢筋没有其他孩子(我已经枚举了它们并检查了这个条件)。



错误可能在工具栏设置的某处,但我可以'看到了。该计划该部分的相关代码是:



I have stared at this for too many hours. I am trying to get a simple toolbar working with a rebar control. The project is MDI, although I don't believe (but can't guarantee) that that isn't part of the issue. The rebar appears. But where the toolbar should be, nothing ever gets blitted except the button face color, evidently as a response to a WM_ERASEBKGND message of the rebar.

Digging into it, the fundamental problem I'm having is that even though the toolbar shows a width of > 1000, and a height of 22, a GetClipBox on the DC is showing the DC is set to 0, 0, 0, 0. This is in response to a reflected notification message, on the CDDS_PREPAINT portion. The rebar has no other children besides the toolbar (I have enumerated them and checked this condition).

The error is probably somewhere in the toolbar setup, but I can't see it. The relevant code in that part of the program is:

bool Toolbar1::setup() {
   if (!toolbarC.createWindowEx()) return false;
   int resourceID = ID_TOOLBAR0; //Just for convenience, so I'll be less tempted to mistype

   //First, setup the image list.  This step loads the bitmap into the program, but doesn't
   //do anything else.
   if (!toolbarC.initializeImageList(resourceID)) return false;

   //Next, load the image into the imagelist:
   //Use the new C++11 vector initialization.  If using an older compiler, will need to
   //rewrite as outlined at http://www.cplusplus.com/reference/vector/vector/vector/
   //This brevity and clarity is one good reason to upgrade to the new standard.

   //The following constants are entered in the order of the icons in the resource:
   std::vector<int> ids = { DwlNewFile, DwlNewProject, DwlSaveFile, DwlOpenFile, DwlCppFile,
                       DwlHeaderFile };

   if (!toolbarC.addMaskedImages(ids, RGB(192, 192, 192))) return false;

   //Before adding stuff to the toolbar, we need to tell it what to expect
   if (!toolbarC.initialize()) return false;

   //Now add some buttons to the toolbar:
   DwlImageCtrl & imgCtrl = *toolbarC.imageControl();  //For '.' instead of '->' convenience
   if (!toolbarC.addButton(imgCtrl.getImagePos(DwlNewFile), fileNewC.id())) return false;
   if (!toolbarC.addButton(imgCtrl.getImagePos(DwlNewProject), fileNewC.id())) return false;

   //And do some toolbar post-image-creation toolbar setup:
   LRESULT r = (BOOL)SendMessage(toolbarC.hwnd(), TB_SETBITMAPSIZE, 0L, MAKELPARAM(16, 16));
   r = SendMessage(toolbarC.hwnd(), TB_SETBUTTONSIZE, 0L, MAKELPARAM(16+7, 16));
   r = SendMessage(toolbarC.hwnd(), TB_AUTOSIZE, 0L, 0L);

   swc::Rect tbr = toolbarC.getWindowRect();
   toolbarC.showWindow();  //Should not need this, but for testing purposes...

   return true;
   }





这个工具栏类中的代码:





The code in the toolbar class this calls:

bool DwlToolbarCtrl::createWindowEx(DWORD style) {
   swc::Rect r;   //Default to 0s is OK for this situation.
   return DwlControlWin::createWindowEx(0L, TOOLBARCLASSNAME, NULL, style,
                  r, NULL, (void*)this);
   }


bool DwlToolbarCtrl::initializeImageList(uint resourceID) {
   return imageControlC.initializeFromMultiImageResource(resourceID);
   }


bool DwlToolbarCtrl::addMaskedImages(const std::vector<int> & ids,
               COLORREF transparentColor) {
   return (imageControlC.addMaskedMultiImageResource(ids, transparentColor));
   }


bool DwlToolbarCtrl::initialize() {
   //This does the actual initialization of the toolbar itself, after the pre-initialization
   //of the imagelist has taken place.  This needs to be called after the 'initializeImageList' function.

   //First, we need to setup a TB_BUTTONSTRUCTSIZE array to tell the toolbar some necessary
   //information:

   SendMessage(hwndC, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0L);
   TBADDBITMAP tbab;
   tbab.hInst = gDwlApp->hInst();
   tbab.nID = (UINT_PTR)imageControlC.resourceNum();
   int numImages = imageControlC.numImages();
   DWORD r = (int)SendMessage(hwndC, TB_ADDBITMAP, (WPARAM)numImages, (LPARAM)&tbab);
   if (r == -1) return false;
   return true;
   }

         
bool DwlToolbarCtrl::addButton(int imagePos, int callbackId) {
   if (imagePos == -1) return false;
   TBBUTTON b;
   b.iBitmap = imagePos;
   b.idCommand = callbackId;
   b.fsState = TBSTATE_ENABLED;
   b.fsStyle = TBSTYLE_BUTTON;
   b.dwData = 0;
   b.iString = 0;
   BOOL res = SendMessage(hwndC, TB_ADDBUTTONS, 1, (LPARAM)&b);
   if (res == FALSE) {
      wString str = dwl::lastSysError();
      int i=0;
      return false;
      }
   return true;
   }





在此过程中没有标记错误代码。在CDDS_PREPAINT处理程序中,正在发生0大小的DC:





No error codes are being flagged during this. In the CDDS_PREPAINT handler is where the 0-sized DC is occurring:

LRESULT DwlToolbarCtrlEx::wPrePaint(NMCUSTOMDRAW * ptr, BOOL & notify) {
   BOOL t = IsWindowVisible(hwndC);
   swc::Rect r = getWindowRect();
   SwcGdi dc(ptr->hdc);
   swc::Rect rc = ptr->rc;

   swc::Rect tt(dwl::getClipBox(dc.dcC));
   dc.FloodFill(0, 0, RGB(255,255,255));

   return CDRF_NOTIFYITEMDRAW;
   }





'tt'测试矩形是令人困惑的0结果。 FloodFill不会产生任何白色。



另一个可能相关的症状是从不为工具栏调用CDDS_ITEMPREPAINT处理程序。这可能非常重要,但我无法解读。



如果您有任何想法,我将非常感激。一旦到位,我正在努力建立一个基于Francisco Campos的 Pretty WinAPI的大大减少闪存的对接框架类 [ ^ ],如果一切顺利的话。如果他们愿意,它将成为一篇关于CP的文章,其他框架可以从中得出。我已经厌倦了调整窗口的大小!



谢谢,

David



The 'tt' test rectangle is the perplexing 0 result. The FloodFill doesn't make anything white.

Another, probably related symptom is that CDDS_ITEMPREPAINT handler is never called for the toolbar. That is probably very significant, but I can't interpret it.

If you have any ideas, I will be very grateful. Once this is in place I'm working towards a vastly flicker-reduced docking framework based on Francisco Campos' Pretty WinAPI Class[^], if everything works out. It will become an article on CP which other frameworks can draw from if they desire. I'm tired of flickery windows resizing!

Thanks,
David

推荐答案

不是解决方案,但由于之前的帖子,我 能够获得一个主要线索。盯着我看到的帖子,该项目是MDI,虽然我不相信(但不能保证)这不是问题的一部分。



将其更改为SDI并且栏正确更新!所以我对这个问题有点新鲜了!
Not a solution, but thanks to the previous post I was able to obtain a major clue. Staring at the post I saw, "The project is MDI, although I don't believe (but can't guarantee) that that isn't part of the issue."

Changed it to SDI and the bar updates properly! So I'm a little fresher on the problem!


这个问题是为噩梦调试会议做的小事情的组合。部分原因是代码其他部分中'bool'和'BOOL'返回类型之间的(不那么)简单区别。仍然不确定我得到了所有东西,因为按钮'悬停'不能保持正确聚焦 - 当鼠标停在它上面时它很快就会解开。但至少它们不再消失。



惊讶地发现'TB_GETIDEALSIZE'导致工具栏从水平变为垂直。也许这是一个仍然不对的迹象。
The problem was a combination of little things that made for a nightmare debug session. Part of it was the (not-so) simple difference between 'bool' and 'BOOL' return types in other parts of the code. Still not certain I got everything, because button 'hover' doesn't stay focused properly - it quickly unfocuses when the mouse is stopped over it. But at least they no longer disappear.

Was surprised to find that 'TB_GETIDEALSIZE' resulted in the toolbar changing from horizontal to vertical. Maybe that's a sign something's still amiss.


这篇关于什么会导致工具栏被完全剪掉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆