API: Trying to Install Libraries...

Pages: 123
Ive tried and tried and tried.....

Well, I have a new idea.

Are there any C++ (C++, not C++/CLI) libraries that make it easier to emplement the windows API to make windows and stuff?

Also, I have a Resource Editor that makes resource files using the api, but makes it easy by allowing me to use an interface (like VC++).

I have not figured out how to emplement the resource files, or integrate them into my programs, though.

If there are any libraries that ease the learning curve for the Windows API, I would really appreciate the help.

Please post the link if you know one. Thanks.
Last edited on
The official one is MFC...
I'm working on an updated version of my free open-source MFC (that only requires native C++) but this will take me a lot of time, as I also am working on other things.

To use the resource-made dialogs, you can:

1. Create your dialog in a resource file. You get an ID for this dialog. Write it up somewhere. say IDD_DIALOG1.
2. Insert the resource file in the project file
3. Include the resource.h file where you need it
4.
1
2
3
4
5
INT_PTR CALLBACK YourWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    return 0;
}
DialogBox((HINSTANCE)GetModuleHandle(0),MAKEINTRESOURCE( IDD_DIALOG1 ),0, YourWindowProc);

http://msdn.microsoft.com/en-us/library/windows/desktop/ms645452(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645469(v=vs.85).aspx

Important note on DialogProc callback:
MSDN wrote:
Return value
Type: INT_PTR
Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the message.
If the dialog box procedure processes a message that requires a specific return value, the dialog box procedure should set the desired return value by calling SetWindowLong(hwndDlg, DWL_MSGRESULT, lResult) immediately before returning TRUE. Note that you must call SetWindowLong immediately before returning TRUE; doing so earlier may result in the DWL_MSGRESULT value being overwritten by a nested dialog box message.
The following messages are exceptions to the general rules stated above. Consult the documentation for the specific message for details on the semantics of the return value.


Remember that WindowProc's type is NOT DialogProc's type.
And it is so because their return values don't do the same thing.
It's advised to read carefully the Return Value section, in case you are using more than one dialog.
Last edited on
Well, see, I don't understand much of the Windows API. I don't know what a WindowsProc is.

