Skip to content

Commit

Permalink
New Revision
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Tang <[email protected]>
  • Loading branch information
neuks committed Apr 15, 2017
1 parent c3ef965 commit 1e93326
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 77 deletions.
65 changes: 65 additions & 0 deletions afx_CApp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//*****************************************************************************
// Win32 Framework - Main
//
// Copyright (C) 2010, Martin Tang
//*****************************************************************************
#include "afx.h"

//=============================================================================
// CApp Implementation
//=============================================================================

CApp::CApp()
{
}

CApp::~CApp()
{
}

int CApp::OnInit()
{
WNDCLASS wc;

// setup application-wide window class
wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = _WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszMenuName = NULL;
wc.lpszClassName = "WINDOW";

RegisterClass(&wc);

return 0;
}

int CApp::OnExit()
{
UnregisterClass("WINDOW", GetModuleHandle(NULL));

return 0;
}

int CApp::OnExec()
{
MSG msg;

ASSERT(this->OnInit());

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

ASSERT(this->OnExit());

return msg.wParam;
}


161 changes: 84 additions & 77 deletions afx.cpp → afx_CWnd.cpp
Original file line number Diff line number Diff line change
@@ -1,77 +1,84 @@
//*****************************************************************************
// Win32 Framework - Main
//
// Copyright (C) 2010, Martin Tang
//*****************************************************************************
#include <list>
#include "afx.h"

using namespace std;

//=============================================================================
// Global Window Queue List
//=============================================================================

typedef list<CWnd*> LWnd;

LWnd g_lWndLst;
CWnd *g_pWndNew;

//=============================================================================
// CWnd Implementation
//=============================================================================

CWnd::CWnd()
{
// initialize properties
this->m_hWnd = NULL;

// add current object to global window list
g_lWndLst.push_back(this);

// register the window to the global identifier for initialization
while(g_pWndNew); // mutex for multi-threading
g_pWndNew = this;
}

CWnd::~CWnd()
{
// destroy if necessary
DestroyWindow(this->m_hWnd);

// remove current object from global window list
for(LWnd::iterator i = g_lWndLst.begin(); i != g_lWndLst.end(); i++) {
if((*i)->m_hWnd == m_hWnd) {
g_lWndLst.erase(i);
break;
}
}

}

int CWnd::MsgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return ::DefWindowProc(this->m_hWnd, uMsg, wParam, lParam);
}

//=============================================================================
// Global Window Message Processor
//=============================================================================

LRESULT CALLBACK _WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if(((uMsg == WM_CREATE) || (uMsg == WM_INITDIALOG)) && g_pWndNew) {
g_pWndNew->m_hWnd = hWnd;
g_pWndNew = NULL;
}

for(LWnd::iterator i = g_lWndLst.begin(); i != g_lWndLst.end(); i++) {
if((*i)->m_hWnd == hWnd)
{
return (*i)->MsgProc(uMsg, wParam, lParam);
}
}

return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

//*****************************************************************************
// Win32 Framework - Main
//
// Copyright (C) 2010, Martin Tang
//*****************************************************************************
#include <list>
#include "afx.h"

using namespace std;

//=============================================================================
// Global Window Queue List
//=============================================================================

typedef list<CWnd*> LWnd;

LWnd g_lWndLst;
CWnd *g_pWndNew;

//=============================================================================
// CWnd Implementation
//=============================================================================

CWnd::CWnd()
{
// initialize properties
this->m_hWnd = NULL;

// add current object to global window list
g_lWndLst.push_back(this);

// register the window to the global identifier for initialization
while(g_pWndNew); // mutex for multi-threading
g_pWndNew = this;
}

CWnd::~CWnd()
{
// destroy if necessary
DestroyWindow(this->m_hWnd);

// remove current object from global window list
for(LWnd::iterator i = g_lWndLst.begin(); i != g_lWndLst.end(); i++) {
if((*i)->m_hWnd == m_hWnd) {
g_lWndLst.erase(i);
break;
}
}

}

int CWnd::MsgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return DefWindowProc(this->m_hWnd, uMsg, wParam, lParam);
}

//=============================================================================
// Global Window Message Processor
//=============================================================================

LRESULT CALLBACK _WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if(((uMsg == WM_CREATE) || (uMsg == WM_INITDIALOG)) && g_pWndNew)
{
g_pWndNew->m_hWnd = hWnd;
g_pWndNew = NULL;
}

for(LWnd::iterator i = g_lWndLst.begin(); i != g_lWndLst.end(); i++)
{
// send command to all windows
if (uMsg == WM_COMMAND)
{
(*i)->MsgProc(uMsg, wParam, lParam);
}
else if((*i)->m_hWnd == hWnd)
{
return (*i)->MsgProc(uMsg, wParam, lParam);
}
}

return DefWindowProc(hWnd, uMsg, wParam, lParam);
}

80 changes: 80 additions & 0 deletions afx_LoadToolbar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//*****************************************************************************
// Win32 Framework - Main
//
// Copyright (C) 2010, Martin Tang
//*****************************************************************************
#include "afx.h"

//=============================================================================
// MFC Replacement Function
//=============================================================================

struct TB_DATA { UINT uWidth, uHeight, uItemCount, uIDs[1]; };

HWND LoadToolbar(HINSTANCE hInstance, DWORD dwStyle, WORD wID, HWND hParent)
{
HRSRC hFound;
HGLOBAL hResource;
HBITMAP hBitmap;
HWND hToolbar;
TB_DATA *pData;
UINT *pIDs;
TBBUTTON *pButtons;

// get module instance
if (hInstance == NULL) {
hInstance = GetModuleHandle(NULL);
}

// find the resource
if ((hFound = FindResource(hInstance, MAKEINTRESOURCE(wID),
MAKEINTRESOURCE(241))) == NULL) {
return NULL;
}

// load toolbar resource
if ((hResource = LoadResource(hInstance, hFound)) == NULL) {
return NULL;
}

// load toolbar bitmap
if ((hBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(wID))) == NULL) {
return NULL;
}

// lock resource
pData = (TB_DATA*)LockResource(hResource);
pIDs = pData->uIDs;
pButtons = (TBBUTTON*)malloc(sizeof(TBBUTTON) * pData->uItemCount);

int nBitmaps = 0;

// create toolbar structure
for (int i=0; i<pData->uItemCount; i++) {
// special treatment
if (pIDs[i] == 0) {
pButtons[i].iString = 0;
pButtons[i].iBitmap = 0;
pButtons[i].fsStyle = TBSTYLE_SEP;
} else {
pButtons[i].iBitmap = nBitmaps;
pButtons[i].iString = nBitmaps++;
pButtons[i].fsStyle = TBSTYLE_BUTTON;
}

// common procedure
pButtons[i].idCommand = pIDs[i];
pButtons[i].fsState = TBSTATE_ENABLED;
pButtons[i].dwData = 0;
}

hToolbar = CreateToolbarEx(hParent, dwStyle, wID, nBitmaps, NULL,
(UINT)hBitmap, pButtons, pData->uItemCount, pData->uWidth,
pData->uHeight, pData->uWidth, pData->uHeight, sizeof(TBBUTTON));

free(pButtons);

return hToolbar;
}


0 comments on commit 1e93326

Please sign in to comment.