|
#include "StdAfx.h"
#include "vsbasicwindow.h"
BOOL CVsBasicWnd::m_bClassRegistered = FALSE;
CVsBasicWnd::CVsBasicWnd(void)
{
m_hWnd = NULL;
}
CVsBasicWnd::~CVsBasicWnd(void)
{
CDbg::Trace( " CVsBasicWnd:: destructor\n" );
if ( m_hWnd != NULL )
{
::DestroyWindow(m_hWnd);
}
}
#pragma warning(disable:4244)
#pragma warning(disable:4312)
LRESULT CALLBACK CVsBasicWnd::_MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hDC = ::BeginPaint(hWnd,&ps);
if ( hDC )
{
::Ellipse( hDC, 0, 0, 40, 40 );
}
::EndPaint(hWnd,&ps);
return 1;
}
case WM_CREATE:
{
if ( lParam != 0 )
{
CVsBasicWnd* pObj = (CVsBasicWnd*)(((LPCREATESTRUCT)(lParam))->lpCreateParams);
pObj->m_hWnd = hWnd;
::SetWindowLongPtr(hWnd,GWLP_USERDATA,(LONG_PTR)pObj);
return 0;
}
break;
}
case WM_DESTROY:
{
CVsBasicWnd* pObj = (CVsBasicWnd*)::GetWindowLongPtr( hWnd, GWLP_USERDATA );
if ( pObj )
{
pObj->m_hWnd = NULL;
}
//if child dont call ::PostQuitMessage(0);
break;
}
};
return ::DefWindowProc(hWnd,uMsg,wParam, lParam);
}
#pragma warning(default:4244)
#pragma warning(default:4312)
void CVsBasicWnd::Close()
{
if ( m_hWnd )
{
::DestroyWindow(m_hWnd );
}
}
BOOL CVsBasicWnd::Create(HWND hParent, int iX, int iY, int iCX, int iCY)
{
if ( !m_bClassRegistered )
{
WNDCLASSEX wcx;
wcx.cbSize = sizeof(wcx); // size of structure
wcx.style = CS_HREDRAW | CS_VREDRAW; // redraw if size changes
wcx.lpfnWndProc = (WNDPROC)_MainWndProc; // points to window procedure
wcx.cbClsExtra = 0; // no extra class memory
wcx.cbWndExtra = 0; // no extra window memory
wcx.hInstance = NULL; // handle to instance
wcx.hIcon = ::LoadIcon(NULL, IDI_APPLICATION); // predefined app. icon
wcx.hCursor = LoadCursor(NULL,IDC_ARROW); // predefined arrow
wcx.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH); // white background brush
wcx.lpszMenuName = NULL; // name of menu resource
wcx.lpszClassName = "MishaVsWindow"; // name of window class
wcx.hIconSm = NULL;
if ( RegisterClassEx(&wcx) )
{
m_bClassRegistered = TRUE;
}
}
if ( m_bClassRegistered )
{
HWND hwnd = CreateWindowEx( 0,
"MishaVsWindow",
"Sample", // title-bar string
(hParent==NULL?WS_OVERLAPPEDWINDOW:WS_CLIPSIBLINGS|WS_CHILD|WS_VISIBLE),
iX, // default horizontal position
iY, // default vertical position
iCX, // default width
iCY, // default height
(HWND) hParent, // no owner window
(HMENU) NULL, // use class menu
NULL, // handle to application instance
this); // no window-creation data
if ( hwnd )
{
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
return TRUE;
}
}
return FALSE;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
For the last 7 years I have developed software in real-time/embedded and MS-Windows environments for military and civil markets. I hold B.Sc. degree in computer engineering. Living in Ontario, Canada, I like hiking and traveling in general. Currently, I'm looking for employment opportunity inside the GTA.