Hiding window in process.start() and moving this window - c#-4.0

I wrote this code, but I cannot hide and move the window.
How can I hide the window in Process.Start() and then move it and show it to the user?
[DllImport("USER32.dll")]
//[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("USER32.dll")]
private static extern bool UpdateWindow(IntPtr hWnd);
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = Application.StartupPath + #"\award_star_gold_2.png";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.RedirectStandardOutput = false;
startInfo.RedirectStandardError = false;
startInfo.UseShellExecute = true;
startInfo.CreateNoWindow = true;
Process processTemp = new Process();
processTemp.StartInfo = startInfo;
processTemp.EnableRaisingEvents = true;
processTemp.Start();
processTemp.WaitForInputIdle();
IntPtr id = processTemp.MainWindowHandle;
Console.Write(id);
System.Threading.Thread.Sleep(1000);
MoveWindow(processTemp.MainWindowHandle, 10, 200, 200, 300, true);
UpdateWindow(processTemp.MainWindowHandle);
}

Related

Tool tip for disabled check boxes in Check List Box control in MFC

I am working in an MFC windows application. I am using check boxes in Check List Box control. Some of the check boxes are disabled. How can I implement the tool tips for disabled check boxes?
Ran Wainstein was implemented the tool tip for each item in the list box control. This can be extended to the Check List Box control also.
MyCheckListBox.h
class CMyCheckListBox : public CCheckListBox
{
DECLARE_DYNAMIC(CMyCheckListBox)
public:
CMyCheckListBox(){};
virtual ~CMyCheckListBox(){};
afx_msg int OnToolHitTest(CPoint point, TOOLINFO * pTI) const;
UINT ItemFromPoint2(CPoint pt, BOOL& bOutside) const;
BOOL OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
protected:
virtual void PreSubclassWindow();
DECLARE_MESSAGE_MAP()
};
MyCheckListBox.cpp
This will work only for Unicode strings.
IMPLEMENT_DYNAMIC(CMyCheckListBox, CCheckListBox)
BEGIN_MESSAGE_MAP(CMyCheckListBox, CCheckListBox)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xFFFF, OnToolTipText)
END_MESSAGE_MAP()
void CMyCheckListBox::PreSubclassWindow() {
CCheckListBox::PreSubclassWindow();
EnableToolTips(TRUE);
}
int CMyCheckListBox::OnToolHitTest(CPoint point, TOOLINFO * pTI) const{
int row;
RECT cellrect;
BOOL tmp = FALSE;
row = ItemFromPoint(point,tmp);
if ( row == -1 )
return -1;
GetItemRect(row,&cellrect);
pTI->rect = cellrect;
pTI->hwnd = m_hWnd;
pTI->uId = (UINT)((row));
pTI->lpszText = LPSTR_TEXTCALLBACK;
return pTI->uId;
}
BOOL CMyCheckListBox::OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult ){
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
CString strTipText;
UINT nID = pNMHDR->idFrom;
GetText( nID ,strTipText);
lstrcpyn(pTTTW->szText, strTipText, 80);
*pResult = 0;
return TRUE;
}
UINT CMyCheckListBox::ItemFromPoint2(CPoint pt, BOOL& bOutside) const{
int nFirstIndex, nLastIndex;
nFirstIndex = GetTopIndex();
nLastIndex = nFirstIndex + GetCount();
bOutside = TRUE;
CRect Rect;
int nResult = -1;
for (int i = nFirstIndex; nResult == -1 && i <= nLastIndex; i++){
if (GetItemRect(i, &Rect) != LB_ERR){
if (Rect.PtInRect(pt)){
nResult = i;
bOutside = FALSE;
}
}
}
return nResult;
}
Finally implement Check List Box control in the corresponding dialog box.The output is

Mfc application crash in CWnd::DefWindowProc while creating Progress Control from within Worker Thread after 34 repetitive cycles on 64 bit windows

