Storing mutable data in global variables is usually a bad idea (like not using the power of .cpp) but we will look over that this time. Currently you have a data that is changed by somebody, and there are some listeners ('observers') who want to know about the change (in this case it is your window). For this reasony you should eliminate the direct access to your
double Ask;
variable by hiding it from other .cpp files by making it static and creating "getter" and "setter" functions for its use:
static double Ask;
double GetAsk()
{
return Ask;
}
void SetAsk(double ask)
{
Ask = ask;
}
Now you get a lot of compiler errors if you are writing the
Ask
variable from other .cpp files and you are be forced to change the
Ask
variable by calling
SetAsk()
. The
SetAsk()
method can now notify your dialog about the change. You should make the
HWND
of the dialog visible to your
SetAsk()
method to allow it to use
PostMessage()
for example with a
WM_APP+XXX
custom message to notify the dialog to refresh its own titlebar. Inside the dialog you should handle
WM_APP+XXX
of course with the code you currently use for your button handling. To start the window immediately with a correct titlebar your should execute the refersher code not only from your
WM_APP+XXX
handler but also from your
WM_INITDIALOG
handler.
Note that things could look much nicer in real C++ if both your window and the value resided in their own objects. The window could 'register' itself into the object of the value as a listener then instead of using global variables for communication.