Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 678
  • Last Modified:

Transparent Dialog Box

I want to take a Dialog I created in the resource editor and use it as the only window in the application (as far as a user is concerned).  The problem is that anything which is not a control in the dialog is transparent.  I am using the Win32 API's.  I have checked in the resource editor, and 'visible' is checked and 'transparent' is not.  Here is the code:

#include<windows.h>
#include<commctrl.h>
#include"resource.h"


HINSTANCE Gclient_instance;
LS_Client* client = 0;
BOOL CALLBACK ClientFunc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK mydialogproc(HWND,UINT,WPARAM,LPARAM);



int WINAPI WinMain(
      HINSTANCE hInstance, // handle to current instance
      HINSTANCE hPrevInstance, // handle to previous instance
      LPSTR lpCmdLine, // pointer to command line
      int nCmdShow  // show state of window
      ){
      Gclient_instance = hInstance;
      InitCommonControls();
      
      //DialogBox(Gclient_instance,MAKEINTRESOURCE(IDD_CLIENT_WINDOW),HWND_DESKTOP,(DLGPROC)ClientFunc);
      HWND x = CreateDialog(Gclient_instance,MAKEINTRESOURCE(IDD_CLIENT_WINDOW),HWND_DESKTOP,(DLGPROC)ClientFunc);
      MSG Msg;

      while(GetMessage(&Msg,0,0,0))
      {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
      }



      return 0;

}




//&&&&&&&&&&&&&&&&&&& Actual Viewed Window &&&&&&&&&&&&&&&&&&//

BOOL CALLBACK ClientFunc(  HWND hwnd,  // handle to dialog box
  UINT uMsg,     // message  
      WPARAM wParam, // first message parameter
  LPARAM lParam  // second message parameter
      )
      
      {
      PAINTSTRUCT ps;
      HDC hDC;
            static LS_Client* clientwin = 0;
            
            /*if(clientwin == 0)
            {
                  HWND lv = GetDlgItem(hwnd,LV_CONTEXT);
                  HWND statcontext = GetDlgItem(hwnd,STATIC_CURRENT_CONTEXT);

                  InitCommonControls();
                  
                  clientwin = new LS_Client(Gclient_instance,LS_CLIENT_MENU);
                  clientwin->SetControls(lv,statcontext);
                  clientwin->GetTarget().AddColumn("Users Whose Password You May Change",0,100);
                  ShowWindow(hwnd,SW_SHOWNORMAL);
                  UpdateWindow(clientwin->GetContext().GetHandle());
                  //(clientwin.GetContext())
            }*/

            switch(uMsg)
            {
                  
                  case WM_PAINT:
                  {
                        //MessageBox(0,"WM_PAINT"," ",MB_OK);
                        hDC=BeginPaint(hwnd,&ps);
                        EndPaint(hwnd,&ps);
                        //ShowWindow(hWnd,SW_HIDE);
                        return(1);
                  }
                  case WM_INITDIALOG:
                  {
                        //DialogBox(Gclient_instance,MAKEINTRESOURCE(IDD_CLIENT_WINDOW),hwnd,(DLGPROC)ClientFunc);
                        //ShowWindow(hwnd,SW_SHOW);
                        //MessageBox(0,"End Init"," ",MB_OK);
                        //return 1;
                        HWND lv = GetDlgItem(hwnd,LV_CONTEXT);
                        HWND statcontext = GetDlgItem(hwnd,STATIC_CURRENT_CONTEXT);

                        //InitCommonControls();

                  
                        clientwin = new LS_Client(Gclient_instance,LS_CLIENT_MENU);
                        clientwin->SetControls(lv,statcontext);
                        clientwin->GetTarget().AddColumn("Users Whose Password You May Change",0,303);
                        //ShowWindow(hwnd,SW_SHOWNORMAL);
                        UpdateWindow(clientwin->GetContext().GetHandle());
                        break;
                  }
                  
                  case WM_COMMAND:
                  {

                        /////////////// SWITCH_JOE ///////////
                        switch(LOWORD(wParam))
                        {
                        
                              case B_SELECT:
                              {
                                    UpdateWindow(clientwin->GetContext().GetHandle());
                              }
                              case B_CHANGE:
                              {
                                    UpdateWindow(clientwin->GetContext().GetHandle());
                              }
                              case M_EXIT:
                              {

                              }

                        }
                        ////////////// ~SWITCH_JOE //////////
                        break;
                  }
                  case WM_DESTROY:
                  {
                        PostQuitMessage(1);
                        break;
                  }




            }//switch
            return 1;
      }









