Windows 7 looking Buttons

Pages: 12
I am working on a program and i would like the buttons to have a Windows 7 look, i found this code to do it but i add it to my program and it doesnt work, it compiles just fine but doesnt do anything.

Button change code:

1
2
3
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 


Main.cpp:

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include "resource.h"
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")


HINSTANCE hInst;

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{



    switch(uMsg)
    {
        case WM_INITDIALOG:
            //Blank
            return TRUE;

        case WM_CLOSE: // If the user clicks the X to close the dialog box
            EndDialog(hwndDlg, 0);
            return TRUE;

        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case IDC_BTN_QUIT:
                    EndDialog(hwndDlg, 0);
                    return TRUE;

                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //MB_ICONINFORMATION is the type of icon displayed in the window that pops up. There is also//
                //MB_ICONHAND, MB_ICONSTOP, or MB_ICONERROR - Error Icon                                           //
                //MB_ICONQUESTION - Question mark Icon                                                                          //
                //MB_ICONEXCLAMATION or MB_ICONWARNING - Exclamation Icon                                       //
                //MB_ICONASTERISK or MB_ICONINFORMATION - Asterisk Icon                                            //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////

                case IDC_BTN_TEST:
                    MessageBox(hwndDlg, "Your computer will now crash because you suck.", "Information", MB_ICONERROR);
                    return TRUE;

                case IDC_BTN_TESTBTN2:
                    MessageBox(hwndDlg, "Rated Argh for pirates fuck you.", "Information", MB_ICONWARNING);
                    return TRUE;

                case Button:
                    MessageBox(hwndDlg, "Test Button 2", "Information", MB_ICONINFORMATION);
                    return TRUE;
            }
    }

    return FALSE;
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst = hInstance;



    // The user interface is a modal dialog box
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}


Resource.rc:

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
36
37
38
39
40
41
42
43
44
45
#include "resource.h"

//6 is the X position of the dialog box on the screen
//5 is the Y position of the dialog box on the screen
//304 is the width of the dialog box
//206 is the height of the dialog box

DLG_MAIN DIALOGEX 6, 5, 304, 206

CAPTION "Project Manager" //Title of the window

FONT 8, "Ariel" //Font size (8) and type (Tahoma)

STYLE 0x10CE0804

//138,  5, 46, 15
//138 is the X position of the button, Left and right
//5 is the Y position of the button, Up and down
//46 is the buttons length
//15 is the buttons height
//&Test is the name of the button
//IDC_BTN_TEST is the name of the defined keyword in resource.h

/*
BEGIN
  CONTROL "&Test", IDC_BTN_TEST, "Button", 0x10010000, 138,  5, 46, 15
END
*/

//CTEXT - Places text in the window, but not a text box.
//PUSHBUTTON - Similar to CONTROL
//RADIOBUTTON - Creates a Radio Button
//CHECKBOX - Creates a checkbox


BEGIN
  CTEXT "Project Manager Version 1.0.0", IDC_STATIC, 113, 0, 100, 15
  CONTROL "&Test", IDC_BTN_TEST, "Button", 0x10010000, 138,  15, 46, 15
  CONTROL "&Quit", IDC_BTN_QUIT, "Button", 0x10010000, 138, 49, 46, 15
  CONTROL "&Button", IDC_BTN_TESTBTN2, "Button", 0x10010000, 138, 32, 46, 15
  GROUPBOX "GroupBox", IDC_STAT2, 25, 5, 100, 50
  PUSHBUTTON "HI", Button, 50, 25, 46, 15
  RADIOBUTTON "Radio Test", RadioB, 138, 88, 50, 50
  CHECKBOX "Checkbox", CheckB, 138, 120, 42, 50
END


Resource.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <windows.h>

// ID of Main Dialog
#define DLG_MAIN 101

// ID of Button Controls
#define IDC_BTN_TEST 1001
#define IDC_BTN_QUIT 1002
#define IDC_BTN_TESTBTN2 1003
#define IDC_STATIC 1004
#define IDC_STAT2 1005
#define Button 1006
#define RadioB 1007
#define CheckB 1008
#define MI 1009
#define listbox 1010 
Do you have windows 7 installed?
Yes thats the os that came with my laptop.
What compiler do you use ? Only Visual Studio understands that pragma directive.
I use code blocks.
Then you must use a manifest file to enable visual styles. Codeblocks comes with a resource compiler.
Add the following line to your .rc file:
1 24 "styles.manifest"

