Pelles C forum

C language => Windows questions => Topic started by: Snowman on March 31, 2015, 03:42:15 PM

Title: Mystery code in Dialog-based-app template
Post by: Snowman 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:
Title: Re: Mystery code in Dialog-based-app template
Post by: jj2007 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
Title: Re: Mystery code in Dialog-based-app template
Post by: frankie 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:
Title: Re: Mystery code in Dialog-based-app template
Post by: Snowman 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.)