NO

Author Topic: Mystery code in Dialog-based-app template  (Read 3328 times)

Snowman

  • Guest
Mystery code in Dialog-based-app template
« on: March 31, 2015, 03:42:15 PM »
Hello. By creating a "simple dialog based application", code for WinMain is generated.
Inside WinMain the following lines of code can be found:

Code: [Select]
    /* Get system dialog information */
    wcx.cbSize = sizeof(wcx);
    if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
        return 0;

Questions:
  • Why is the 32770 magic number used?
  • What does the if statement check?

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: Mystery code in Dialog-based-app template
« Reply #1 on: March 31, 2015, 04:59:55 PM »
It checks the presence of the dialog class.

Quote
#32770   The class for a dialog box.
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633574%28v=vs.85%29.aspx

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: Mystery code in Dialog-based-app template
« Reply #2 on: March 31, 2015, 06:43:57 PM »
Questions:
  • Why is the 32770 magic number used?
  • What does the if statement check?

As already said by JJ #32770 is the name of the dialog windows class. Because you want create such kind of window you'll use the function GetClassInfoEx to get all class informations to use for our new window.
To be sure that we get correct class data we have to check which value is returned from the function. GetClassInfoEx returns 0 if it fails (class data is not valid) or a value>0 if success.
The form:
Code: [Select]
if (something)in C is TRUE if something <>0. The estended form should be:
Code: [Select]
if (something != 0)Which is equivalent to the former.
The operator ! negates the logical value: TRUE became FALSE and the reverse. So:
Code: [Select]
    if (!GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx))
        return 0;
Works this way:
  • Executes the function
  • Invert the result of function (fail becomes TRUE)
  • if function fails exit program with vallue 0 (return 0;)
« Last Edit: March 31, 2015, 06:48:21 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Snowman

  • Guest
Re: Mystery code in Dialog-based-app template
« Reply #3 on: April 04, 2015, 11:44:53 AM »
Thanks for your replies. (I know this post is a bit pointless but this forum has no "Thanks" button.)