Solved

Non Square Window Shapes

Posted on 1998-04-03
5
892 Views
Last Modified: 2013-12-03
I have a program somebody gave me that creates an non-square window.  Has anybody else seen this?  What I need to know is if there is some way to do this for a Dialog box instead of a SDI.  Here is the code for SDI:

#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
            PSTR szCmdLine, int iCmdShow)
{
      static char szAppName[] = "App Name";
      static char szAppTitle[] = "App Name";
      HWND hwnd;
      MSG msg;
      WNDCLASSEX wndclass;

      wndclass.cbSize = sizeof(wndclass);
      wndclass.style = CS_HREDRAW | CS_VREDRAW;
      wndclass.lpfnWndProc = WndProc;
      wndclass.cbClsExtra = 0;
      wndclass.cbWndExtra = 0;
      wndclass.hInstance = hInstance;
      wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
      wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
      wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
      wndclass.lpszMenuName = NULL;
      wndclass.lpszClassName = szAppName;
      wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

      RegisterClassEx(&wndclass);
      hwnd = CreateWindow (szAppName, szAppTitle,WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
            NULL, NULL, hInstance, NULL);
      ShowWindow(hwnd, iCmdShow);
      UpdateWindow(hwnd);

      while (GetMessage (&msg, NULL, 0, 0))
      {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
      }
      return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
      HDC hdc;
      PAINTSTRUCT ps;
      RECT rect;
      HRGN Rgn;
      POINT points[5];
      int AutoMagic = -1;

      switch (iMsg)
      {
            case WM_CREATE :
                  SetWindowRgn(hwnd,NULL,FALSE);
                  GetWindowRect(hwnd,&rect);
                  points[0].x = points[0].y = points[1].x = 0;
                  points[1].y = GetSystemMetrics(SM_CYMENU) + GetSystemMetrics(SM_CYCAPTION);
                  points[3].x = points[4].x = rect.right - rect.left;
                  points[4].y = 0;
                  points[3].y = points[1].y;
                  points[2].x = (rect.right - rect.left)/2;
                  points[2].y = rect.bottom - rect.top;
                  Rgn = CreatePolygonRgn(points,5,WINDING);
                  SetWindowRgn(hwnd,Rgn,TRUE);
                  return 0;
            case WM_PAINT :
                  hdc = BeginPaint(hwnd, &ps);
                  GetClientRect(hwnd,&rect);
                  DrawText(hdc, "Inside the Window!", AutoMagic, &rect,
                        DT_SINGLELINE | DT_CENTER | DT_VCENTER);
                  EndPaint(hwnd, &ps);
                  return 0;
            case WM_DESTROY :
                  PostQuitMessage(0);
                  return 0;
      }
      return DefWindowProc(hwnd, iMsg, wParam, lParam);
}


This is pretty clever programming, but is it possible for Dialog boxes and can I implement it in C++ using MSVC++5.0?
0
Comment
Question by:WinDude
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1412526
The "trick" is to use SetWindowRgn() on the dialog. After calling SetWindowRgn() with the region of how you want the dialog to look.

0
 
LVL 1

Author Comment

by:WinDude
ID: 1412527
ok, I added more points.  Could I get this translated to C++ MFC for a dialog box?

0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1412528
In the Window Procedure of your dialog, add:

case WM_INITDIALOG:
SetWindowRgn(hwnd,NULL,FALSE);
   GetWindowRect(hwnd,&rect);
   points[0].x = points[0].y = points[1].x = 0;
   points[1].y = GetSystemMetrics(SM_CYMENU) +
   GetSystemMetrics(SM_CYCAPTION);
   points[3].x = points[4].x = rect.right - rect.left;
   points[4].y = 0;
   points[3].y = points[1].y;
   points[2].x = (rect.right - rect.left)/2;
   points[2].y = rect.bottom - rect.top;
   Rgn = CreatePolygonRgn(points,5,WINDING);
   SetWindowRgn(hwnd,Rgn,TRUE);
   return 0;
0
 
LVL 1

Author Comment

by:WinDude
ID: 1412529
can anybody translate the ENTIRE (as small as it is) to C++ MFC? yes I'm clueless...
0
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 400 total points
ID: 1412530
If you want this to be done in MFC, do this:
1. Create a dialog based app using AppWizard - It will generate you a dialog based app.
2. Click on View->ClassWizard. Select the class named CMyDlg.
In the messageList select WM_INITDIALOG and doubleclick it.
paste the code:

SetWindowRgn(NULL,FALSE);
   GetWindowRect(&rect);
   points[0].x = points[0].y = points[1].x = 0;
   points[1].y = GetSystemMetrics(SM_CYMENU) +
   GetSystemMetrics(SM_CYCAPTION);
   points[3].x = points[4].x = rect.right - rect.left;
   points[4].y = 0;
   points[3].y = points[1].y;
   points[2].x = (rect.right - rect.left)/2;
   points[2].y = rect.bottom - rect.top;
   Rgn = CreatePolygonRgn(points,5,WINDING);
   SetWindowRgn(Rgn,TRUE);
   return 0;
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now