Results 1 to 6 of 6

Thread: How to create CWnd from QWidget?

  1. #1
    Join Date
    Mar 2011
    Location
    Việt Nam
    Posts
    8
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Question How to create CWnd from QWidget?

    file.h have: class CTaskbarNotifier : public CWnd
    ///////
    CTaskbarNotifier m_wndTaskbarNotifier;
    \\\\\\\


    file.cpp
    ///////
    Qt Code:
    1. myfile::myfile(QWidget *parent) : QWidget(parent)
    2. {
    3.  
    4. // create the layout
    5. createLayout();
    6.  
    7. // create the animations
    8. createAnimations();
    9.  
    10. m_wndTaskbarNotifier.Create(/*what_this?*/);
    11. }
    To copy to clipboard, switch view to plain text mode 
    \\\\\\\


    Include TaskbarNotifier.cpp
    ///////
    Qt Code:
    1. int CTaskbarNotifier::Create(CWnd *pWndParent)
    2. {
    3. m_pWndParent=pWndParent;
    4. CString strWndClass=AfxRegisterWndClass(0,AfxGetApp()->LoadStandardCursor(IDC_ARROW),GetSysColorBrush(COLOR_WINDOW),NULL);
    5. return CreateEx(0,strWndClass,NULL,WS_POPUP,0,0,0,0,pWndParent->m_hWnd,NULL);
    6. }
    To copy to clipboard, switch view to plain text mode 
    \\\\\\\

    Thanks!!!

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create CWnd from QWidget?

    You are mixing Qt and MFC. Are you sure???

    Try using QWidget::winId to extract Windows Native Handle of the Widget
    A camel can go 14 days without drink,
    I can't!!!

  3. The following user says thank you to mcosta for this useful post:

    vudvpro (10th May 2011)

  4. #3
    Join Date
    Mar 2011
    Location
    Việt Nam
    Posts
    8
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: How to create CWnd from QWidget?

    Thank you very much!
    But you can give me an example of it?

  5. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create CWnd from QWidget?

    Sorry but I don't know MFC.
    A camel can go 14 days without drink,
    I can't!!!

  6. The following user says thank you to mcosta for this useful post:

    vudvpro (10th May 2011)

  7. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to create CWnd from QWidget?

    You can do CWnd *wnd = CWnd::FromHandle(QtWnd->winId) but note that this only creates a temporary CWnd object and so should not be stored for later use.

  8. The following user says thank you to squidge for this useful post:

    vudvpro (10th May 2011)

  9. #6
    Join Date
    Mar 2011
    Location
    Việt Nam
    Posts
    8
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Smile Re: How to create CWnd from QWidget?

    This ok:
    Qt Code:
    1. void Myclass::CreateTaskbarNotifier()
    2. {
    3. CTaskbarNotifier pTaskbarItem;
    4. afxCurrentInstanceHandle = qWinAppInst();
    5. CWnd *pWnd;
    6. pWnd = AfxGetApp()->GetMainWnd();
    7. pTaskbarItem.Create(pWnd);
    8. }
    9.  
    10.  
    11. int CTaskbarNotifier::Create(CWnd *pWndParent)
    12. {
    13. m_pWndParent = pWndParent;
    14. CString strWndClass = AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW), GetSysColorBrush(COLOR_WINDOW), NULL);
    15. return CreateEx(WS_EX_TOOLWINDOW, strWndClass, NULL, WS_POPUP, 0, 0, 0, 0, pWndParent->m_hWnd, NULL);
    16. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by vudvpro; 10th May 2011 at 11:07.

Similar Threads

  1. how create CWnd and use it in Qt
    By litterflybug in forum Qt Programming
    Replies: 5
    Last Post: 11th July 2013, 11:20
  2. Create a QWidget as child of a Win32 window
    By BenPa in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 29th March 2011, 14:35
  3. Example of QWidget::create required
    By andyp in forum Qt Programming
    Replies: 0
    Last Post: 21st October 2009, 11:09
  4. Cannot create a QWidget when no GUI is being used
    By Teerayoot in forum Qt Programming
    Replies: 2
    Last Post: 16th May 2007, 14:29
  5. Replies: 4
    Last Post: 24th April 2007, 13:18

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.