The styles.manifest file contains what you wrote in pragma directive, without quotes and escaping.
Where do i put it? there is a keyword called STYLE and it has 0x10CE0804 after it do i need to change that?
Bump
more easy will be installing visual studio express.
all problems solved :D
What will that solve? I have visual studio 2010 but I want to use code blocks instead.
Sorry, maybe that sounds stupid but I don't rely see the reason why would someone prefer code::blocks over VS.

I've never use code::blocks except on linux machine so I just don't get it.

cheers!
Isnt visual studio more visual stuff anyways? like making windows and chckboxes and buttons?
Yeah, that's why it is so cool.
nice GUI enviroinment.

Thats the thing though, i dont want to cut corners, i want to do it myself, how will i learn Windows API if i Use Visual Studio?
Visual Studio express has nothing "visual" in it, does not have a GUI editor if this is what you mean.
Payed versions does come with a rudimentary resource editor, but there are free resource editors out there which can be used with codeblocks too like ResEdit.
add this on top of your main.cpp
1
2
3
4
#define _WIN32_WINNT  0x0501
#define  WINVER       0x0501
#define _WIN32_IE     0x0600
#include <commctrl.h> 


add this to your resource.rc
1 24 "manifest.xml"

make manifest.xml and put this in it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
    version="1.0.0.0"
    processorArchitecture="*"
    name="CompanyName.ProductName.YourApplication"
    type="win32"
/>
<description>Your application description here.</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>


add manifest.xml to your project and link your project to comctl32.
more info here http://msdn.microsoft.com/en-us/library/windows/desktop/bb773175%28v=vs.85%29.aspx

good luck!!

[edit]
BTW, I also recommend you try ResEdit just like modoran.
Last edited on
There isnt a simpler way? I mean my OS is windows 7. I mean it doesnt have to be Windows 7 buttons, i just want to make them look a little better than they are now, they look like Windows 95 or Windows XP buttons. Kind of bland, is there any site that can show me how to change buttons style? also something i have been wondering what is this doing to the code?

STYLE 0x10CE0804

What is style? and what is the stuff after it?

Also can you give me a link to the different Resource.rc keywords, i want to see what all different ones there are. These are the words im talking about, i want to see what different kinds there are:

CTEXT
CONTROL
GROUPBOX
PUSHBUTTON
AUTORADIOBUTTON
AUTOCHECKBOX
Last edited on
There isnt a simpler way?

Yes, I don't think there is a simplier way.

wondering what is this doing to the code?
STYLE 0x10CE0804

It declares window style.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa381051%28v=vs.85%29.aspx

Also can you give me a link to the different Resource.rc keywords, i want to see what all different ones there are.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa381043%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa380599%28v=vs.85%29.aspx


And I forgot, you should add this code to your WinMain function before any other code.
1
2
3
4
5
INITCOMMONCONTROLSEX iccx;
iccx.dwSize=sizeof(INITCOMMONCONTROLSEX);
iccx.dwICC=ICC_ANIMATE_CLASS;
InitCommonControlsEx(&iccx);
hInst = hInstance;


Here's a sample project I made.
http://uploading.com/files/118e2aam/test000.zip/
Sweet thanks :D ive been looking it all over for a while now and i found an edit control keyword but dont know how to get it to work? I also cant get the menu bar to work either, the info they had on them wast all that helpful.

This is what i have in my Resource.rc:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


BEGIN
  CTEXT "Project Manager Version 1.0.0", IDC_STATIC, 113, 0, 100, 15
  CONTROL "&Test", IDC_BTN_TEST, "Button", 0x10010000, 138,  15, 46, 15
  CONTROL "&Quit", IDC_BTN_QUIT, "Button", 0x10010000, 138, 49, 46, 15
  CONTROL "&Button", IDC_BTN_TESTBTN2, "Button", 0x10010000, 138, 32, 46, 15
  GROUPBOX "GroupBox", IDC_STAT2, 25, 5, 100, 50
  PUSHBUTTON "HI", Button, 50, 25, 46, 15
  AUTORADIOBUTTON "Radio Test", RadioB, 138, 88, 45, 10
  AUTORADIOBUTTON "Radio Test2", RadioB2, 138, 97, 50, 10
  AUTOCHECKBOX "Checkbox", CheckB, 138, 107, 42, 10
  EDITTEXT "This is a dialog box", DialogBox, 0, 156, 50, 50
  MENU MenuBar, 138, 107, 42, 10
END
Please help!
Pages: 12