-1

i need a modern style for my program. The default style is similar to Windows Vista and i want a modern style like Windows 10!!! Please Help :(( In python i can solve this easly with tkinter, only need "from tkinter.ttk import * " for a modern style of the widgets, but in C i can not solve this, i missing a solution for this problem in long time but my english level don't help me jajaja... and i really need help with this. image of i want

Here my example code:

#include <windows.h>
#define ID_BTNHI 0

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

WNDCLASSEX class_;

int WINAPI WinMain(HINSTANCE hInstanciaAct, HINSTANCE hInstanciaPrev, LPSTR IpCmdLine, int iCmdShow){
    
    ShowWindow(GetConsoleWindow(), SW_HIDE);
    
    HWND hWnd;
    MSG msg;
    
    class_.cbSize = sizeof(WNDCLASSEX);
    class_.cbWndExtra = 0;
    class_.cbClsExtra = 0;
    class_.style = CS_HREDRAW|CS_VREDRAW;
    class_.lpfnWndProc = WndProc;
    class_.hInstance = hInstanciaAct;
    class_.hIcon = LoadImage(NULL, "icoff.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
    class_.hIconSm = LoadImage(NULL, "icoff.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
    class_.hCursor = LoadCursor(NULL, IDC_ARROW);
    class_.lpszClassName = "MYCLASS";
    class_.lpszMenuName = NULL;
    class_.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
    
    if(!RegisterClassEx(&class_)){
        MessageBox(NULL, "NON", "ERROR", MB_ICONERROR);
        return EXIT_FAILURE;
    }
    
    hWnd = CreateWindowEx(0, "MYCLASS", "Folder Open", WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 340, 140, HWND_DESKTOP, NULL, hInstanciaAct, NULL);
    if(hWnd == NULL){
        MessageBox(NULL, "NON2", "ERROR", MB_ICONERROR);
        return EXIT_FAILURE;
    }
    
    ShowWindow(hWnd, iCmdShow);
    UpdateWindow(hWnd);
    
    while(GetMessage(&msg, NULL, 0, 0) > 0){
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    
    return msg.wParam;
}

HWND hBtn;

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
    switch(msg){
        case WM_CREATE:{
            hBtn = CreateWindow("BUTTON", "Open Folder", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 82.5, 48, 175, 22.5, hWnd, (HMENU)ID_BTNHI, GetModuleHandle(NULL), NULL);
            break;
        }
        case WM_COMMAND:{
            switch(LOWORD(wParam)){
                case ID_BTNHI:{
                    system("start .");
                    break;
                }
            }
            break;
        }
        case WM_DESTROY:{
            PostQuitMessage(0);
            break;
        }
        default:{
            return DefWindowProc(hWnd, msg, wParam, lParam);
        }
        
    }
    return 0;

}
Pan
  • 3
  • 3

1 Answers1

2

You have two ways to modify the button style, both of which need to enable the visual style

If you are using Microsoft Visual C++ 2005 or later, you can add the following compiler directive to your source code instead of manually creating a manifest. For readability, the directive is broken into several lines here.

So, you can select YES (/MANIFEST) in Properties->Linker->Manifest->Generate Manifest and add the following compiler directive:

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

Also, you can add a manifest file in Properties->Manifest Tool->Input and Out->Additional Manifest Files

enter image description here

The content of the manifest file is as follows:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
    <application>
      <!--The ID below indicates app support for Windows 10 -->
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
    </application>
  </compatibility>
  <dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
  </dependency>
</assembly>

Both methods works for me:

enter image description here

Zeus
  • 3,703
  • 3
  • 7
  • 20