Share via

Child windows example code problem

Adam Berridge 21 Reputation points
2020-12-29T14:43:05.417+00:00

In https://learn.microsoft.com/en-us/windows/win32/winmsg/using-windows the example code creating three child windows has hinst passed as a parameter of CreateWindowEx but where did this come from? It isn't a parameter of the containing function or defined within it's scope.

Windows development | Windows API - Win32
0 comments No comments

Answer accepted by question author
  1. RLWA32 52,366 Reputation points
    2020-12-29T14:49:39.21+00:00

    A Windows desktop application is passed its HINSTANCE as a parameter to the WinMain function. This HINSTANCE would be saved in the global hInst variable when the application starts running and it would then be available to the CreateWindowEx function.

    See nf-winbase-winmain

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Castorix31 91,866 Reputation points
    2020-12-29T14:47:14.743+00:00

    hInst is from WinMain, like :

    HINSTANCE hInst;
    int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
    {
     hInst = hInstance;
     // ...
    
    1 person found this answer helpful.
    0 comments No comments

  2. Adam Berridge 21 Reputation points
    2020-12-29T14:58:40.267+00:00

    OK, but this isn't clear in the example.


  3. Adam Berridge 21 Reputation points
    2020-12-29T14:50:04.197+00:00

    Except that the call to CreateWindowEx in the example is in the message callback function, not WinMain.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.