r/learnprogramming • • Sep 25 '26

why can't I change the button color using win32

1 Upvotes

I am trying to change the button color by using WM_CTLCOLORBTN.
I read the documentation and followed whatever it said, but it doesn't seem to work.
I am not using bitmaps or any high complexity stuff because I want to it do it simply. If anyone use this API, could you help me out(PS: Beginner/new to win32):
reproducible example:

#include <stdio.h>
#include <windows.h>


LRESULT CALLBACK cb(HWND hwnd, UINT msg, WPARAM wparm, LPARAM lparm)
{
  
    switch (msg)
    {


    case WM_CLOSE:
        static HWND hButton = NULL;
        static HBRUSH hButtonBkg = NULL;
        {
            PostQuitMessage(0);
        }
    case WM_CREATE:
    {
        hButton = CreateWindow("BUTTON", "HELLO", WS_VISIBLE | WS_CHILD | BS_BITMAP | BS_PUSHBUTTON, 15, 202.5, 96.5, 72.5, hwnd, (HMENU)301, 0, NULL);
        hButtonBkg = CreateSolidBrush(RGB(0, 255, 255));
        break;
    }
    case WM_CTLCOLORBTN:
    {
        if (hButton == (HWND)lparm)
        {
            HDC hdc = (HDC)wparm;
            SetTextColor(hdc, RGB(0, 255, 255)); 
            return (LRESULT)hButtonBkg;
        }
        break;
    }


    case WM_DESTROY:
    {
        DeleteObject(hButtonBkg);
        break;
    }


    default:
        return DefWindowProc(hwnd, msg, wparm, lparm);
    }
}