I'm looking for a library that will at LEAST make emplementation less.... windows.. -y(?). I know all the C++ basics, (classes, pointers, references, vectors, strings, char*, arrays, etc... etc...) but I'm still learning the 'stunts' I can do with them (I'm always pushing myself, always learning new ways to do different things efficiently). I do not want to have to learn - what seems like - a giant, new language, while I haven't even started my first CS class...
Hi

Okay. The issue here is you're not asking questions like, "how does SendMessageA work?", you're asking "How do make a window do something". The answers to most of your questions are very much out there. When I had these kinds of questions I would just search until I found it.

To add a resource just use the resource editor in Visual Studio and add binary data. If you reference a file it'll include that file on build. Take note of the resource id definition and reference it like, FindResource( ... ID_SOMERESOURCE_1 ... ); - Or whatever you name it. Then CreateFileW & WriteFile.

FindResource() MSDN documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms648042(v=vs.85).aspx

CreateFileW() MSDN documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx

WriteFile() MSDN documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365747(v=vs.85).aspx


After dropping the resource file just draw it to the window.
Thanks
Last edited on
The other (semi) official Win32-specific GUI library is WTL -- the Windows Template library. This a lighter weight alternative to MFC.

Windows Template Library (WTL):
http://sourceforge.net/projects/wtl/

I only recently discovered that WTL (and MFC) can be with Visual C++ Express. I had thought that they were only available with the paid for versions, but it turns out they come with the Windows Driver Kit (the SDK used for Windows device driver development.) Of course, you don't get the (Visual Studio) code wizards to help you with MFC or ATL.

And as a result of learning this, I posted a basic example of a WTL app here:

MFC and ATL are part of WDK (in case you didn't know...)
http://www.cplusplus.com/forum/windows/102538/

Of course you should also consider one of the cross-platform GUI toolkits, like Qt, wxWidgets, FLTK, etc.

And if you are keen on Win32 programming, you should check out Charles Petzold's book, Programming Windows.

Is Petzold's book still relevant?
http://www.cplusplus.com/forum/windows/90740/

Andy
Last edited on
@SpaceWorm: He doesn't mean to draw an image over a window, but he means this:
http://www.resedit.net/
You can compose your window with this and pack it in a "Resource file" as a Dialog.
@IWishIKnew: When you create a window, Windows sends you lots of informations about what is the user doing, like, moving the mouse, clicking around, pressing keys, moving the window, etc...
But, where does it sends you these informations?
To your WndProc/DlgProc.

Your DlgProc is a function, and it will look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
INT_PTR CALLBACK YourWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    switch(Msg) // Msg will contain the current event that's happening.
    {
    case WM_INITDIALOG:
        // Dialog is being created here.
        return 1;
    case WM_QUIT:
        // Dialog is being destroyed here.
        return 1;
    case WM_CLOSE:
        // User is asking you to close your program here.
        if(AllowUserToCloseProgram) // If you want user to be able to close the program,
        {
            EndDialog(hWnd,0); // Close it.
        }
        return 1;
    case WM_TIMER: // Will be used if you want to use timers.
        // Right now, it's useless tho.
        return 1;
    case WM_COMMAND: // A button is pressed!
        switch(LOWORD(wParam)) // This contains the ID of the pushed button/item.
// Basically, if you made an item with id IDC_BUTTON1,
// then LOWORD(wParam) will be IDC_BUTTON1 once pushed.
        {
        case IDC_BUTTON1:
            // First button pushed
            return 1;
        }
        return 0;
    }
    return 0;
}


For other Window items, like static text and such, you have functions like SetWindowText and GetWindowText, or SetDlgItemText or GetDlgItemText for your uses:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645521(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645489(v=vs.85).aspx
For other infos, just search on the MSDN.
MSDN has informations for all Window items and Messages.

http://msdn.microsoft.com/en-us/library/ms644927%28v=VS.85%29.aspx

Another information:
You will not need a message loop for dialogs.
You just need to write
DialogBox((HINSTANCE)GetModuleHandle(0),MAKEINTRESOURCE( IDD_DIALOG1 ),0, YourWindowProc);
where you want your Dialog to be created at.

Working example (IDD_DIALOG1 and IDC_BUTTON1 required, so, a dialog with a push button):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
INT_PTR CALLBACK YourWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    switch(Msg)
    {
    case WM_COMMAND:
        {
            switch(LOWORD(wParam))
            {
                case IDC_BUTTON1:
                    MessageBoxA(hWnd,"Button Clicked!","Info",MB_ICONASTERISK);
                    return 1;
            }
            return 0;
        }
    case WM_INITDIALOG:
        MessageBoxA(hWnd,"Dialog Created!","Info",MB_ICONASTERISK);
        return 1;
    case WM_CLOSE:
        if(MessageBoxA(hWnd,"Destroy Dialog?","Question",MB_ICONQUESTION|MB_YESNO) == IDOK)
        {
            EndDialog(hWnd,0);
        }
        return 1;
    case WM_QUIT:
        MessageBoxA(hWnd,"Dialog being closed","Info",MB_ICONASTERISK);
        return 1;
    }
    return 0;
}

int main(int argc, char** argv)
{
    DialogBox((HINSTANCE)GetModuleHandle(0),MAKEINTRESOURCE( IDD_DIALOG1 ),0, YourWindowProc);
    return 0;
}


Other infos:
HWND is a Window Handle.
WPARAM and LPARAM are the same type now, 32-bit, where long ago one was 16-bit and the other 32-bit.
HINSTANCE is a Handle to a Program Instance. This was also used long ago, and it's still being used for few things.

MessageBoxA shows the default MessageBox "Alert" window, for the Ascii text mode.
For the unicode, you can use MessageBoxW (Wide).
For both, use MessageBox and TCHAR's.

This is the very bare bones GUI program, using Dialogs.
@EssGeEich
Thanks so much for the info! I believe I understand it, but I will read up on it more tomorrow (it's late here for me right now...)

@andywestken

Thanks! I will see what I can use it for, and hofully it will find usfullness in my programs. :)

Also, Which one of those cross-platform toolkits is easiest (least steps, etc) to install? I have had a poor experience trying to get WXwidgets to work in the past. The infernal thing wouldn't even build right, and the IDE wouldn't even use it for some reason.

Anyway, if you want to refer me, here is what I use:

Compiler: MinGW pre-built with Boost(Nuwen's distro; nuwen.net/mingw.html couldn't figure out how to build the damn thing (Boost), dispite all the very helpful forum posters here...took days before I gave it up, but was sooo close...)

IDE: NetBeans

OS: Windows 8
Architecture: 64 bit

Also, I was reading on wxWidgets (i had the bad experience on Code::Blocks) so, I was wondering if ResEdit could be used in conjunction with wxWidgets.

----------------------------------------------------------------------------

Thanks for the help, I really appreciate it.
Last edited on
Yes, ResEdit can be used in conjuction with wxWidgets, but however if you use wxWidgets and you don't like Code::Blocks with wxSmith plugin (it crashes for me when using wxAui*) there are better choices:

1. wxFormBuilder - http://sourceforge.net/projects/wxformbuilder/
This is my favourite wxWidgets designer, very powerful once you know how to use it
2. CodeLite with wxCrafter plugin - http://codelite.org/
3. wxDev-C++ - http://wxdsgn.sourceforge.net/
So, would installing wxWidgets interfere with my compiler setup?

note:

I have nuwen's distro, and I want to keep it, because I like boost.

________________________________________________________

EDIT:

I have decided to use wxWidgets.
Last edited on
So...

For wxWidgets:

There MUST be a few steps missing, like the part about there being no "configure" command on a windows operating system.... I'm reading the installation instructions and it's only for Unix OS'.

Also, it would appear that the include files and library files don't need to be "built", but then I'm no epert in "building" libraries....

Can someone please help me?

EDIT1:

Hold on, I just found a setup binary on the download page. I'll see what I can do with it.
Last edited on
That windows setup contains wxwidgets sources, you must build it from sources using the same compiler (nuwen or whatever)

Open a command prompt (your compiler most likely provide a batch file with environment already set up for you), go to %WXWIN%\build\msw\ and execute something like mingw32-make -f makefile.gcc

See the documentation for available options when building wxWidgets, located in %WXWIN%\docs\msw\install.txt
Last edited on
Do I always use my own compiler when building additional libraries?

I'm getting the sense that the libraries are somhow added to a perverbial 'resource pile' that it uses to... compile.

I know how the compiler works, as far as converting code into binary/parsing code, but where it gets it's sources from is where my knowledge ends...

Also, I do have MSYS installed alongside MinGW. :) (left over from my failed attempt to build Boost)
Last edited on
Ok, so far as I can tell:

