Results 1 to 5 of 5

Thread: Convert Windows "HWND" to QWidget* pointer?

  1. #1
    Join Date
    Sep 2006
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Convert Windows "HWND" to QWidget* pointer?

    Hi together,
    I wrote a screen saver for windows using QT. Everything works fine, but not the preview.

    From the commandline I get a parameter like "/p:345678". The number incidicate the WId of the parent window, the "mini monitor" in the windows build-in dialog for setting up the screensaver.

    So I tried:

    QWidget *parent=QWidget::find((HWND)WId);

    Then for debugging purpose:
    if (parent==NULL)
    QMessageBox::information(NULL,"","No parent "+QString::number(WId));
    else QMessageBox::information(NULL,"","Parent found "+QString::number(WId));

    Then create the widget:
    QWidget *miniMonitor=new QWidget(parent);

    But it does not work. parent ist always NULL. Althought the WId is correct, I can't get a pointer to the parent window to create a child window.

    In a windows API example they do something like:
    if( strncmp( lpszCmdLine, "/p", 2 ) == 0 )
    {
    // preview screen
    lpszCmdLine += 3;
    HWND hParentWnd = (HWND)strtoul( lpszCmdLine, '\0', 10 );
    GetClientRect( hParentWnd, &rc );

    hwndMain = CreateWindow("MainWndClass", "myScreenSaver",
    WS_CHILD, rc.left, rc.top, rc.right, rc.bottom, hParentWnd, NULL, hinst, NULL);
    }

    How to do this in QT?

    Thanks for tips, Bernd

  2. #2
    Join Date
    Aug 2006
    Posts
    44
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Convert Windows "HWND" to QWidget* pointer?

    Unless the parent window is also a QWidget in your QApplication, QWidget::find() won't work.

    I suspect what you may need to do in this case is use ::SetParent() directly on the wID of your own QWidget after you create it.

  3. #3
    Join Date
    Sep 2006
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert Windows "HWND" to QWidget* pointer?

    Quote Originally Posted by Eldritch View Post
    Unless the parent window is also a QWidget in your QApplication, QWidget::find() won't work.

    I suspect what you may need to do in this case is use ::SetParent() directly on the wID of your own QWidget after you create it.
    Thank you for the tip.
    But looking in the documentation:
    void QWidget::setParent ( QWidget * parent )

    So setParent needs a pointer to a QWidget. There is no setParent(WId) defined :-(

    And if my try to do:
    QWidget *parent=QWidget::find(WId); fails although WId is definetly a valid HWND, then setParent does not help me. :-(

    Greetings from Berlin, Bernd

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Convert Windows "HWND" to QWidget* pointer?

    He was talking about WinAPI function SetParent(HWND, HWND) declared in windows.h.
    J-P Nurmi

  5. #5
    Join Date
    Sep 2006
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Convert Windows "HWND" to QWidget* pointer?

    Quote Originally Posted by jpn View Post
    He was talking about WinAPI function SetParent(HWND, HWND) declared in windows.h.
    Thanks, that's working fine, Bernd

Similar Threads

  1. converting unix exe to windows binary
    By deekayt in forum General Programming
    Replies: 2
    Last Post: 17th September 2006, 01:00
  2. Replies: 8
    Last Post: 2nd August 2006, 16:19
  3. Qt and windows vista
    By munna in forum General Discussion
    Replies: 8
    Last Post: 11th January 2006, 22:33

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.