C language > Windows questions
compiling error in a windows program : CreateWindow Function
(1/1)
p b das:
The following program gives error while attempted to compile using Pelles C:
--- Code: ---#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 ;
--- End code ---
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
TimoVJL:
CreateWindow is a macro using CreateWindowEx, so
--- Code: --- 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
--- End code ---
and h is an array of HWNDs, not HWND.
jj2007:
--- Quote from: p b das on July 19, 2017, 05:44:09 PM ---Solution solicited
--- End quote ---
This is not a paid help forum. You should learn reading the manuals.
--- Code: --- h[x] = CreateWindowA ( "button" , "Press Me" , WS_OVERLAPPEDWINDOW, x*20,
x*20 , 150 , 100 , 0 , 0 , hinstance , 0 ) ;
ShowWindow (h[x] , nCmdShow );
--- End code ---
p b das:
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
jj2007:
--- Quote from: p b das on July 21, 2017, 02:37:08 PM ---I am beginner in windows C programming
--- End quote ---
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.
Navigation
[0] Message Index
Go to full version