wxWidgets build commands are crap: wrong commands, can't find files, BLAH BLAH BLAH

I'm about to give up.... this is ludicrous, it's like Boost all over again.

I followed the damn instructions TO THE LETTER and it wont fraking build.

I got the library from this link (I sifted through the (unecessary?) plethora of crap under their 2.8.12 version folder on sourceforge):
http://sourceforge.net/projects/wxwindows/files/2.8.12/wxMSW-2.8.12-Setup.exe/download

Next, I followed the instructions (to the best of my ability... withering as I grow exhausted of this seemingly futile attempt...) contained within the following subdirectory (entire thing extracted directly to "C:\wxWidgets-2.8.12", I renamed it as "C:\wxWidgets")

.\docs\msw

I followed them to the letter... all sorts of errors regarding incorrect executable names, not being able to find the damn compiler, blah blah blah blah....

I tried modifying configure.gcc, but that led to execution of files that had the same problems.... and THEN the part about no c compiler, WHICH IS JUST PLAIN WRONG.

Can someone please help me?

OS: Windows 8 (64-bit)
Compiler: MinGW (32-bit)
IDE: NetBeans

Is QT easier than this?
QT is a bit bloatware-ish.
It's a complete IDE on his own, and it's configured on his own, too.
Does anyone have an answer?

Also, is there another one out there that isn't a huge wall to climb? Quite honestly, I do not understand all this nonsense (why they force you to go through all this just to install a library).

My dad says he never had to build libraries (back in the DOS days (all text, no gui)). But that was a different time. Is ther SOME sort of standard set of instructions for building libraries I should be aware of? Is it all in the installation, or are there other factors I need to check?
Last edited on
Have you tried these instructions? http://wiki.wxwidgets.org/Compiling_wxWidgets_with_MinGW

Edit: Currently compiling with
make -f makefile.gcc SHARED=1 UNICODE=1 BUILD=release


Edit2: Build successful, *.a and *.dll are in
C:\wxWidgets-2.8.12\lib\gcc_dll


If you build it successfully you then need to set the include and lib directories and link to the libs in your IDE. I don't know netbeans so I can't help with that.
Last edited on
I followed them to the letter... all sorts of errors regarding incorrect executable names, not being able to find the damn compiler, blah blah blah blah....


You need the compiler to be in the PATH, does nuwen compiler you are using provide a special command prompt ? IF NOT, you must setup it manually first.


This is the cause to your problem, you will not be able to build any library until this step is done.

Also, I do have MSYS installed alongside MinGW. :) (left over from my failed attempt to build Boost)


Either Boost or wxWidgets can be build with or without MSYS, let's forget about MSYS for now on.


Also, is there another one out there that isn't a huge wall to climb? Quite honestly, I do not understand all this nonsense (why they force you to go through all this just to install a library).


A library is NOT intended for novice or end-users, is intended for developers, which (hopefully) know how a compiler and linker work.

However, there is prebuilt binaries for wxWidgets at https://github.com/rjpcomputing/wxpack/wiki
However, you cannot use it except with the same compiler as they used when build the binaries, now you hopefully understand why it is better to just build from source any C++ library :)

Is QT easier than this?


Until you understand how compilers and linkers works no, it is not easier.
modoran wrote:
... does nuwen compiler you are using provide a special command prompt ?...
It does,
C:\MinGW\open_distro_window.bat
Last edited on
Ah.

So, would putting a commond prompt into the compiler's directory also achieve this?

@naraku

I Did not know that that was what that was for... Thank you.

Also, no I did not try those instructions. I will try them.

---------------------------------------------------------------------------------------------------------

Also, I'm learning this on my own, so all help is appreciated. :)

I will ook up how compilers work.
Last edited on
Alright, I did a quick search, and what I got was mostly about how it compiles...

- What specifically should I look for?

- Also, do compilers come without a "special command prompt"? If so, how would I set mine up with it?

ps. I know how to write batch files, but... since I'm new to building libraries... yeah.
Last edited on
Pages: 123