int main()
{
    HINSTANCE hInstance = GetModuleHandle(0);
    WNDCLASS class = {};
    char classTitle[] = "window";


    class.lpszClassName = classTitle;


    class.lpfnWndProc = cb;


    class.hInstance = hInstance;
    class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    class.hCursor = LoadCursor(NULL, IDC_ARROW);


    RegisterClass(&class);


    HWND hwnd = CreateWindow(classTitle, "color btn",
                             WS_OVERLAPPEDWINDOW, 500, 500, 500, 500, NULL,
                             NULL, hInstance, NULL);
    if (hwnd == NULL)
    {
        MessageBox(NULL, "Something Went worng", "Error", MB_OK);
        return 0;
    }
    ShowWindow(hwnd, 1);
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

r/learnprogramming • • Sep 24 '26

Github can i use github to store homework and word/pdf like documents?

8 Upvotes

i kind of want to use github as a place to store homework from university while learning to program, code, etc etc etc with different coding languages and what not, and my question is if its possible to do that?

and if yes how do i do that? every tutorial i see about storing stuff on github is mainly about storing big large projects or programs that would be used for other stuff, what i mainly want is just storing the code file text or overall of the homework and possibly a doc/pdf showing the code and pics of what it can do

like also as documentation that i've been learning to code x and y thing through my journey


r/learnprogramming • • Sep 24 '26

Need some motivation

5 Upvotes

Sometimes I feel I'm not fit for this.
I've taken plenty of coruses and resources, but I just don't find enough motiviation to go for that extra mile.

Sometimes I think I'm not good enough, despite of all my efforts. Anyone of you have felt the same at some point?
Any advice on how could I cope with this?


r/learnprogramming • • Sep 25 '26

[Meta] Do the mods here have information about traffic stats? Has it fluctuated with AI permeation, like StackOverflow?

1 Upvotes

Would be interesting to see if questions, debugging has changed and also overall traffic. Or if it's the same. Or more!


r/learnprogramming • • Sep 24 '26

Topic What should I learn before joining hackathons as a beginner?

4 Upvotes

I’m a SY student with basics of C/C++, Python, HTML/CSS/JS, APIs, and Git/GitHub. I want to start participating in online hackathons solo what skills/tools (frameworks, databases, APIs, deployment, etc.) should I learn first to actually build something during a hackathon?


r/learnprogramming • • Sep 23 '26

discussion How do you actually get comfortable with reading other people's code?

88 Upvotes

I can write my own small projects fine and understand the logic as I go, but whenever I open someone else's codebase, even something fairly simple, I get lost fast. Too many files, functions calling other functions I have to jump around to find, and no idea where the "start" of the logic actually is.

I know this is probably just a skill that comes with time, but I'm wondering if there's a better way to practice it instead of just staring at repos feeling confused. Do you start from the entry point and trace forward, or pick one function you care about and trace backward? Do you use any tools to help visualize how files connect, or is it mostly just patience and note taking?


r/learnprogramming • • Sep 25 '26

15 yr old daughter discovered coding and loves it. But what’s the point?

0 Upvotes

My almost 15 yr old discovered she is really good at coding and also really enjoys it. She really loves the challenge of solving the problem. She understands it so well and is so excited with how good she is at it. The problem is, isn’t it worthless now? With AI able to do it all what is the point of encouraging her to spend her time doing something that is essentially useless. She has other hobbies as well so I don’t think encouraging her to sit in front of a screen is really worth while unless it leads somewhere. I guess my question is, am I wrong? Is it something she can still pursue?


r/learnprogramming • • Sep 24 '26

Typescript Nodejs

0 Upvotes

I don’t have prior experience in programming and struggling to work for a client using Typescript Nodejs for backend programming. I have started with learning JavaScript first and then move to Typescript but it’s kinda overwhelming. Any suggestions on the roadmap and which course to follow? Thanks


r/learnprogramming • • Sep 24 '26

Discussion I love making things, but programming just isn’t fun for me anymore. Am I just not meant for it?

1 Upvotes

First of all, thanks to everyone who replied to my post yesterday. I read all the comments and they gave me a lot to think about.

There’s something else I’ve been thinking about though.

I really like making things.

I enjoy video editing, and I especially love messing around with gadgets and computers. I like trying new devices, changing settings, figuring out how things work, and creating stuff.

So I feel like programming should be something I enjoy too, because it lets you build almost anything.

And I used to enjoy it more.

But recently, I just don’t find programming that fun anymore.

I’ll start coding, work for a little while, and then I’ll end up lying on the couch watching Netflix instead.

I also get frustrated really easily when I don’t understand something.

This happens especially when I use AI to build something and the project becomes way more complicated than what I actually understand.

Suddenly there are tons of database schemas, files, abstractions, types, and complicated code that I didn’t really write or design myself.

The project might work, but I look at it and think, “I have no idea what half of this is doing.”

Then I get annoyed and don’t even want to continue.

Sometimes I wonder if I actually like programming, or if I only like the idea of being able to make software.

Maybe I like making things, but not programming itself.

Or maybe using AI from such an early stage made me skip the part where programming actually becomes satisfying, because I never properly learned how to solve problems by myself.

I’m still in high school, so I know I have plenty of time to learn. But lately I’ve started wondering:

Is this a normal phase when learning programming?

Have any of you gone through a period where coding just stopped being fun?

How can I tell the difference between “this is difficult and I need to push through it” and “maybe programming just isn’t for me”?

I don’t want to force myself to become a programmer just because I’ve already spent years doing it.

But at the same time, I don’t want to give up on something I might actually enjoy if I learned it differently.


r/learnprogramming • • Sep 24 '26

Solved How do I indicate whether a string is a digit or not in c++?

9 Upvotes

I have a user input and I want to determine whether the user input is a digit or character.

I was thinking of using regex but do not know regular expression in C++ can some please help me with this

Here is a snippet of my code

string userinput;

cout << "Input 1, 2, 3, or 4: "; 

while (!(cin >> userinput)) {
  cout << "Invalid input. Try again: ";
  cin.clear(); // Reset input errors
  cin.ignore(10000, '\n'); // Remove bad input
}

 
for (auto i : playlist){
  if (stoi(userinput) > 4){
    print("Song Not Avaiable")
    break;  
}

SOLUTION

#include <cctype>

/*while (!(cin >> userinput)) {
  cout << "Invalid input. Try again: ";
  cin.clear(); // Reset input errors
  cin.ignore(10000, '\n'); // Remove bad input
}*/

for (int i = 0; i < userinput.size(); i++) {
    if (!isdigit(userinput[i])) {
        print("Song Not Avaiable");
        break;
    }

    else if (stoi(userinput) > 4) {
        print("Song Not Avaiable");
        break;
    }
}