I am trying to figure out the exact reason for the crash happening in my 32 bit MFC application which is running on 64 bit system.
Actually this is a multithreaded MFC SDI application and can do cyclic execution which includes Inspection and outputting inspection results as reports.
After an inspection finishes it show a Custom Alert Window with a progress control until the reports are generated.The Alert Window is created from a Worker Thread and the Main Thread waits until the window is created.
Below is the coded representation of one cycle of Displaying the Alert Window With Progress Bar:
static const __int64 POPUPWND_POLLPERIOD = 10 * 10000LL;
static const __int64 POPUPWND_POLLTIMEOUT = 1000 * POPUPWND_POLLPERIOD;
class CCallFunc
{
public:
class Queue;
public:
typedef int(*Call)(const CCallFunc &cf);
public:
CCallFunc(Call call, LPVOID lpData) :
m_call(call),
m_lpData(lpData)
{}
int Run() { m_call(*this); }
LPVOID GetData() const { return m_lpData; }
private:
Call m_call;
LPVOID m_lpData;
};
class CCallFunc::Queue
{
public:
int SetQueue(const CCallFunc &cf, const __int64 &timeout = INFINITE)
{
m_pcf = &cf;
m_timeout = timeout;
}
public:
int Run(const __int64 &timeout = 0)
{
CCallFunc cf(*m_pcf);
cf.Run();
}
private:
const CCallFunc* m_pcf;
__int64 m_timeout;
};
class CWorkThread
{
private:
static DWORD WINAPI SystemThread(LPVOID lpData)
{
CWorkThread* pThread = (CWorkThread*)lpData;
__int64 timeout = pThread->m_timeout;
try {
pThread->m_queue.Run(timeout);
}
catch (const CCallFunc &cf) {
pThread->m_queue.SetQueue(cf, timeout);
}
}
public:
static int Aquire(CWorkThread *pThread)
{
pThread = &thisThread;
return S_OK;
}
static void Sleep(const __int64 &period)
{
__int64 current;
__int64 final = period;
switch (final) {
case INFINITE:
while (true)
::SleepEx(INFINITE, TRUE);
throw;
case 0:
::SleepEx(DWORD(0), TRUE);
return;
default:
::GetSystemTimeAsFileTime(reinterpret_cast<FILETIME*>(&current));
if ((final += current) < 0)
final = current;
while (current < final) {
if (::SleepEx(DWORD((final - current) / __int64(10000)), TRUE) == 0)
return;
::GetSystemTimeAsFileTime((FILETIME*)&current);
}
}
}
int Start(CCallFunc::Call call, LPVOID lpData)
{
return Start(CCallFunc(call, lpData));
}
int Start(const CCallFunc &fc)
{
DWORD dwID = 0;
::CreateThread(0, 0, &SystemThread, this, 0, &dwID);
}
public:
CCallFunc::Queue m_queue;
private:
__int64 m_timeout;
static CWorkThread thisThread;
};
class CPopupWindow;
struct PopupWndCreateContext : public CCreateContext {
CPopupWindow* popup;
CString clsname;
CString wndname;
DWORD style;
DWORD exstyle;
CRect rc;
HWND parent;
UINT id;
};
class CPopupWindow : public CWnd
{
public:
int Show()
{
HWND hParent = 0;
CWinApp* pApp = NULL;
CWnd* pMain;
if ((pApp = ::AfxGetApp()) != 0 && (pMain = pApp->GetMainWnd()) != 0) {
hParent = pMain->m_hWnd;
}
Create(800, 600, hParent);
}
private:
int Create(int iWidth, int iHeight, HWND parent)
{
PopupWndCreateContext ctxt;
ctxt.popup = this;
ctxt.clsname = "AlertCtrl";
ctxt.wndname = "Alert Control";
ctxt.style = WS_VISIBLE | WS_POPUP;
ctxt.exstyle = 0;
ctxt.rc = CRect(0, 0, iWidth, iHeight);
ctxt.parent = parent;
ctxt.id = 10000;
CWorkThread* pThread;
int e;
if (SUCCEEDED(e = CWorkThread::Aquire(pThread)) && SUCCEEDED(e = pThread->Start(&Run, &ctxt))) {
for (__int64 t = 0; t < POPUPWND_POLLTIMEOUT; t += POPUPWND_POLLPERIOD) {
if (::IsWindow(*this))
return 0;
CWorkThread::Sleep(POPUPWND_POLLPERIOD);
}
}
}
static int Run(const CCallFunc &cf)
{
int e = 0;
PopupWndCreateContext& ctxt = *(static_cast<PopupWndCreateContext*>(cf.GetData()));
ASSERT(&ctxt != 0);
CPopupWindow &wnd = *ctxt.popup;
static const DWORD clsstyle = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW;
static const HCURSOR clscursor = ::LoadCursor(0, IDC_WAIT);
static const HICON clsicon = 0;
static LPCTSTR clsname = ::AfxRegisterWndClass(clsstyle, clscursor, NULL, clsicon);
if (wnd.CreateEx(DWORD(ctxt.exstyle), ctxt.clsname, ctxt.wndname, DWORD(ctxt.style), ctxt.rc.left, ctxt.rc.top, ctxt.rc.Width(), ctxt.rc.Height(), ctxt.parent, HMENU(ctxt.id), 0) != 0) {
HWND hwnd = wnd.GetSafeHwnd();
::UpdateWindow(hwnd);
MSG msg;
while ((::GetMessage(&msg, 0, 0, 0))) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
wnd.DestroyWindow();
}
return e;
}
};
class CAlertCtrl : CPopupWindow
{
CProgressCtrl m_progctrl;
DECLARE_MESSAGE_MAP();
int OnCreate(LPCREATESTRUCT cs)
{
int e = 0; //< error code / return value
if ((e = __super::OnCreate(cs)) != 0)
return e;
if (!::IsWindow(m_progctrl))
{
CRect rc;
GetClientRect(rc);
if (m_progctrl.Create(WS_CHILD | WS_VISIBLE | PBS_SMOOTH, rc, this, 100000))
m_progctrl.SetRange(0, 10000);
}
return e;
}
};
BEGIN_MESSAGE_MAP(CAlertCtrl, CPopupWindow)
ON_WM_CREATE()
END_MESSAGE_MAP()
So while executing m_progctrl.Create it crashes in the Wincore.cpp
at the method CWnd::DefWindowProc trying to execute callWindowProc after calling the method CPopupWindow::Show for the 35th Cycle.
/////////////////////////////////////////////////////////////////////////////
// Default CWnd implementation
LRESULT CWnd::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
{
if (m_pfnSuper != NULL)
return ::CallWindowProc(m_pfnSuper, m_hWnd, nMsg, wParam, lParam);

Form2 Not Opening?

I am making a Video game using microsoft Visual c++, I am coding all of this in CLR language, But I this weird problem....
For some reason Whenever I try and open form 2 with Form 1 all I get are these errors...
*1>------ Build started: Project: Retaliation, Configuration: Debug Win32 ------
1> Form2.cpp
1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(431): error C2065: 'Form2' : undeclared identifier
1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(431): error C2065: 'f2' : undeclared identifier
1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(431): error C2061: syntax error : identifier 'Form2'
1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(432): error C2065: 'f2' : undeclared identifier
1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(432): error C2227: left of '->Show' must point to class/struct/union/generic type
1> type is ''unknown-type''
1> Retaliation.cpp
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========*
Here is my code for form 1...
#pragma once
#include "stdAfx.h"
#include "Form2.h"
#include "Form1.h"
namespace Retaliation {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace std;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
String^ CharName;
String^ Race;
String^ Gender;
String^ Specialty;
String^ Friend;
int YesorNo;
int ExitChoice;
int TimerValue;
int MonsterN;
int EnemyHp;
int Dm;
int Energy;
int Action;
int Rage;
int MaxMana;
int MaxRage;
int MaxEnergy;
int Save;
// 1 = Earth pony 2 = Pegasus 3 = unicorn
int Lv;
int XpR;
int Xp;
int A;
int D;
int Hp;
int MaxHp;
int Magic;
int Mana;
int Agility;
int Gold;
String ^Enpowerment;
// 1 = Friendship is Magic, 2 = Music is Magic, 3 = Darkness is Magic, 4 = Light is Magic, 5 = Chaos is Magic
// End of leveling thread
int Checkpoint;
int FriendNameN;
int SavePoint;
int MenuChoice;
int RightMenuChoice;
int RestartFile;
int Answer;
int EnemyA;
int EnemyD;
int EnemyLv;
int EnemyMana;
int EnemyMagic;
int EnemyAgility;
int Random;
String ^ EName;
int Damage;
int Survivors;
int SavedSurvivors;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Timer^ timer1;
public:
int MainActions;
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::PictureBox^ pictureBox2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::Button^ button5;
private: System::Windows::Forms::PictureBox^ pictureBox3;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Required designer variable.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->button4 = (gcnew System::Windows::Forms::Button());
this->button5 = (gcnew System::Windows::Forms::Button());
this->pictureBox3 = (gcnew System::Windows::Forms::PictureBox());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->timer1 = (gcnew System::Windows::Forms::Timer(this- >components));
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ > (this->pictureBox1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ > (this->pictureBox2))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.Image")));
this->pictureBox1->Location = System::Drawing::Point(0, -3);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(600, 295);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location = System::Drawing::Point(13, 230);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(127, 43);
this->button1->TabIndex = 1;
this->button1->Text = L"Start Game";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(313, 212);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(120, 42);
this->button2->TabIndex = 2;
this->button2->Text = L"New Game";
this->button2->UseVisualStyleBackColor = true;
this->button2->Visible = false;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// button3
//
this->button3->Location = System::Drawing::Point(143, 212);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(120, 42);
this->button3->TabIndex = 3;
this->button3->Text = L"Load Game";
this->button3->UseVisualStyleBackColor = true;
this->button3->Visible = false;
this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
//
// pictureBox2
//
this->pictureBox2->BackColor = System::Drawing::Color::Transparent;
this->pictureBox2->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources- >GetObject(L"pictureBox2.BackgroundImage")));
this->pictureBox2->Location = System::Drawing::Point(0, -3);
this->pictureBox2->Name = L"pictureBox2";
this->pictureBox2->Size = System::Drawing::Size(86, 81);
this->pictureBox2->TabIndex = 4;
this->pictureBox2->TabStop = false;
this->pictureBox2->Visible = false;
//
// label1
//
this->label1->AutoSize = true;
this->label1->BackColor = System::Drawing::Color::Transparent;
this->label1->Location = System::Drawing::Point(92, -3);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(22, 13);
this->label1->TabIndex = 5;
this->label1->Text = L" ";
this->label1->Visible = false;
//
// label2
//
this->label2->BackColor = System::Drawing::Color::Transparent;
this->label2->Location = System::Drawing::Point(358, 87);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(199, 98);
this->label2->TabIndex = 9;
this->label2->Text = L"None";
this->label2->Visible = false;
//
// button4
//
this->button4->Location = System::Drawing::Point(463, 13);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(75, 23);
this->button4->TabIndex = 12;
this->button4->Text = L"Yes";
this->button4->UseVisualStyleBackColor = true;
this->button4->Visible = false;
this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
//
// button5
//
this->button5->Location = System::Drawing::Point(463, 43);
this->button5->Name = L"button5";
this->button5->Size = System::Drawing::Size(75, 23);
this->button5->TabIndex = 13;
this->button5->Text = L"No";
this->button5->UseVisualStyleBackColor = true;
this->button5->Visible = false;
this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// pictureBox3
//
this->pictureBox3->BackColor = System::Drawing::Color::Transparent;
this->pictureBox3->Location = System::Drawing::Point(13, 84);
this->pictureBox3->Name = L"pictureBox3";
this->pictureBox3->Size = System::Drawing::Size(165, 208);
this->pictureBox3->TabIndex = 14;
this->pictureBox3->TabStop = false;
this->pictureBox3->Visible = false;
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(463, 212);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 15;
this->textBox1->Visible = false;
this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged_1);
//
// timer1
//
this->timer1->Interval = 1000;
this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(598, 285);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->pictureBox3);
this->Controls->Add(this->button5);
this->Controls->Add(this->button4);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->pictureBox2);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Retaliation";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
public:int MoviePlay;
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
//
this -> button2 -> Visible = true;
this -> button3 -> Visible = true;
this -> button1 -> Visible = false;
this -> pictureBox1 -> Load("Derpy.jpg");
//
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
if (YesorNo == 0){
this -> button4 -> Visible = true;
this -> button2 -> Visible = false;
this -> button5 -> Visible = true;
this -> button3 -> Visible = false;
this -> label2 -> Visible = true;
this -> label2 -> Text = "Are you Sure?";
this -> YesorNo = 1;
}
else if (YesorNo == 5)
{
Gender = "Female";
this -> label2 -> Text = "What is your Race??";
this -> button4 -> Text = "Earth Pony";
this -> button5 -> Text = "Unicorn";
this -> button2 -> Visible = true;
this -> button2 -> Text = "Pegasus";
YesorNo = 6;
}
else if (YesorNo == 6)
{
Race = "Pegasus";
this -> button2 -> Visible = false;
this -> button4 -> Visible = false;
this -> button5 -> Visible = false;
label2 -> Text = "Thank You For Playing!!";
YesorNo = 7;
this -> timer1 -> Start();
}
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
if (YesorNo == 1)
{
this -> label2 -> Text = "To Make your Pony Character, See PonyMakin.txt in your Retaliation Folder, Your pony should have a invisible background... If not check your background color For your pony!";
button4 -> Text = "Show Pony";
YesorNo = 2;
}
else if ( YesorNo == 2)
{
this -> pictureBox3 -> Visible = true;
this -> pictureBox3 -> Load("Outline Body Model.jpg");
this -> pictureBox2 -> Visible = true;
this -> pictureBox2 -> Load("OutlineModel.jpg");
YesorNo = 3;
this -> textBox1 -> Visible = true;
this -> textBox1 -> Text = "Name?";
this -> button5 -> Visible = false;
this -> button4 -> Visible = false;
this -> label2 -> Visible = false;
}
else if (YesorNo == 5)
{
Gender = "Male";
this -> label2 -> Text = "What is your Race??";
this -> button4 -> Text = "Earth Pony";
this -> button5 -> Text = "Unicorn";
this -> button2 -> Visible = true;
this -> button2 -> Text = "Pegasus";
YesorNo = 6;
}
else if (YesorNo == 6)
{
Race = "Earth_Pony";
this -> button2 -> Visible = false;
this -> button4 -> Visible = false;
this -> button5 -> Visible = false;
label2 -> Text = "Thank You For Playing!!";
YesorNo = 7;
this -> timer1 -> Start();
}
}
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
if (YesorNo == 1 || YesorNo == 2)
{
Application::Exit();
}
else if (YesorNo == 4)
{
this -> textBox1 -> Visible = false;
this -> label2 -> Visible = true;
this -> label2 -> Text = "What Is Your Gender?";
this -> button4 -> Text = "Male";
this -> button5 -> Text = "Female";
this -> button4 -> Visible = true;
this -> button5 -> Visible = true;
YesorNo = 5;
}
else if (YesorNo == 5)
{
Gender = "Female";
this -> label2 -> Text = "What is your Race??";
this -> button4 -> Text = "Earth Pony";
this -> button5 -> Text = "Unicorn";
this -> button2 -> Visible = true;
this -> button2 -> Text = "Pegasus";
YesorNo = 6;
}
else if (YesorNo == 6)
{
Race = "Unicorn";
this -> button2 -> Visible = false;
this -> button4 -> Visible = false;
this -> button5 -> Visible = false;
label2 -> Text = "Thank You For Playing!!";
YesorNo = 7;
this -> timer1 -> Start();
}
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
this -> button3 -> Text = "None yet";
}
private: System::Void textBox1_TextChanged_1(System::Object^ sender, System::EventArgs^ e) {
this -> label1 -> Visible = true;
CharName = textBox1 -> Text;
label1 -> Text = CharName;
this -> button5 -> Visible = true;
this -> button5 -> Text = "Done?";
YesorNo = 4;
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
TimerValue+= 1000;
if (TimerValue == 5000)
{
Form2 ^ f2 = gcnew Form2;
f2->Show();
this->Hide();
MoviePlay = 1;
StreamWriter^ outFile = gcnew StreamWriter("Movie.txt");
String^ Movie = MoviePlay.ToString();
outFile->Write(Movie);
outFile->Close();
this -> timer1 -> Stop();
}
}
};
}
Why can I not open Form 2?
2010\projects\retaliation\retaliation\Form1.h(431): error C2065: 'Form2' : undeclared identifier
Is refering to...
Form2 ^ f2 = gcnew Form2; at the bottom
Just in case it has to do with a problem in Form2...
#pragma once
#include "stdAfx.h"
#include "Form1.h"
#include "Form2.h"
namespace Retaliation {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace std;
/// <summary>
/// Summary for Form2
/// </summary>
public ref class Form2 : public System::Windows::Forms::Form
{
public:
int MoviePlay;
Form2(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form2()
{
if (components)
{
delete components;
}
}
private: AxWMPLib::AxWindowsMediaPlayer^ MoviePlayer1;
protected:
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form2::typeid));
this->MoviePlayer1 = (gcnew AxWMPLib::AxWindowsMediaPlayer());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->MoviePlayer1))->BeginInit();
this->SuspendLayout();
//
// MoviePlayer1
//
this->MoviePlayer1->Enabled = true;
this->MoviePlayer1->Location = System::Drawing::Point(0, 0);
this->MoviePlayer1->Name = L"MoviePlayer1";
this->MoviePlayer1->OcxState = (cli::safe_cast<System::Windows::Forms::AxHost::State^ >(resources- >GetObject(L"MoviePlayer1.OcxState")));
this->MoviePlayer1->Size = System::Drawing::Size(860, 497);
this->MoviePlayer1->TabIndex = 0;
this->MoviePlayer1->Enter += gcnew System::EventHandler(this, &Form2::axWindowsMediaPlayer1_Enter);
//
// Form2
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(859, 495);
this->Controls->Add(this->MoviePlayer1);
this->Name = L"Form2";
this->Text = L"Form2";
this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->MoviePlayer1))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void axWindowsMediaPlayer1_Enter(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void Form2_Load(System::Object^ sender, System::EventArgs^ e) {
if (MoviePlay == 1)
{
MoviePlayer1->URL = "\\Scv183\\Scene1.mpeg";
MoviePlayer1 -> Ctlcontrols -> play();
}
}
};
}
You are getting an error because you have a circular dependency in your header files.
Your compiler is trying to compile Form2.cpp, where you include Form1.h, in Form1.h you include Form2.h, and in Form2.h you include Form1.h. You need to use a forward declaration, or to change your design so that you class are less coupled.
Moreover don't include a headerfile in itself..
More generally, you should not implement your function definitions in header files, but use your .cpp files for that. I also don't think you need to use precompiled headers (stdAfx.h), you should disable the check-box when you create a Visual Studio project.
Follow these steps:
Create a new project. Form1 is created by default.
Create a button on Form1, double click it and paste the code below:
Form2^ testDialog = gcnew Form2;
testDialog->ShowDialog (this);
delete testDialog;
Go to solution explorer, right click the project and add a new Form and save it as Form2.
Double click Form1.cpp and you will see that it starts with the following lines:
#include "stdafx.h"
#include "Form1.h"
Edit it as follows:
#include "stdafx.h"
#include "Form2.h"
#include "Form1.h"
Note: The sequence of #include should not be changed.
Go ahead, run your project and enjoy!!!!
Prasanth

