Noob question about c++ CreateWindow ()

Thread Starter

ArakelTheDragon

Joined Nov 18, 2016
1,366
Hi!

I have just started trying to program in "C++" since I know "C" but its not for GUI. All my functions are made in "C", only the needed part for the graphics are in "C++".

I have a static text box in "case WM_CREATE:":
Code:
  hStaticTextBox = CreateWindow ("STATIC",
  "Results, also included in 'Report.txt':",
  WS_BORDER | WS_CHILD | WS_VISIBLE,
  10, 40, 400, 250,
  hwnd,
  (HMENU) 2, NULL, NULL);
How do I make it after the results are calculated, to be displayed on the static text box, perhaps by usign "case WM_COMMAND:", any examples are appreciated!
 

402DF855

Joined Feb 9, 2013
271
Would you consider using MFC (Microsoft Foundation Classes) which wraps the Win32 API in a C++ framework that is a whole lot easier to work with?
 

Thread Starter

ArakelTheDragon

Joined Nov 18, 2016
1,366
Would you consider using MFC (Microsoft Foundation Classes) which wraps the Win32 API in a C++ framework that is a whole lot easier to work with?
I don't want to start a new approach, I just started working with this one. I know absolutely nothing about your approach, can you explain?
 

402DF855

Joined Feb 9, 2013
271
Before MFC (and Visual Basic etc.) one would write a Windows GUI app using C and the Win32 API. It's been so long since I used C for this, but there was a WinMain and humongous switch statements; all very untidy in hindsight. Then Microsoft came along with MFC, which is a C++ framework that goes a long way to modularizing and simplifying the GUI development process.

But if you are not willing to use C++ then the approach you are taking is reasonable. It seems like you are trying to change the text displayed in a static text box. In MFC this would look like:

C:
void CMyDialog::OnBnClickedOk()
{
    m_pMyStaticBox->SetWindowText("Hello!");
}
In this case, the user pushed the OK button on the dialog and the framework does all the message passing behind the scenes so that I as the developer only have to add the call to set the text. I suspect in C you would use the Win32 API SetWindowText(handle,string) to do the same thing, but you have to plumb all the message passing to get there.

So if you are interested in learning C++ (if you don't know it yet) and also in being able to develop apps relatively quickly I'd recommend the C++ approach. It's simpler, and faster.
 

Thread Starter

ArakelTheDragon

Joined Nov 18, 2016
1,366
I don't know if I have the strength to learn C++ also at the moment.

As for the rest, I had a static text box inside of the main window, not as a pop-up, as pop-up its not a problem to make it work. Its rather simple also, but you are right about the enormous switch statements.

Code:
::MessageBox (hwnd, sStr , "Report.txt", MB_OK);  /* MB_OK == Message box with button "OK" only. */
 

Tesla23

Joined May 10, 2009
560
Hi!

I have just started trying to program in "C++" since I know "C" but its not for GUI. All my functions are made in "C", only the needed part for the graphics are in "C++".

I have a static text box in "case WM_CREATE:":
Code:
  hStaticTextBox = CreateWindow ("STATIC",
  "Results, also included in 'Report.txt':",
  WS_BORDER | WS_CHILD | WS_VISIBLE,
  10, 40, 400, 250,
  hwnd,
  (HMENU) 2, NULL, NULL);
How do I make it after the results are calculated, to be displayed on the static text box, perhaps by usign "case WM_COMMAND:", any examples are appreciated!
If you want to program Windows using C, search for"Programming Windows" by Charles Petzold, it's the old bible for programming Windows, and you will probably find a pdf on the web.
 

spinnaker

Joined Oct 29, 2009
7,830
I don't know if I have the strength to learn C++ also at the moment.

As for the rest, I had a static text box inside of the main window, not as a pop-up, as pop-up its not a problem to make it work. Its rather simple also, but you are right about the enormous switch statements.

Code:
::MessageBox (hwnd, sStr , "Report.txt", MB_OK);  /* MB_OK == Message box with button "OK" only. */

Sorry but if you wan to survive in Windows development, you pretty much need to learn C++, C# or VBASIC. I don't know if anyone codes at the API level anymore.
 

Thread Starter

ArakelTheDragon

Joined Nov 18, 2016
1,366
Sorry but if you wan to survive in Windows development, you pretty much need to learn C++, C# or VBASIC. I don't know if anyone codes at the API level anymore.
Don't take it personal all of you, I appreciate your opinion and help, but you are assuming too much.

I don't need this to be a developer, maybe at some point that will be necessary, but for now I am just making programs for myself and I prefer not to use the command line, but to use the GUI, although I don't see any advantages, actually I think its worst.

Also I see simple programs like "7-zip", and others, which do not require enourmous amounts of resources and work very well. And these small programs and custom tools which I can build are very useful to me. Its like the program I always needed but never had without the junk and bloatware.

EDIT:
Thanks for the book, its looks very useful, like the "Kernighan and Ritchie C" book edition 2.
 
Last edited:
Top