Thread: 2 Window Problems

  1. #1
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223

    2 Window Problems

    1. I would like to change the opacity of the main window. I have found this article on Layered Window and have tried the example of "making a dialog box come up as a translucent window". Even when I put the following code (directly from the example):
    Code:
    		// Set WS_EX_LAYERED on this window
    		SetWindowLong(hwndDlg, GWL_EXSTYLE, GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_LAYERED);
    		// Change opacity of window
    		SetLayeredWindowAttributes(hwndDlg, 0, (255 * 80) / 100, LWA_ALPHA);
    into WM_INITDIALOG, the window comes up hidden or something. Note: It is fine when I take the code out and also I am not having this problem:
    http://cboard.cprogramming.com/.../t-9281.html
    I think it is to do with handling WM_PAINT, a message which I have ignored and don't know how to use (as of yet). I try putting in WM_PAINT and make it always return straight away and the opacity stays at 100% and all the window controls are missing, waht's up with that?

    2. Just Woundering, is it possible to make a child window at runtime? (e.g. Use CreateWindow instead of DialogBox(..., MAKEINTRESOURCE(IDD_RUNDIALOG), ...). I know how to create a child window from a resource using the DialogBox(...) method, but not the other way. The main downfall is that windows created from resources can't be resized (in my experience anyway, & I really like to resize windows). If it is possible to use CreateWindow please say how, as I'm stumped on this issue (and the above one too). Thanks.
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    2. Just Woundering, is it possible to make a child window at runtime? (e.g. Use CreateWindow instead of DialogBox
    Check out MDI

  3. #3
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Quote Originally Posted by BobS0327 View Post
    Check out MDI
    MDI isn't quite what I'm looking for, I am talking about popup windows, grey background and not limited to the size of the owner window. Windows that feature common controls and buttons, ect. An about or Prefrences dialog box for example. Thanks for clearing that up though.
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Create another window in your app? (one that does not use a resource template.

    Fill in a WNDCLASS struct for the window.
    Call RegisterClass() to register the class name.
    Call CreateWindow(). Do not use the WS_CHILD.

    Create the controls with CreateWindow() using the appropriate class name for the control (ie 'edit')

    AFAIK WIN32 dialogs do not allow resizing like VB dialogs.

    Or are you asking about modeless dialogs?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Thanks, I thought it would be similar (or the same) as creating the first (main) window straight away in WinMain. The second question is answered, so does anyone have any ideas on how to adjust "alpha-blending" (opacity) on the window? I have looked at a tutorial and found out how to handle WM_PAINT but when I put the code in (see q1 above), the window come out completely hidden, the program is still running, but just doesn't have a window for some reason. The compiler isn't giving any errors or warnings about it, so I have linked it correctly. I have also tried putting the code in WinMain, but to no avail. Any ideas?
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You are setting the window to a transparency of 2 out of 0-255 (3rd param).

    Try setting it to 255 and see if the window appears 'normal' then adjust to desired level (if it does).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Quote Originally Posted by novacain View Post
    You are setting the window to a transparency of 2 out of 0-255 (3rd param).
    Actually the 3rd param is (255 * 80) / 100 which = 204 not 2.
    Now, the code takes no effect whatsoever, if I change the 3rd param to 30 or 255, the window still comes up 100% opaque. This is because, for some reason WM_ITITDIALOG never gets called. I thought this gets called when the window gets created. If I put it before ShowWindow() in WinMain the same thing happens as I started with. Just after, none of the common controls appear and the window is still 100% opaque. This just shouldn't happen, and could mean that Elysia was right "msdn docs can sometimes be misleading".
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by P4R4N01D View Post
    Actually the 3rd param is (255 * 80) / 100 which = 204 not 2.
    Oooppps!

    This is because, for some reason WM_ITITDIALOG never gets called. I thought this gets called when the window gets created.
    Dialogs use WM_INITDIALOG but

    Windows (created with CreateWindow or CreateWindowEx) use WM_CREATE.......
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    Thanks novacain for your help so far, now the code does get executed by putting it in WM_CREATE. The problem now is that:
    Code:
    SetWindowLong(hwndDlg, GWL_EXSTYLE, GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_LAYERED);
    Doesn't work. It is this line that makes the window not appear, as described before. I got this from msdn, so it should work. I used CreateWindowEx to create the window, but this should not make much difference.
    I was wondering why one of my windows use WM_INITDIALOG and not others. I din't take into consideration that they were created differently.
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  10. #10
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by P4R4N01D View Post
    The problem now is that:
    Code:
    SetWindowLong(hwndDlg, GWL_EXSTYLE, GetWindowLong(hwndDlg, GWL_EXSTYLE) | WS_EX_LAYERED);
    Doesn't work.
    Are you asking for the window to be redrawn after you change the style?
    That's all I can think of. Something like:
    Code:
    // Ask the window and its children to repaint
    RedrawWindow(hwndDlg, NULL, NULL,
        RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
    or just InvalidateRect(hwndDlg,0,1).

  11. #11
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223

    Layered Window is still not Visible

    Quote Originally Posted by oogabooga View Post
    Are you asking for the window to be redrawn after you change the style?
    No. I am trying to set WS_EX_LAYERED on the main window, created by CreateWindowEx, handle is hwndDlg. So I can then set the opacity to something < 100&#37;. I found something interesting on msdn, saying reasons why this may occur.
    After the CreateWindowEx call, the layered window will not become visible until the SetLayeredWindowAttributes or UpdateLayeredWindow function has been called for this window. Note that WS_EX_LAYERED cannot be used for child windows.
    However, i am calling SetLayeredWindowAttributes and the window still doesn't show. I have decided to try setting WS_EX_LAYERED when I create the window using CreateWindowEx. I tried calling SetLayeredWindowAttributes just before the call to ShowWindow but this still doesn't work.
    -----ADDED----
    I tryed the following (which still didn't work). Note: I did this instead of SetLayeredWindowAttributes:
    Code:
    BLENDFUNCTION bl;
    	bl.BlendOp = AC_SRC_OVER;
    	bl.BlendFlags = 0;
    	bl.SourceConstantAlpha = (255 * 80) / 100;
    	bl.AlphaFormat = AC_SRC_ALPHA;
    
    	UpdateLayeredWindow(hwndMain, NULL, NULL, NULL, NULL, NULL, 0, &bl, LWA_ALPHA);
    Last edited by P4R4N01D; 01-24-2008 at 11:00 PM. Reason: Tried UpdateLayeredWindow
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM