Menu

WM_SETICON for dialog box does not work.

2003-12-03
2012-09-26
  • Øyvind Kaurstad

    I'm frustrated.

    In my code I am creating a dialog box with the DialogBox function.

    In the dialog box callback I have this code:

    case WM_INITDIALOG:
    {
       SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)(HICON)LoadIcon(hProgInst, MAKEINTRESOURCE(MAINICON)));
           
       return TRUE;
    }break;

    At some point in the past this worked just fine, and caused the program icon to be displayed in the upper left corner of the dialog box to the left of the caption.

    The code is unaltered, but at some point is stopped working, possible when I upgraded to MingW 3.2.

    Now nothing happens. I have of course checked that LoadIcon does return a valid icon handle, so that's not it.

    This is frustrating, since the dialog box looks much better with the icon in place.

     
    • Øyvind Kaurstad

      Holy cow!

      This almost always happens to me when I ask a question. A fem minutes later I solve my own question...

      Anyway, in case it can be of any use to anyone:

      For some reason the style WS_POPUPWINDOW had to be added to the style of the dialogbox for the icon to show in the title bar.

      I used to have this in the resource script:

      STYLE DS_CENTER | WS_POPUP | WS_CAPTION

      and the icon would show just fine.

      Now I need to have this:

      STYLE DS_CENTER | WS_POPUP | WS_CAPTION | WS_POPUPWINDOW

      to have the icon show in the title bar.

      I don't know why, and I don't care, but it is a bit strange...

       
    • Jack Black

      Jack Black - 2003-12-03

      Out of interest why do you have this paramter?

      (LPARAM)(HICON)LoadIcon(hProgInst, MAKEINTRESOURCE(MAINICON))

      You are casting a cast? Pointless?  Try

      (LPARAM)LoadIcon(hProgInst, MAKEINTRESOURCE(MAINICON))

      BlakJak :]

       
      • Kip

        Kip - 2003-12-03

        Blakjak, this is common in win32. It is for code clarity.

        Kip

         
    • aditsu

      aditsu - 2003-12-03

      msdn says:
      WS_POPUPWINDOW
          Creates a pop-up window with WS_BORDER, WS_POPUP, and WS_SYSMENU styles. The WS_CAPTION and WS_POPUPWINDOW styles must be combined to make the window menu visible.
      WS_SYSMENU
          Creates a window that has a window menu on its title bar. The WS_CAPTION style must also be specified.

      I think the icon you want is the window menu, and you need both WS_SYSMENU and WS_CAPTION for that; WS_POPUPWINDOW includes WS_SYSMENU and WS_POPUP, so you can probably use:
      DS_CENTER | WS_CAPTION | WS_POPUPWINDOW
      or
      STYLE DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU

      why it worked before? possibly a bug in the old windres (or in the constant values)

      Adrian

       
    • Øyvind Kaurstad

      @BlakJak:

      The double cast was just one of the stupid things I tried to correct the problem. I didn't think it would work (or even have a purpose), but I was getting desperate... :-)

      For the record, the double cast wasn't there originally, and it isn't there now...

      @Adrian:

      Yes, you are probably correct that there was a bug in the older windres that caused my code (which also had a bug) to work. My error was actually concealed by the windres bug. :-)

      Thanks to both of you!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.