NO

Author Topic: compiling error in a windows program : CreateWindow Function  (Read 4231 times)

p b das

  • Guest
The following program gives error while attempted to compile   using Pelles C:


 
Code: [Select]
#include<windows.h>
  int  _stdcall WinMain ( HINSTANCE hinstance, HINSTANCE hPrevInstance,
                                      LPSTR  lpszCmdline, int nCmdShow )
 {   
       
           HWND h[10] ;
            int x ;

          for ( x = 0; x <= 9 ; x++ )
           {
                 h[x] =  CreateWindow ( "BUTTON" , "Press Me" ,
                                                        WS_OVERLAPPEDWINDOW , x *20,
                                                        x*20 , 150 , 100 , 0 , 0 , h , 0 ) ;
                ShowWindow ( h[x] , nCmdShow  );

             }

             MessageBox ( 0 , "Hi !" , "Waiting" , 0 ) ;
              return 0 ;
 

The compiling error is as under  :


  error #2140: Type error in argument 11 to 'CreateWindowExA'; expected 'struct HINSTANCE__ *' but found 'HWND'.
*** Error code: 1 ***

Solution solicited



« Last Edit: July 20, 2017, 01:06:45 PM by frankie »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: compiling error in a windows program : CreateWindow Function
« Reply #1 on: July 19, 2017, 09:42:33 PM »
CreateWindow is a macro using CreateWindowEx, so
Code: [Select]
h = CreateWindowEx(
0, // 1 DWORD dwExStyle
"BUTTON", // 2 LPCTSTR lpClassName
"Press Me", // 3 LPCTSTR lpWindowName
WS_OVERLAPPEDWINDOW, // 4 DWORD dwStyle
x * 20, // 5 int x
x * 20, // 6 int y
150, // 7 int nWidth
100, // 8 int nHeight
0, // 9 HWND hWndParent
0, // 10 HMENU hMenu
h, // 11 HINSTANCE hInstance
0); // 12 LPVOID lpParam
and h is an array of HWNDs, not HWND.
May the source be with you

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: compiling error in a windows program : CreateWindow Function
« Reply #2 on: July 20, 2017, 01:12:26 PM »
Solution solicited

This is not a paid help forum. You should learn reading the manuals.

Code: [Select]
                 h[x] = CreateWindowA ( "button" , "Press Me" , WS_OVERLAPPEDWINDOW, x*20,
                                                        x*20 , 150 , 100 , 0 , 0 , hinstance , 0 ) ;
                ShowWindow (h[x] , nCmdShow  );

p b das

  • Guest
Re: compiling error in a windows program : CreateWindow Function
« Reply #3 on: July 21, 2017, 02:37:08 PM »
The code can be modified  avoiding  array as under :

 #include<windows.h>


 int _stdcall WinMain ( HINSTANCE hinstance, HINSTANCE hPrevInstance,
                                      LPSTR  lpszCmdline, int nCmdShow )
{
  HWND  h ;


     
      h = CreateWindow (" BUTTON" , "Press Me" ,
                     WS_OVERLAPPEDWINDOW ,10 ,10 ,150 , 100 , 0 , 0 , h , 0  );
       ShowWindow (h , nCmdShow ) ;
       MessageBox ( 0 , " Hi !" , "Waiting" , MB_OK ) ;
        return  0 ;

  }


This code also results into same compiling error  in Pelles C compiler .  I have tested  this code and the earlier code posted in this forum   run correctly in
 Dev-C++ .without any compiling error. I want to know if there is any problem with the Pelles C compiler . I am beginner in windows C programming

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: compiling error in a windows program : CreateWindow Function
« Reply #4 on: July 21, 2017, 03:24:03 PM »
I am beginner in windows C programming

You should learn to
a) read error messages and
b) read our posts.

And no, there is no problem with Pelles C. You do not understand the differences between HWND and HINSTANCE, and you do not have the faintest idea what a local variable is. Your code is nonsense, my dear.