Windows 7 Theme isn't being applied to my simple win32 program.

Sep 2, 2013 at 11:01am
Hey guys,

I am just starting to learn how to program with the win32 API so that I can make some GUI's for my programs instead of having them all just be console applications. So far everything has been going well, but now that I am starting to add controls I have noticed that they are not in the windows 7 theme.

Here is a simple program that I created to make a window with a button on it. The window has the look of a windows 7 window however the button does not.

I am currently using Code::Blocks 12.11 with the GNU GCC Compiler and my operating system is Windows 7.


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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <windows.h>

#define IDC_BUTTON_1 101

const char g_ClassName[] = "windowClass";

LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch(uMsg) {
        case WM_CREATE: {
            HWND hwndButton1 = CreateWindowEx(NULL,
                "BUTTON",
                "Click Me",
                WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_PUSHLIKE, // | BS_FLAT,
                50, 220, 100, 24,
                hwnd,
                (HMENU)IDC_BUTTON_1,
                GetModuleHandle(NULL),
                NULL);

            if (hwndButton1 == NULL) {
                MessageBox(NULL, "FAILURE Creating button 1", "ERROR!", MB_OK | MB_ICONWARNING);
                return 0;
            }
        }
        break;
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) {
HWND hwndMain;
WNDCLASSEX wc;
MSG Msg;

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = MainWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_ClassName;
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

if (!RegisterClassEx(&wc)) {
    MessageBox(NULL, "Failed to register window class!", "ERROR!", MB_OK | MB_ICONWARNING);
    return 0;
}



hwndMain = CreateWindowEx(
    WS_EX_CLIENTEDGE,
    g_ClassName,
    "Controls Test",
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, 500, 500,
    NULL, NULL, hInstance, NULL);



if (hwndMain == NULL) {
    MessageBox(NULL, "Failed to create window!", "ERROR!", MB_OK | MB_ICONWARNING);
    return 0;
}

ShowWindow(hwndMain, nCmdShow);
UpdateWindow(hwndMain);

while (GetMessage(&Msg, NULL, 0, 0) > 0) {
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
}
}


Does anyone know why this is happening or how to fix it? Any help would be appreciated!

Thanks!
Last edited on Sep 2, 2013 at 11:01am
Sep 2, 2013 at 3:29pm
Sep 2, 2013 at 8:44pm
Thank you so much! This worked amazingly.
Last edited on Sep 2, 2013 at 8:44pm
Topic archived. No new replies allowed.