Using callback function in a directshow filter cause memory leaks

I am using third party API which I get streams from a callback function
int OnNewImage(BYTE *pData, int nLen)
When I run a simple C++ sample program from console
int continue = 1;
int OnNewImage(BYTE *pData, int nLen)
{
std::cout << "On new image is called" << std::endl;
return continue;
}
int main()
{
// This will block
int result = DownloadStream(/*params*/...,OnNewImage /*callbackfunction*/);
return 0;
}
I get no memory leaks.[ memory does not increase ]
But When I use this callback function in a directshow filter, it
produce memory leaks.[ memory increase regularly]
What may cause this? And how can I fix it? Any ideas?
UPDATE: My DirectShow Filter structure
What I do:
Basically
I get streams at "unsigned __stdcall DVRStreamThread(LPVOID
pvParam)" function which call back OnNewImage
Then i insert frames into my queue inside that callback[OnNewImage]
Finally At FillBuffer I consume frames from queue.
It is am h264 stream. I can able to set simple graph like this
MySourceFilter ---> H264 Decoder ---> Video Renderer
Here is my FilterSourceCode:
Well I have a simple queue which i insert incoming frames then consume:
SynchronisedQueue
template <typename T>
class SynchronisedQueue
{
public:
void Enqueue(const T& data)
{
boost::unique_lock<boost::mutex> lock(queueMutex);
dataQueue.push(data);
conditionVariable.notify_one();
}
T Dequeue()
{
boost::unique_lock<boost::mutex> lock(queueMutex);
while (dataQueue.size()==0)
{
conditionVariable.wait(lock);
}
T result=dataQueue.front(); dataQueue.pop();
return result;
}
int Size()
{
boost::unique_lock<boost::mutex> lock(queueMutex);
int size = dataQueue.size();
return size;
}
private:
std::queue<T> dataQueue;
boost::mutex queueMutex;
boost::condition_variable conditionVariable;
};
Then My Filter:
DvrSourceFilter [ header]
#define DVRSourceFilterName L"DVRDirectShowFilter"
#include <streams.h>
#include <process.h>
#include <MyDvrApi.h>
#include "SynchronisedQueue.h"
// {F89A85DA-F77C-4d44-893B-CCA43A49E7EF}
DEFINE_GUID(CLSID_DVRSourceFilter,
0xf89a85da, 0xf77c, 0x4d44, 0x89, 0x3b, 0xcc, 0xa4, 0x3a, 0x49, 0xe7, 0xef);
class DECLSPEC_UUID("34363248-0000-0010-8000-00AA00389B71") Subtype_H264;
class DVRSourceFilter;
using namespace std;
/*
* **********************
* DVRPin
* **********************
*/
class DVRPin : public CSourceStream
{
public:
DVRPin(HRESULT *phr, DVRSourceFilter *pFilter);
~DVRPin();
// Override the version that offers exactly one media type
HRESULT GetMediaType(CMediaType *pMediaType);
HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pRequest);
HRESULT FillBuffer(IMediaSample *pSample);
static int OnNewImage(void *pUser, BYTE *pData, int nLen, int nCh, int tMts, int nType, void *returnHandle);
// Setters
void SetDvrIp(char* dvrIp);
void SetDvrPort( int dvrPort);
void SetDvrUserName( char * userName);
void SetDvrPassword(char* password);
void SetStartTime(int startTime);
void SetMilliSecond(int milliSecond);
void SetChannelNumber(int channelNumber);
void SetSize(int width, int height);
// Getters
char* GetDvrIp();
int GetDvrPort();
char* GetDvrUserName();
char* GetDvrPassword();
int GetStartTime();
int GetMilliSecond();
int GetChannelNumber();
int GetMode();
public:
char* dvrIp;
int dvrPort;
char* userName;
char* password;
int startTime;
int milliSecond;
int channelNumber;
BITMAPINFOHEADER m_bmpInfo;
BYTE* m_RGB24Buffer;
DWORD m_RGB24BufferSize;
bool streamCompleted;
int hDecHandle;
HANDLE m_hDVRStreamThreadHandle;
unsigned int m_dwThreadID;
SynchronisedQueue<std::vector<BYTE>> IncomingFramesQueue;
protected:
virtual HRESULT OnThreadCreate();
virtual HRESULT OnThreadDestroy();
virtual HRESULT DoBufferProcessingLoop();
};
/*
* **********************
* DVRSourceFilter
* *********************
*
*/
class DVRSourceFilter : public CSource
{
public:
DECLARE_IUNKNOWN;
static CUnknown * WINAPI CreateInstance(IUnknown *pUnk, HRESULT *phr);
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void **ppv);
void SetDVRLiveParameters(char* dvrIP, int dvrPort, char* userName, char* password, int channelNumber, int width, int height);
private:
DVRSourceFilter(IUnknown *pUnk, HRESULT *phr);
~DVRSourceFilter();
private:
DVRPin *m_pPin;
};
DvrSourceFilter [implementation]
#include "DvrSourceFilter.h"
unsigned __stdcall DVRStreamThread(LPVOID pvParam)
{
DVRPin* streamReader = (DVRPin*)pvParam;
int channelBits = 1 << (streamReader->channelNumber - 1);
streamReader->m_RGB24BufferSize = streamReader->m_bmpInfo.biWidth * streamReader->m_bmpInfo.biHeight * 3;
streamReader->m_RGB24Buffer = (BYTE*)malloc(streamReader->m_RGB24BufferSize);
DownloadStream((LPCTSTR)streamReader->dvrIp,
streamReader->dvrPort , (LPCTSTR)streamReader->userName ,
(LPCTSTR)streamReader->password , channelBits, channelBits,
streamReader->startTime, streamReader->milliSecond,
streamReader->OnNewImage, (void*)streamReader);
streamReader->startTime = -2; // End Of Stream
return 0;
}
/*
* ******************
* DVRPin Class
* ******************
*/
DVRPin::DVRPin(HRESULT *phr, DVRSourceFilter *pFilter)
: CSourceStream(NAME("DVR Source Bitmap"), phr, pFilter, L"Out")
{
m_bmpInfo.biSize = sizeof(BITMAPINFOHEADER);
m_bmpInfo.biCompression = BI_RGB;
m_bmpInfo.biBitCount = 24;
m_bmpInfo.biPlanes = 1;
m_bmpInfo.biClrImportant = 0;
m_bmpInfo.biClrUsed = 0;
m_bmpInfo.biXPelsPerMeter = 0;
m_bmpInfo.biYPelsPerMeter = 0;
hDecHandle = 0;
m_RGB24Buffer = NULL;
m_RGB24BufferSize = 0;
streamCompleted = false;
startTime = -1; // Live Stream
*phr = S_OK;
}
DVRPin::~DVRPin()
{
}
int DVRPin::OnNewImage(void *pUser, BYTE *pData, int nLen, int nCh, int tMts, int nType, void *returnHandle)
{
DVRPin* reader = (DVRPin*)pUser;
if(reader->streamCompleted)
{
return false;
}
if(pData)
{
std::vector<BYTE> vecFrame(pData, pData + nLen/sizeof(pData[0]));
reader->IncomingFramesQueue.Enqueue(vecFrame);
}
return !reader->streamCompleted;
}
HRESULT DVRPin::OnThreadCreate()
{
m_hDVRStreamThreadHandle =
(HANDLE)_beginthreadex(NULL, 0, &DVRStreamThread, (void*)this, 0, &m_dwThreadID);
return S_OK;
}
HRESULT DVRPin::OnThreadDestroy() {
streamCompleted = true;
_endthreadex(0);
CloseHandle(m_hDVRStreamThreadHandle);
return S_OK;
}
HRESULT DVRPin::GetMediaType(CMediaType *pMediaType)
{
CAutoLock cAutoLock(m_pFilter->pStateLock());
CheckPointer(pMediaType, E_POINTER);
VIDEOINFOHEADER* pvi = (VIDEOINFOHEADER*)pMediaType->AllocFormatBuffer(sizeof(VIDEOINFOHEADER));
if (pvi == 0)
return(E_OUTOFMEMORY);
ZeroMemory(pvi, pMediaType->cbFormat);
pvi->bmiHeader = m_bmpInfo;
pvi->bmiHeader.biSizeImage = GetBitmapSize(&pvi->bmiHeader);
SetRectEmpty(&(pvi->rcSource));
SetRectEmpty(&(pvi->rcTarget));
pMediaType->SetType(&MEDIATYPE_Video);
pMediaType->SetFormatType(&FORMAT_VideoInfo);
pMediaType->SetTemporalCompression(FALSE);
// Work out the GUID for the subtype from the header info.
const GUID SubTypeGUID = __uuidof(Subtype_H264);//GetBitmapSubtype(&pvi->bmiHeader);
pMediaType->SetSubtype(&SubTypeGUID);
pMediaType->SetSampleSize(pvi->bmiHeader.biSizeImage);
return S_OK;
}
HRESULT DVRPin::DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pRequest)
{
HRESULT hr;
CAutoLock cAutoLock(m_pFilter->pStateLock());
CheckPointer(pAlloc, E_POINTER);
CheckPointer(pRequest, E_POINTER);
VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER*) m_mt.Format();
if (pRequest->cBuffers == 0)
{
pRequest->cBuffers = 2;
}
pRequest->cbBuffer = pvi->bmiHeader.biSizeImage;
ALLOCATOR_PROPERTIES Actual;
hr = pAlloc->SetProperties(pRequest, &Actual);
if (FAILED(hr))
{
return hr;
}
if (Actual.cbBuffer < pRequest->cbBuffer)
{
return E_FAIL;
}
return S_OK;
}
HRESULT DVRPin::FillBuffer(IMediaSample *pSample)
{
if(!streamCompleted)
{
CAutoLock cAutoLock(m_pLock);
HRESULT hr;
BYTE* pData = NULL;
hr = pSample->GetPointer(&pData);
if(FAILED(hr))
{
pSample->Release();
return hr;
}
if(IncomingFramesQueue.Size() <= 0) {
return S_OK;
}
vector<BYTE> data = IncomingFramesQueue.Dequeue();
int dataSize = (int)data.size();
if(dataSize <= 0 || dataSize > 1000000)
{
return S_OK;
}
memcpy(pData, &data[0], dataSize);
hr = pSample->SetActualDataLength(dataSize);
if(FAILED(hr))
{
pSample->Release();
return hr;
}
hr = pSample->SetSyncPoint(TRUE);
if(FAILED(hr))
{
pSample->Release();
return hr;
}
pSample->Release();
}
return S_OK;
}
HRESULT DVRPin::DoBufferProcessingLoop() {
Command com;
REFERENCE_TIME rtNow = 0L;
REFERENCE_TIME rtAdvise = 0L;
OnThreadStartPlay();
do {
while (!streamCompleted && !CheckRequest(&com)) {
IncomingFramesQueue.WaitUntilHaveElements();
IMediaSample *pSample;
HRESULT hr = GetDeliveryBuffer(&pSample,NULL,NULL,FALSE);
if (FAILED(hr)) {
continue; // go round again. Perhaps the error will go away
// or the allocator is decommited & we will be asked to
// exit soon.
}
hr = FillBuffer(pSample);
if (hr == S_OK) {
Deliver(pSample);
} else if (hr == S_FALSE) {
pSample->Release();
DeliverEndOfStream();
return S_FALSE;
} else {
// Log Error
}
pSample->Release();
}
if (com == CMD_RUN || com == CMD_PAUSE)
com = GetRequest(); // throw command away
else if (com != CMD_STOP)
{
// Log Error
}
} while (!streamCompleted && com != CMD_STOP);
return S_OK;
}
void DVRPin::SetDvrIp( char* dvrIp )
{
this->dvrIp = dvrIp;
}
void DVRPin::SetDvrPort( int dvrPort )
{
this->dvrPort = dvrPort;
}
void DVRPin::SetDvrUserName( char * userName )
{
this->userName = userName;
}
void DVRPin::SetDvrPassword( char* password )
{
this->password = password;
}
void DVRPin::SetStartTime( int startTime )
{
this->startTime = startTime;
}
void DVRPin::SetMilliSecond( int milliSecond )
{
this->milliSecond = milliSecond;
}
void DVRPin::SetSize(int width, int height) {
m_bmpInfo.biWidth = width;
m_bmpInfo.biHeight = height;
m_bmpInfo.biSizeImage = GetBitmapSize(&m_bmpInfo);
}
char* DVRPin::GetDvrIp()
{
return dvrIp;
}
int DVRPin::GetDvrPort()
{
return dvrPort;
}
char* DVRPin::GetDvrUserName()
{
return userName;
}
char* DVRPin::GetDvrPassword()
{
return password;
}
int DVRPin::GetStartTime()
{
return startTime;
}
int DVRPin::GetMilliSecond()
{
return milliSecond;
}
void DVRPin::SetChannelNumber( int channelNumber )
{
this->channelNumber = channelNumber;
}
int DVRPin::GetChannelNumber()
{
return channelNumber;
}
/*
* ****************************
* DVRSourceFilter Class
* ***************************
*/
DVRSourceFilter::DVRSourceFilter(IUnknown *pUnk, HRESULT *phr)
: CSource(NAME("DVRSourceBitmap"), pUnk, CLSID_DVRSourceFilter)
{
// The pin magically adds itself to our pin array.
m_pPin = new DVRPin(phr, this);
// Just for test at graph studio
SetDVRLiveParameters("192.168.3.151", 7000, "admin", "000000", 3, 352, 288);
if (phr)
{
if (m_pPin == NULL)
*phr = E_OUTOFMEMORY;
else
*phr = S_OK;
}
}
DVRSourceFilter::~DVRSourceFilter()
{
delete m_pPin;
}
CUnknown * WINAPI DVRSourceFilter::CreateInstance(IUnknown *pUnk, HRESULT *phr)
{
DVRSourceFilter *pNewFilter = new DVRSourceFilter(pUnk, phr);
if (phr)
{
if (pNewFilter == NULL)
*phr = E_OUTOFMEMORY;
else
*phr = S_OK;
}
return pNewFilter;
}
STDMETHODIMP DVRSourceFilter::NonDelegatingQueryInterface( REFIID riid, void **ppv )
{
return CSource::NonDelegatingQueryInterface(riid, ppv);
}
void DVRSourceFilter::SetDVRLiveParameters( char* dvrIP, int dvrPort, char* userName, char* password, int channelNumber, int width, int height )
{
m_pPin->SetDvrIp(dvrIP);
m_pPin->SetDvrPort(dvrPort);
m_pPin->SetDvrUserName(userName);
m_pPin->SetDvrPassword(password);
m_pPin->SetChannelNumber(channelNumber);
m_pPin->SetStartTime(-1);// Live Stream
m_pPin->SetMilliSecond(0);
m_pPin->SetSize(width, height);
}
...
To make directshow Filter simple [ to understand memory leak source], just implement OnNewImage function and FillBufferFunction as "dummy", but still has memory leak:
int DVRPin::OnNewImage(void *pUser, BYTE *pData, int nLen, int nCh, int tMts, int nType, void *returnHandle)
{
return 1; // for not to end call back
}
HRESULT DVRPin::FillBuffer(IMediaSample *pSample)
{
pSample->Release();
return S_OK;
}
In DVRStreamThread, you have:
streamReader->m_RGB24Buffer = (BYTE*)malloc(streamReader->m_RGB24BufferSize);
But I don't see a matching call to free() anywhere. When your DVRPin object is deleted, you will have to explicitly free the data pointed to by its m_RGB24Buffer member.
First thing I see, is that your destructors are not virtual. This might be a cause of leaks when release is not taking place when inheritance is used. See related article about the necessity of virtual destructors.

How to change RibbonStatusBarPane text color?

My application is using MFC Ribbon(VS2008 + Feature pack9).
I'm not able to change RibbonStatus Bar Pane text color.I override the virtual int DrawPaneText(CDC* pDC, const CString& strText, CRect rectText, UINT uiDTFlags) function but things are not working.
In non Ribbon Status Bar there is a function void SetPaneTextColor(int nIndex, COLORREF clrText = (COLORREF)-1 , BOOL bUpdate) in order to change pane text color.
how to do this in MFCRibbonStatusBarPane ?
class MyPane : public CMFCRibbonStatusBarPane
{
public:
MyPane(){};
MyPane(
UINT nCmdID,
LPCTSTR lpszText,
BOOL bIsStatic = FALSE,
HICON hIcon = NULL,
LPCTSTR lpszAlmostLargeText = NULL)
:CMFCRibbonStatusBarPane(nCmdID,
lpszText,bIsStatic,hIcon,lpszAlmostLargeText){}
MyPane(
UINT nCmdID,
LPCTSTR lpszText,
HBITMAP hBmpAnimationList, list
int cxAnimation = 16,
COLORREF clrTrnsp= RGB(192,192,192),
HICON hIcon = NULL,
BOOL bIsStatic = FALSE)
:CMFCRibbonStatusBarPane(nCmdID,lpszText,
hBmpAnimationList,cxAnimation,clrTrnsp,hIcon,bIsStatic){}
MyPane(
UINT nCmdID,
LPCTSTR lpszText,
UINT uiAnimationListResID,
int cxAnimation = 16,
COLORREF clrTrnsp= RGB(192,192,192),
HICON hIcon = NULL,
BOOL bIsStatic = FALSE)
:CMFCRibbonStatusBarPane(nCmdID,lpszText,
uiAnimationListResID,cxAnimation,clrTrnsp, hIcon,bIsStatic){}
~MyPane(){};
virtual COLORREF OnFillBackground(CDC* pDC)override
{
return RGB(255,0,0); //return whatever new color you want
}
};
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
[...]
m_wndStatusBar.AddElement(new MyPane(ID_STATUSBAR_PANE1, strTitlePane1, TRUE), strTitlePane1);
m_wndStatusBar.AddExtendedElement(new MyPane(ID_STATUSBAR_PANE2, strTitlePane2, TRUE), strTitlePane2);
[...]
}

Resources