Results 1 to 3 of 3

Thread: Frame (MenuBar) corrupt inside Windows app

  1. #1
    Join Date
    Jun 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Frame (MenuBar) corrupt inside Windows app

    Hello.
    I build Qt application as DLL. That dll is used in Windows app (3ds max 2012). To make my Qt app as child window for 3ds max I do:
    Qt Code:
    1. void MainWindow::setParentWindowHandle(fVoid *parent)
    2. {
    3. if(parent)
    4. {
    5. SetParent(winId(), (HWND)parent);
    6.  
    7. QEvent e(QEvent::EmbeddingControl);
    8. QApplication::sendEvent(this, &e);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    But, when my window is showed, border frame(menu bar with close, maximize buttons) isn't painted, it's corrupt (or something like this, see the image below).
    Frameless.jpg

    But close, maximize buttons is there! I may click them.

    Don't know why it isn't painted...

    P.S.: When my app isn't child of 3ds max then all frames, buttons are showed fine

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Frame (MenuBar) corrupt inside Windows app

    How is your Qt event loop being called?

  3. #3
    Join Date
    Jun 2011
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default Re: Frame (MenuBar) corrupt inside Windows app

    Sorry for missing for long time.
    I've fixed the code but just partialy. To make right processing of events I used code from QtWinMigrate project. So, what I've done?
    First I added to class MyApplication such method:
    Qt Code:
    1. bool MyApplication::pluginInstance(Qt::HANDLE plugin)
    2. {
    3. if (qApp)
    4. return FALSE;
    5.  
    6. QT_WA({
    7. hhook = SetWindowsHookExW(WH_GETMESSAGE, QtFilterProc, 0, GetCurrentThreadId());
    8. }, {
    9. hhook = SetWindowsHookExA(WH_GETMESSAGE, QtFilterProc, 0, GetCurrentThreadId());
    10. });
    11.  
    12. if (plugin) {
    13. char filename[256];
    14. if (GetModuleFileNameA((HINSTANCE)plugin, filename, 255))
    15. LoadLibraryA(filename);
    16. }
    17.  
    18. return TRUE;
    19. }
    To copy to clipboard, switch view to plain text mode 

    It's called from here:
    Qt Code:
    1. BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD ul_reason_for_call, LPVOID lpReserved)
    2. {
    3. BOOL ret = TRUE;
    4. hInstance = hinstDLL; // Hang on to this DLL's instance handle.
    5.  
    6. switch(ul_reason_for_call)
    7. {
    8. case DLL_PROCESS_ATTACH:
    9. {
    10. VFBApplication::pluginInstance(hinstDLL);
    11. }
    12. ...
    13. }
    To copy to clipboard, switch view to plain text mode 


    Second, at MyApplication constructor I called:
    Qt Code:
    1. QAbstractEventDispatcher::instance()->setEventFilter(qmfc_eventFilter);
    To copy to clipboard, switch view to plain text mode 

    qmfc_evenFilter looks like this (it's static standalone function):
    Qt Code:
    1. static bool qmfc_eventFilter(void *message)
    2. {
    3. long result = 0;
    4. return static_cast<MyApplication*>(qApp)->winEventFilter((MSG*)message, &result);
    5. }
    To copy to clipboard, switch view to plain text mode 

    MyApplication::winEventFilter:
    Qt Code:
    1. bool MyApplication::winEventFilter ( MSG * msg, long * result )
    2. {
    3. static bool recursion = false;
    4. if (recursion)
    5. return false;
    6.  
    7. recursion = true;
    8.  
    9. QWidget *widget = QWidget::find(msg->hwnd);
    10. HWND toplevel = 0;
    11. if (widget) {
    12. HWND parent = widget->winId();
    13. while(parent) {
    14. toplevel = parent;
    15. parent = GetParent(parent);
    16. }
    17. HMENU menu = toplevel ? GetMenu(toplevel) : 0;
    18. if (menu && GetFocus() == msg->hwnd) {
    19. if (msg->message == WM_SYSKEYUP && msg->wParam == VK_MENU) {
    20. // activate menubar on Alt-up and move focus away
    21. SetFocus(toplevel);
    22. SendMessage(toplevel, msg->message, msg->wParam, msg->lParam);
    23. widget->setFocus();
    24. recursion = false;
    25. QApplication::processEvents();
    26. return TRUE;
    27. } else if (msg->message == WM_SYSKEYDOWN && msg->wParam != VK_MENU) {
    28. SendMessage(toplevel, msg->message, msg->wParam, msg->lParam);
    29. SendMessage(toplevel, WM_SYSKEYUP, VK_MENU, msg->lParam);
    30. recursion = false;
    31. QApplication::processEvents();
    32. return TRUE;
    33. }
    34. }
    35.  
    36. QApplication::processEvents();
    37. }
    38.  
    39. recursion = false;
    40. return QApplication::winEventFilter(msg, result);
    41. }
    To copy to clipboard, switch view to plain text mode 

    In additional MyApplication has such method:
    Qt Code:
    1. bool MyApplication::event(QEvent * e)
    2. {
    3. QApplication::processEvents();
    4. return QApplication::event(e);
    5. }
    To copy to clipboard, switch view to plain text mode 


    As a result I have almost normal behavior of MyApplication. At start point it's look like this:
    NormalWindow.jpg

    But several objects still corrupt my window:
    CorruptedOneWindow.jpg
    CorruptedSecondWindow.jpg

Similar Threads

  1. frame/panel style windows 7 nothing is drawn
    By mortoray in forum Qt Programming
    Replies: 0
    Last Post: 14th November 2010, 08:19
  2. Replies: 1
    Last Post: 28th May 2010, 11:33
  3. Focus frame inside QComboBox list
    By alpinista in forum Qt Programming
    Replies: 2
    Last Post: 13th November 2009, 14:30
  4. Previous frame inner to this frame(corrupt stack?)
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 28th May 2007, 01:35
  5. Previous frame inner to this frame(corrupt stack?)
    By coralbird in forum Qt Programming
    Replies: 17
    Last Post: 29th April 2006, 01:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.