0
rwinkler
Asked:
rwinkler
  • 5
1 Solution
 
rwinklerAuthor Commented:
Edited text of question
0
 
rwinklerAuthor Commented:
Edited text of question
0
 
rwinklerAuthor Commented:
Edited text of question
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
overworkedCommented:
You're returning 1 for WM_PAINT when you should be returning FALSE or 0 since returning 1 or TRUE will keep the message from reaching dialog children.
0
 
bbarberCommented:
I agree with the above.  But here's some more cool code you might want to try at your whim.


   static HBRUSH      Return_Brush;
            case WM_CTLCOLOR:
                switch( HIWORD( lParam ) )
                {
                      case CTLCOLOR_BTN:
                      case CTLCOLOR_STATIC:
                      case CTLCOLOR_DLG:
                            if( hbrBlack != GetTextColor( ( HDC )wParam ) )
                            {
                                  SetTextColor( ( HDC )wParam, RGB( 0, 0, 0 ) );
                            }
                            if( TRANSPARENT != GetBkMode( ( HDC )wParam ) )
                            {
                                  SetBkMode( ( HDC )wParam, TRANSPARENT );
                            }
                            if( hbrGray != GetBkColor( ( HDC )wParam ) )
                            {
                                  SetBkColor( ( HDC )wParam, RGB( 192, 192, 192 ) );
                            }
                            return( Gray_Brush );
                      
                      case CTLCOLOR_MSGBOX:
                      case CTLCOLOR_EDIT :
                            if( LOWORD( lParam ) == GetDlgItem( hDlg, IDD_BOX6 ) ||
                                LOWORD( lParam ) == GetDlgItem( hDlg, IDD_BOX11 )||
                                     LOWORD( lParam ) == GetDlgItem( hDlg, IDD_BOX13 ) )
                            {
                                  if( hbrBlack != GetTextColor( ( HDC )wParam ) )
                                  {
                                        SetTextColor( ( HDC )wParam, RGB( 0, 0, 0 ) );
                                  }
                                  if( TRANSPARENT != GetBkMode( ( HDC )wParam ) )
                                  {
                                        SetBkMode( ( HDC )wParam, TRANSPARENT );
                                  }
                                  SetBkColor( ( HDC )wParam, RGB( 192, 192, 192 ) );
                                  return( Gray_Brush );
                            }
                            if( hbrBlack != GetTextColor( ( HDC )wParam ) )
                            {
                                    SetTextColor( ( HDC )wParam, RGB( 0, 0, 0 ) );
                            }
                            if( TRANSPARENT != GetBkMode( ( HDC )wParam ) )
                              {
                                    SetBkMode( ( HDC )wParam, TRANSPARENT );
                            }
                            if( hbrGray != GetBkColor( ( HDC )wParam ) )
                              {
                                    SetBkColor( ( HDC )wParam, RGB( 255, 255, 255 ) );
                            }
                            return( White_Brush );
                }
                return( ( HBRUSH )NULL );

0
 
rwinklerAuthor Commented:
Unfortunately, this gave the same result.  I still get a window which is transparent (ie, invisible), except for the controls.  I have added a message box when either button is pressed, but the message box refuses to acquire focus.  Doh.
0
 
rwinklerAuthor Commented:
You were on the right track.  It was the return 1 at the very end of the proc that was the problem...causing it to ignore every other message besides those I'd explicitly handled.  Thanks for the help :)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now