0

I'm working on a program that disables Windows Explorer. I did it before in Python, but when I build it in C it is faster to start the program.

I want the buttons to look elegant, like the title text style and font. How do I make the text of the buttons look nice? I hope you can help me.

image of the program and the buttons

My code:

#include <windows.h>
#define ID_BTNHI0 0
#define ID_BTNHI1 1
#define ID_BTNHI2 2

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 = "MICLASE";
    class_.lpszMenuName = NULL;
    class_.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
    
    if(!RegisterClassEx(&class_)){
        MessageBox(NULL, "NON", "ERROR", MB_ICONERROR);
        return EXIT_FAILURE;
    }
    
    hWnd = CreateWindowEx(0, "MICLASE", "Windows Explorer Toggle", 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 hBtn0;
HWND hBtn1;
HWND hBtn2;

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
    switch(msg){
        case WM_CREATE:{
            hBtn0 = CreateWindow("BUTTON", "Disable Windows Explorer", WS_VISIBLE | WS_CHILD | BS_FLAT, 82.5, 24.5, 175, 22.5, hWnd, (HMENU)ID_BTNHI0, GetModuleHandle(NULL), NULL);
            //SetFocus(hBtn0);
            hBtn1 = CreateWindow("BUTTON", "Enable Windows Explorer", WS_VISIBLE | WS_CHILD | BS_FLAT, 82.5, 24.5, 175, 22.5, hWnd, (HMENU)ID_BTNHI1, GetModuleHandle(NULL), NULL); 
            ShowWindow(hBtn1, SW_HIDE);
            hBtn2 = CreateWindow("BUTTON", "Open Folder", WS_VISIBLE | WS_CHILD | BS_FLAT, 82.5, 48, 175, 22.5, hWnd, (HMENU)ID_BTNHI2, GetModuleHandle(NULL), NULL);
            break;
        }
        case WM_COMMAND:{
            switch(LOWORD(wParam)){
                case ID_BTNHI0:{
                    system("TASKKILL /F /IM explorer.exe");
                    //clase.hIcon = LoadImage(NULL, "icoff.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
                    //clase.hIconSm = LoadImage(NULL, "icoff.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
                    ShowWindow(hBtn0, SW_HIDE);
                    ShowWindow(hBtn1, SW_SHOW);
                    //SetFocus(hBtn1);
                    break;
                }
                case ID_BTNHI1:{
                    system("start %SystemRoot%\\explorer.exe");
                    //clase.hIcon = LoadImage(NULL, "icon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
                    //clase.hIconSm = LoadImage(NULL, "icon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
                    ShowWindow(hBtn1, SW_HIDE);
                    ShowWindow(hBtn0, SW_SHOW);
                    //SetFocus(hBtn0);
                    break;
                }
                case ID_BTNHI2:{
                    system("start .");
                    //SetFocus(hBtn0);
                    break;
                }
            }
            break;
        }
        case WM_DESTROY:{
            PostQuitMessage(0);
            break;
        }
        default:{
            return DefWindowProc(hWnd, msg, wParam, lParam);
        }
        
    }
    return 0;

}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Pan
  • 3
  • 3

1 Answers1

1

You need to get rid of the BS_FLAT window style on the buttons, and also enable ComCtrl32 v6.0 Visual Styles for your program, if you haven't already. Then the buttons will have a modern look.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • You failed to understand the problem, first of all the button code already uses "BS_FLAT", and that's why it looks like that, and even if you activate the visual styles, the text is still seen with that style, the problem is not the button, is the text inside the button. – Pan Feb 08 '21 at 21:33
  • "*You failed to understand the problem*" - then that was your fault for not explaining it clearly enough. "*the button code already uses "BS_FLAT"*" - I know, and I'm saying to *get rid* of that, so the buttons have a more modern 3d look instead. "*if you activate the visual styles, the text is still seen with that style*" - the button text will take on the font and styling of the active theme, which is what it should be doing. – Remy Lebeau Feb 08 '21 at 22:20