Re: How to create/display a modal window? And surplus of win32 code
Thanks ovidiucucu, I will check out the threads ... and upload the source :) Just got a bit sidetracked by something :) You already know I'm using plain WinAPI, which means the look of the buttons is very very basic, I'd say ugly, but I thought, oh well, that's the price I have to pay for not using wrappers. But I've noticed in one of the signatures of one of the members here on this board a link to nice buttons for the use with Win32. So I've downloaded the "SDK" for those buttons, and sure thing it didn't work, even the example code. The thing is, it uses this headers (and libs):
#include <uxtheme.h>
#include <tmschema.h>
I've searched those on my machine but did not find anywhere. Then I searched the net and found out they are part of Platform SDK. Ok, I downloaded Platform SDK April 2005 release ... only to find out it is incompatible with VC++ 6.0 (which is what I'm using), so I though I need an older SDK, and from what I've read I needed 2003 February edition. I downloaded that, installed, but I still keep getting almost 270 warnings + errors, and lots of them do not make any sense. Yes I added the include directory to Include paths, and same with Lib path, but that's it... also ticked the option to register environmental variables during the install. Rebooted, created fresh project but still no go. For several hours I'm trying to make this code to compile. Here's approx what errors compiler is giving me:
Code:
d:\program files\microsoft visual studio\myprojects\example\imagebutton.h(37) : warning C4028: formal parameter 2 different from declaration
d:\program files\microsoft visual studio\myprojects\example\imagebutton.h(37) : warning C4028: formal parameter 3 different from declaration
d:\program files\microsoft visual studio\myprojects\example\imagebutton.h(38) : warning C4031: second formal parameter list longer than the first list
d:\program files\microsoft visual studio\myprojects\example\imagebutton.h(38) : warning C4028: formal parameter 2 different from declaration
d:\program files\microsoft visual studio\myprojects\example\imagebutton.h(38) : warning C4028: formal parameter 3 different from declaration
[...]
d:\program files\microsoft visual studio\myprojects\example\buttontest.c(17) : error C2146: syntax error : missing ';' before identifier 'hPulsante'
d:\program files\microsoft visual studio\myprojects\example\buttontest.c(17) : error C2065: 'hPulsante' : undeclared identifier
d:\program files\microsoft visual studio\myprojects\example\buttontest.c(18) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct HWND__ *'
d:\program files\microsoft visual studio\myprojects\example\buttontest.c(22) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'const int '
d:\program files\microsoft visual studio\myprojects\example\buttontest.c(22) : warning C4024: 'ImageButton_Create' : different types for formal and actual parameter 2
d:\program files\microsoft visual studio\myprojects\example\buttontest.c(22) : warning C4020: 'ImageButton_Create' : too many actual parameters
d:\program files\microsoft visual studio\myprojects\example\buttontest.c(23) : warning C4047: 'function' : 'struct HINSTANCE__ *' differs in levels of indirection from 'const int '
d:\program files\microsoft visual studio\myprojects\example\buttontest.c(23) : warning C4024: 'ImageButton_SetBitmap' : different types for formal and actual parameter 2
[...]
d:\program files\microsoft visual studio\vc98\include\windef.h(281) : see declaration of 'COLORREF'
d:\program files\microsoft visual studio\myprojects\example\imagebutton.c(622) : error C2146: syntax error : missing ';' before identifier 'crPixel'
d:\program files\microsoft visual studio\myprojects\example\imagebutton.c(623) : error C2275: 'BYTE' : illegal use of this type as an expression
d:\program files\microsoft visual studio\vc98\include\windef.h(143) : see declaration of 'BYTE'
d:\program files\microsoft visual studio\myprojects\example\imagebutton.c(623) : error C2146: syntax error : missing ';' before identifier 'byNewPixel'
d:\program files\microsoft visual studio\myprojects\example\imagebutton.c(625) : warning C4018: '<' : signed/unsigned mismatch
d:\program files\microsoft visual studio\myprojects\example\imagebutton.c(627) : warning C4018: '<' : signed/unsigned mismatch
d:\program files\microsoft visual studio\myprojects\example\imagebutton.c(682) : error C2275: 'DWORD' : illegal use of this type as an expression
and so on.... long long list.
I probably should have started a new thread, but anyway, maybe somebody of you could help with this?
P.S. I'm using "ImageButton": http://imagebutton.winapizone.net/en/
Thanks everybody forthe replies,
Oleg
Re: How to create/display a modal window? And surplus of win32 code
First of all take a look at this (from ImageButon.h)
Code:
BOOL ImageButton_Create(HWND hButton, LPTSTR text);
BOOL ImageButton_Create(HWND hwndParent, UINT ctrlID, LPTSTR text);
In C language we have not function overloading, isn't it?
So, change the extension of ImageButon.c to ImageButon.CPP.
Further you must add somewhere in a source file:
Code:
#pragma comment(lib, "comctl32.lib")
But the troubles will not stop here.
Te code contains some other errors as for example:
Code:
BOOL ImageButton_DrawItem(WPARAM wParam, LPARAM lParam, int number)
{
// ...
LPWSTR wThemeCaption;
// ...
// ...
if (wThemeCaption)
delete [] wThemeCaption;
}
wThemeCaption was not initiaized so crashes on delete [] wThemeCaption;
I think it's better to ask the author, for me it's prety enough for this evening. ;)
Re: How to create/display a modal window? And surplus of win32 code
well d'oh !! I didn't know VC++ treats *.c files as code written in C :rolleyes: I mean, it's pretty incorrect to *identify* files by its extension ... there are better ways, such as headers e.g., of course this is not a binary file ... but if it's VC++ then it must treat the whole code as C++ unless explicitly specified by some #define or something... That's why I said some erors did not make any sense, I thought "why would it yield about simple overloading...everything's all right there", but I didn't think the problem was in the extension, so I didn't rename. Furthermore, how could he write this code with this .c extension if it should not have compiled this way? And also I see no point in renaming it to .c to make confusion. Anyway, odd. But thanks again, at least it complies now. I've already noticed errors too, I will see if I can fix them.
Regards,
Oleg
Re: How to create/display a modal window? And surplus of win32 code
Oh, now i see. I'm gonna fix them immediately.
PS: sorry for the .c file. Dev-cpp don't look at the extension. In fact it compiled ImageButton.c as a cpp file and i didn't care nor look at the extension :(
Re: How to create/display a modal window? And surplus of win32 code
If you consider that C/CPP extension problem mentioned here is a real problem (which I think it's not) you can report it to MS. Who knows, maybe in a furture implementation... ;)
Anyhow that code is wrtitten in C++ as long as it uses overloaded functions, operator new and delete, and so on.
IMO it's a mistake of the author to put C++ code in .C source files, at least from "good style programming" point of view.
Re: Cannot compile ImageButton source files
Re: Cannot compile ImageButton source files
Everything should be fine now. Fixes and adds:
- .cpp extension. Compile it as a c++ file.
- Images weren't destroyed when they were substituted.
- Using std::vector instead of array: more flexible and easier to use
- Using std::string for caption: no more delete and new
- Support for Unicode
- Thanks to vector, and more flexible functions to set images, code has been reduced by 200 lines (this sentence sounds as an advertising to me :D)
I'm sorry but i don't have visual c++, so if you can test it i will appreciate it :thumb: :)
Re: Cannot compile ImageButton source files
Oups!!!
Now I realize that you are "the author". :)
Sorry if I was a little bit too harsh.
1 Attachment(s)
Re: Cannot compile ImageButton source files
Here is attached the VC++ 6.0 project.
I have made just few minimal changes (search for comment //Ovidiu).
Re: Cannot compile ImageButton source files
Thank you, i will add a note about linking to comctl32.lib for Visual c++ and mingw.
But i don't see the differences between these two:
Code:
IMAGEBUTTONPROP newIB = {0};
//and
IMAGEBUTTONPROP newIB;
ZeroMemory(&newIB, sizeof(IMAGEBUTTONPROP));
Re: Cannot compile ImageButton source files
The first one gives Compiler Error C2552.
The other change
Code:
#ifndef IDC_HAND
#define IDC_HAND MAKEINTRESOURCE(32649) //Ovidiu
#endif
is just an ugly "patch" for VC++ 6.0 with no fully Platform SDK Update. ;) ...
Re: Cannot compile ImageButton source files
...however it's an alternative to define WINVER before including <windows.h>
Code:
#define WINVER 0x0500
#include <windows.h>
But this can scare some guys because of this ugly obsolete note:
Code:
Compiling...
buttontest.cpp
NOTE: WINVER has been defined as 0x0500 or greater which enables
Windows NT 5.0 and Windows 98 features. When these headers were released,
Windows NT 5.0 beta 1 and Windows 98 beta 2.1 were the current versions.
For this release when WINVER is defined as 0x0500 or greater, you can only
build beta or test applications. To build a retail application,
set WINVER to 0x0400 or visit http://www.microsoft.com/msdn/sdk
to see if retail Windows NT 5.0 or Windows 98 headers are available.
See the SDK release notes for more information.
:D :D
Of course in newer VC++ versions this note nomore appears.
Re: Cannot compile ImageButton source files
Quote:
Originally Posted by MSDN
The type has one or more user-defined constructors.
I don't define any constructor
Quote:
Originally Posted by MSDN
The type has one ore more non-static, private data members.
No private members.
Quote:
Originally Posted by MSDN
The type has one or more virtual functions.
No function at all.
Quote:
Originally Posted by MSDN
The type has a base class.
No base class/struct.
Quote:
Originally Posted by MSDN
thee type is a ref class or CLR interface.
It's not a class neither an interface
Quote:
Originally Posted by MSDN
The type is a scalar (int i = {} ;
?
Quote:
Originally Posted by MSDN
The type has a non-fixed dimension array (zero-array) whose elements have destructors.
The std::string has destructor (i suppose) but it's not an array..
Do you really get that compiler error?
Re: Cannot compile ImageButton source files
Yes.
Code:
Compiling...
ImageButton.cpp
C:\ButtonTest\ImageButton.cpp(687) : error C2552: 'newIB' : non-aggregates cannot be initialized with initializer list
Error executing cl.exe.
btnCaption is the bad guy (a kind of "non-fixed dimension array", I presume) ;)
Re: Cannot compile ImageButton source files
Lol. If i add ZeroMemory, it crashes (with MinGW). OH MAN! :confused: