Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. WinApi and QT - how use
QtWS25 Last Chance

WinApi and QT - how use

Scheduled Pinned Locked Moved Unsolved General and Desktop
winapicreatewindowgetmodulehandle
3 Posts 2 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TomNow99
    wrote on last edited by
    #1

    Hello,

    I would like to write "hello world" using QT and WinApi: create simple Window. My code:

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        WNDCLASSEXW wc;
        wc.cbSize = sizeof( WNDCLASSEXW );
        wc.style = 0;
        wc.lpfnWndProc = WndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance =  (HINSTANCE)::GetModuleHandle(NULL);
        wc.hIcon = 0;
        wc.hCursor = 0;
        wc.hbrBackground =0;
        wc.lpszMenuName = NULL;
        wc.lpszClassName = (LPCWSTR)"myClass";
        wc.hIconSm = 0;
        qInfo()<<RegisterClassExW(&wc);
        HWND window = CreateWindowExW(WS_EX_CLIENTEDGE, (LPCWSTR)"myClass", (LPCWSTR)"title", WS_EX_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,300,300,NULL, NULL, (HINSTANCE)::GetModuleHandle(NULL), NULL);
        qInfo()<<window;
        ShowWindow(window ,SW_SHOW);
        UpdateWindow( window );
    }
    

    I get numbers ( qInfo() ):
    49696
    0x0

    So RegisterClassExW is successed and CreateWindowExW isn't is.

    Maybe (HINSTANCE)::GetModuleHandle(NULL) is bad?

    JonBJ 1 Reply Last reply
    0
    • T TomNow99

      Hello,

      I would like to write "hello world" using QT and WinApi: create simple Window. My code:

      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          WNDCLASSEXW wc;
          wc.cbSize = sizeof( WNDCLASSEXW );
          wc.style = 0;
          wc.lpfnWndProc = WndProc;
          wc.cbClsExtra = 0;
          wc.cbWndExtra = 0;
          wc.hInstance =  (HINSTANCE)::GetModuleHandle(NULL);
          wc.hIcon = 0;
          wc.hCursor = 0;
          wc.hbrBackground =0;
          wc.lpszMenuName = NULL;
          wc.lpszClassName = (LPCWSTR)"myClass";
          wc.hIconSm = 0;
          qInfo()<<RegisterClassExW(&wc);
          HWND window = CreateWindowExW(WS_EX_CLIENTEDGE, (LPCWSTR)"myClass", (LPCWSTR)"title", WS_EX_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,300,300,NULL, NULL, (HINSTANCE)::GetModuleHandle(NULL), NULL);
          qInfo()<<window;
          ShowWindow(window ,SW_SHOW);
          UpdateWindow( window );
      }
      

      I get numbers ( qInfo() ):
      49696
      0x0

      So RegisterClassExW is successed and CreateWindowExW isn't is.

      Maybe (HINSTANCE)::GetModuleHandle(NULL) is bad?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @TomNow99
      What in the world is the point of this? The whole point about developing in Qt is so that you not use a platform-specific api like WinApi, you use Qt methods instead. I can only imagine you have not understood this. The MainWindow instance you are in is already a main window, all you have to do is show() it. If you really want to do your way, give up on Qt, just use e.g. Visual Studio and a Windows SDK.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        TomNow99
        wrote on last edited by
        #3

        I know that I can use QDialog to create Window instead of WinApi. But I think this example is very easy, so I think there is another way...

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved