1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What's the proper sytax, and initialization of HWND *pHwnd[]={}; ?

Discussion in 'Win32' started by JimmyJ, Aug 3, 2008.

  1. JimmyJ

    JimmyJ New Member

    Joined:
    Aug 3, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    trading stocks
    Location:
    Cincinnati, OH
    Hello, and good day to whomever reads this.

    I am trying to learn the proper syntax, usage, and initialization of
    "HWND *pHwnd[]={...};".I am trying to create a loop which creates 3 windows. Then it assigns
    the returned HWND to an HWND variable pointed to by "HWND *pHwnd[]={..};". So I do not want
    pHwnd to point to anything other than what it's been initialized with already, rather I want
    to know how to assign the return from CreatWindowEx() to the variables pHwnd points to.


    I am not looking for a work-around unless there is no other way. I am trying to learn the
    about C++ semantics in Win32. Also I should mention that I am new to C++ and Win32.


    The code below helps to depict what I'm trying to do. Can you show what is wrong?








    Code:
       
       
        LPCTSTR lpClassName[]=  {"Static","Static","Static"};
        LPCTSTR lpWindowName[]= {"Win1",  "Win2",  "Win3"};
        
        int x[]      ={0, 0,  0};
        int y[]      ={50,100,150};
        int nWidth[] ={50,50, 50};
        int nHeight[]={20,20, 20};    
        
        HMENU hMenu[3];
    
    
        HWND hWin2, hWin2, hWin3;
        HWND *pHwnd[]={&hWin1, &hWin2, &hWin3};
    
    
         switch (message)                  /* handle the messages */
         {
            
            
            
    
    
            case WM_CREATE:
    
                 for(int makeWin=0; makeWin < 22*; makeWin++)
                 {           
                     hMenu[makeWin]=(HMENU)makeWin;
          
                     pHwnd[makeWin]=CreateWindowEx(0,
                                                   lpClassName[makeWin],
                                                   lpWindowName[makeWin],
                                                   WS_CHILD|WS_VISIBLE,
                                                   x[makeWin],
                                                   y[makeWin],
                                                   nWidth[makeWin],
                                                   nHeight[makeWin],
                                                   hwnd,
                                                   hMenu[makeWin],
                                                   NULL,
                                                   NULL
                                                   );  
                     
                 }
    
    
            break; 
    
    



    Thanks to anyone who reads this, and a big thanks to anyone who helps!
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Why not just use an array of HWNDs?
    HWND myWindows[3];
    myWindows[0]=CreateWindow(...);

    or, as you're doing it in a loop:
    for(i=0; i<3; i++) { myWindows=CreateWindow(...); }

    You said you don't want a workaround unless there is no other way but it would help to understand exactly why you want to use individual variables and an array of pointers to those variables and why this is preferred over simply using an array of HWNDs. What does an array of pointers to HWND do that an array of HWNDs doesn't do?
     

Share This Page