Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all 3033 articles
Browse latest View live

add to listbox thread

$
0
0
startthread get called to launch to update list box.
a)is it the only way to pass string to the PostMessage?. my concern is that allocate using new in each iteration each time slows it down a bit.
b)does OnAddToListBox look memory leak free?.
c)What is the best way handle m_pThread at the end?. Anyway to improve it?.

Code:

UINT CMyDlg::Dump(LPVOID lparam) 

    HWND *pHndl = static_cast<HWND *>(lparam);
    char buffer[200];
    for (int i = 0; i < 100; i++)
    {
        sprintf_s(buf,"user %d, data %s",i, "Connected");
        ::PostMessage(*pHndl, UWM_ADD_To_LBox, 0, (WPARAM)(new CString(buffer)));
    }
    delete pHndl;
}

void CMyDlg::startthread(LPVOID lparam) 
{
        HWND *pHndl = new HWND;
        *pHndl = GetSafeHwnd();
        m_pThread = AfxBeginThread(Dump, pHndl);
}

LRESULT CMyDlg::OnAddToListBox(WPARAM wParam,LPARAM lParam)
{
        std::auto_ptr<CString> text(reinterpret_cast<CString*>(lParam));
          m_listbox.AddString(*text);
          m_listbox.RedrawWindow();
          return 0;
}


Skip And Rotate View A Page In Property Sheet

$
0
0
Hi,
When i click the back button, I like to skip some old pages & rotate pages view in my property sheet.

I have 5 pages, when i clicked the User button in my MainDlg the below function called like,
User Button Clicked -> Page1 Opened
Next Button Clicked
-> Page2 -> Page3 -> Page4 -> Page5
Back Button Clicked
Page1 <- Page2 <- Page3 <- Page4 <- Page5

This work done. working good.
Code:

void MainDlg:: onButtonUserClicked()
{
  CSheet oSht(this);
  Page1 p1;
  Page2 p2.
  Page3 p3;
  Page4 p4;
  Page5 p5;

  oSht.AddPag(&p1, Page1::IDD);
  oSht.AddPag(&p2, Page2::IDD);
  oSht.AddPag(&p3, Page3::IDD);
  oSht.AddPag(&p4, Page4::IDD);
  oSht.AddPag(&p5, Page5::IDD);

  if(oSht.Domodal() == ID_WIZFINISH)
  {
      ::AfxmessageBox("Finished");
  }
  else
  {
  }
}

My requirement is,
User Button Clicked -> Page1 Opened
Next Button Clicked
-> Page2 -> Page3 -> Page4-> Page5 -> Page1(Again called 1st page automatically - rotate pages view)
Back Button Clicked(Cur Page loc is Page5)
(Start the prev Process)Page5 <- Page1 <- (Skip the Page2 & 3)Page4 <- Page5

Is this possible ?

My difficulty in this section

$
0
0
Hi,

I read some part a C++ book explaining lists. But I think the author has mistaken in that. If possible, please read section 17.9.3. An example: Lists, of this link http://books.google.com/books?id=We2...epage&q&f=true.

I consider the predecessor (pred) as prior Link and successor (succ) as next Link. And the direction of expand to be from left to write. That is, if we have Link l1, the next Link, l2, will be new and therefore, in the right side of the previous Link, l1.

I think there is some mistake or wrong replacement in places of prep & succ and also in the code. Can you understand that section and you think it has not any wrong?

Thanks.

[RESOLVED] Skip And Rotate View A Page In Property Sheet

$
0
0
Hi,
When i click the back button, I like to skip some old pages & rotate pages view in my property sheet.

I have 5 pages, when i clicked the User button in my MainDlg the below function called like,
User Button Clicked -> Page1 Opened
Next Button Clicked
-> Page2 -> Page3 -> Page4 -> Page5
Back Button Clicked
Page1 <- Page2 <- Page3 <- Page4 <- Page5

This work done. working good.
Code:

void MainDlg:: onButtonUserClicked()
{
  CSheet oSht(this);
  Page1 p1;
  Page2 p2.
  Page3 p3;
  Page4 p4;
  Page5 p5;

  oSht.AddPag(&p1, Page1::IDD);
  oSht.AddPag(&p2, Page2::IDD);
  oSht.AddPag(&p3, Page3::IDD);
  oSht.AddPag(&p4, Page4::IDD);
  oSht.AddPag(&p5, Page5::IDD);

  if(oSht.Domodal() == ID_WIZFINISH)
  {
      ::AfxmessageBox("Finished");
  }
  else
  {
  }
}

My requirement is,
User Button Clicked -> Page1 Opened
Next Button Clicked
-> Page2 -> Page3 -> Page4-> Page5 -> Page1(Again called 1st page automatically - rotate pages view)
Back Button Clicked(Cur Page loc is Page5)
(Start the prev Process)Page5 <- Page1 <- (Skip the Page2 & 3)Page4 <- Page5

Is this possible ?

Explore current path

$
0
0
I quite often use an ide written in assembler: RadAsm3(https://fbedit.svn.sourceforge.net/s...ase/RadASM.zip)

It has a menu item to explore current path.
I have used other ide's that have a similar feature but:
The one in RadAsm3 will activate a current Explorer window if the current path is the same as the one requested.
All others open a new Explorer window.

I would like to implement the RadAsm3 approach using Visual Studio 2013 Community c++ as my host compiler for testing.

I tried to get the title of current windows but it appears ShellExecute "explore" does not produce a conventional window???

Any suggestions?

James

taking decimal input from the user in c++

$
0
0
I want the input for the price in decimal format(15.00). If the input is in integer format then I want to convert it to decimal format.

The maximum price for a sale is 999.99 and minimum is 0.00.

I have tried so far:

Code:

#include<iostream>
using std::cout;
using std::cin;

void main(){
    float eventPrice;

    bool cPrice = true;
    while (cPrice)
    {
        cout << "Please enter the event ticket price:";
        cin >> eventPrice;
        if (eventPrice <= 999.99 && eventPrice>=0) cPrice = false;
        else
        {
            cout << "Invlaid price. Try again!!";
        }
    }
    cout << "the price is:";
        cout << eventPrice;
}

Avalid input will be:

1.8,
0.8,
0.00,
0,
9,
99

adding rational number using only class functions

$
0
0
Hi, i'm having trouble finishing this program. What I’m trying to do is create a class for Rational numbers. Get input from user for denominator and numerator. Store the numbers without a sign, and for the sign store it separately in char. I’m not supposed to use accessor functions. The part that I can’t seem to know how to do is use the info that was stored in the addUp function. This function need to add two rational numbers. i need to make this function general enough that it can handle two fractions, or a fraction and a whole number, or two whole numbers. What I already have here is readin function which reads in the numerator and denominator. setnumerator and setdenominator to assign positive values. setsign should get the sign of the fraction. Finally addUp should addUp which I explained before. I have some ideas about writing the tests, but can’t seem to know how to implement it to the program. The main program is still empty but all I’m supposed to do there is call the class functions, which my because of my lake of experience I can’t seem to figure out where to start.


Code:

#include <iostream>

using namespace std;

class Rational
{
private:
       
        int numerator, denominator;
        char sign;
       
public:

        Rational(const int denominator = 1, const char sign = '+');  // constructor.  Will set beginning balance to zero
        int setnumerator(const int numerator);
        int setdenominator(const int denominator);
        char setsign(const int numerator, const int denominator, const char sign);
        void PrintFraction();
        void readint();
        Rational addUp(Rational first, Rational second);

};




int main()
{

       



        system ("PAUSE");
        return 0;
}





Rational::Rational(const int denominator, const char sign)  // the constructor
{

}

int Rational::setnumerator(const int numerator)
{

        if (numerator<0)
                {
                        int numer = numerator * -1;
                        return numer;
                }
        else
                {
                        int numer = numerator;
                        return numer;
                }

}

int Rational::setdenominator(const int denominator)
{
       
                if (denominator<0)
                        {
                                int denom = denominator * -1;
                                return denom;
                        }
                else
                        {
                                int denom = denominator;
                                return denom;
                        }

}

char Rational::setsign(const int numerator, const int denominator, const char sign)
{

        if (denominator>0 && numerator>0 || denominator<0 && numerator<0)
                {

                        char fianlsign = '+';
                        return fianlsign;
                }
        char fianlsign = '-';
        return fianlsign;

}

void Rational::PrintFraction()
{
        if (denominator!=1)
                {
                        cout<<sign<<numerator<<"/"<<denominator;
                }
        cout<<sign<<numerator;
}

void Rational::readint()
{
       
        cout<<"enter numerator: ";
        cin>>numerator;
        cout<<"enter denominator: ";
        cin>>denominator;

        return;

}

Rational addUp(Rational first, Rational second)
{

}

How to change the client area icon during runtime

$
0
0
Having searched extensively, I'm sorry to report that I cannot find any code examples of how to change the mouse tracking icon during runtime. I wish to emulate the Microsoft Paint app behavior with respect, for example, to click on a toolbar button such as the 'Fill With Color' bucket and have the mouse pointer icon change to a little bucket. I wish to do this in an MFC SDI app. Any help greatly appreciated. FWIW, I have tried various Microsoft web help code but nothing seems to work for me as I'm probably missing something.

Here's a bit of code that does nothing that I can tell, although it compiles and runs. (m_hIcon2 is a member HANDLE, IDI_FLOODFILL is an existing icon in the app resources). I have come across numerous other examples that do not work and/or will not compile using VS 2010 Win7(64).

Code:

void CMainFrame::SetNewIcon()
{

        m_hIcon2 = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_FLOODFILL));
        SetIcon(m_hIcon2, FALSE);


}// SetNewIcon()

void CMainFrame::OnFloodFill()
{
        TRACE0("Clicked on Flood Fill toolbar button\n");

        //m_wndToolBar2.GetToolBarCtrl().
        //UINT nStyle = 0;
        //m_wndToolBar2.SetButtonStyle(13, nStyle);
        m_bFloodFill = !m_bFloodFill;

        if(m_bFloodFill) { TRACE0("Need to change the icon to IDI_FLOODFILL here.\n"); SetNewIcon(); }
        if(!m_bFloodFill) { TRACE0("Need to change the icon from IDI_FLOODFILL to standard here.\n"); }

}


void CMainFrame::OnUpdateFloodFill(CCmdUI* pCmdUI)
{
        pCmdUI->SetCheck(m_bFloodFill); 
       
}

Any help greatly appreciated.

check type

$
0
0
How to check the type of argument passed to each function, checktype, in below?.
void checktype(void *p)
{
}

or

template <typename Type>
Type checktype(Type t) {

}

what is std::container_base12 and std::container_base0

$
0
0
Hi, folks,

I am trying to pass a std::string from one dll to another by boost::any. It is odd that the first 4 letters are always lost during this process, i.e. the buffer pointer is shifted by 4 bytes. When I looked into the code, it turned out that in one dll, std::container_base0 is used while in native C++ std::container_base12 is used instead. I suspect that is what caused the problem. Does anyone know how to tell the compilers to use the same container?

Thanks a lot,
CR

Can't understand the question

$
0
0
Hello guys,

I can't understand what does the question want, to write appropriate code for it. Would you please read it to find out what it exactly wants?

Modify the Link class from 17.10.1 to hold a value of a class God. Class God should have members of type string: name, mythology, vehicle, weapon. For example God("Zeus", "Greek", "", "lightning") and God("Odin","Norse", "Eight-tagged flying horse called Sleipner",""). Write a print_all() function that lists gods with their attributes one per line. Add a member function add_ordered() that places its new element in its current lexicographical position. Using the Links with the values of type God, make a list of god from three lexicographically ordered lists - one per each mythology.

The 17.10.1 is here:
http://books.google.com/books?id=We2...epage&q&f=true

Problems are these:
What is "gods"? Of which class is it?
" Add a member function add_ordered() ..." to what class?
What is that meant by "a value of a class God"? An object?

Can you understand the question completely?

Getting exceptions on Windows 7 and Windows 8 on different parts of the Code

$
0
0
Hi,
I'm Getting exceptions on Windows 7 and Windows 8 on different parts of the Code? any idea of why this can be happening, why the difference in behavior?
I appreciate your Ideas!!:confused:

Thanks

App -- Engine interaction need help

$
0
0
In learning purposes I've started to create my own game engine using C++, OpenGL 3.3, XAudio2 and some minor dependencies
The problems i reach are most commonly about structure of engine itself, like where does the App begins and Engine ends?
Name:  schemeengine.jpg
Views: 111
Size:  93.6 KB
For now I have Engine project building into .lib, and Editor project building into .exe, that depends on Engine.lib and uses it:
Name:  projectlist.jpg
Views: 110
Size:  90.8 KB

-----------------------------------

The problem is i need my Logic of App to react on events like Update, click on Button, how do i achieve that if Engine must be a built-ready alone app, not depending on my Logic.h, but Logic.h must react on events in Engine?

I thought about engineSetButtonPressCallback(void (*p)(...)), engineSetUpdateCallback(void (*p)()), but that seems wrong, like accessing not your own scope

So if Engine and App are 2 different entities, who can transport events from Engine to App? I prefer not to use OOP, so Engine is not a class, and App can't be like class App:Engine, so i could use virtual methods

-----------------------------------

main.cpp is like:
Code:

int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
        // Pre-init
        CoInitialize(0); // COM init
        std::ios::sync_with_stdio(false); // super fast io

        ResetCurrentDirectory();

        // Init

        swEngineInit();

        //

        logicInit();
       
        // Run

       

        swEngineRun();

        // Release

        swEngineRelease();

        // Exit

        closelog();
        CoUninitialize();

        return 0; // end app
}

logic comes for smth like that:

Code:

#include "Logic.h"

// globals

bool bUILoaded = false;



// end globals

void preloadUI()
{
        std::ifstream input("UIList.txt", std::ios::in);
        char buffer[256]; string line;
        while(input.getline(buffer, 255))
        {
                line = buffer;
                if(line != "")
                {
                        tpPreloadTexture(line, TEXTURE_TYPE_SHARP);
                }
        }

        input.close();
       
        bUILoaded = true;
}

void logicInit()
{
        tpPreloadTexture("Graphic/UI/LoadScreen.png", TEXTURE_TYPE_SHARP);
        uiSetBackground("Graphic/UI/LoadScreen.png");

        Sprite s;
        s.name = "test";
        s.relx = 0.5;
        s.rely = 0.5;
        s.posy = 60;
        s.width = 100;
        s.height = 60;
        s.texture = "Graphic/UI/ButtonStart.png";
        uiAddSprite(s);

       

        saDestroyOnEnd(saCreateSound("Sound/Arrow/arrwdth_02.ogg"));

        preloadUI();
}

void logicUpdate()
{
       
}

void logicSpritePress(string name)
{

}

void logicButtonPress(string name)
{

}

the main loop stuff hiden in engine:

Code:

void swEngineRun()
{
        printlog("message: entering win loop");
        waEventLoop();
}

winapi, depending highly on framework GLFW:

Code:

void waEventLoop()
{
        LARGE_INTEGER timeFrequency;
        LARGE_INTEGER timeNow;
        bool useQPC = QueryPerformanceFrequency(&timeFrequency);
        double prevTime = 0.0;

        if(useQPC)
        {
                QueryPerformanceCounter(&timeNow);
                dCreateTime = (1000LL * timeNow.QuadPart) / timeFrequency.QuadPart * 0.001;
        } else
                dCreateTime = GetTickCount() * 0.001;

        while(true)
        {
                glfwPollEvents();

                if(bErrorFlag)
                {
                        printlog("message: fatal error in engine, closing win loop");
                        break;
                }

                if(bExitFlag)
                {
                        printlog("message: exit message recieved, closing win loop");
                        break;
                }

                prevTime=dRealTime;

                if(useQPC)
                {
                        QueryPerformanceCounter(&timeNow);
                        dRealTime = (1000LL * timeNow.QuadPart) / timeFrequency.QuadPart * 0.001;
                } else
                        dRealTime = GetTickCount() * 0.001;

                bPrevMouseLeft = glfwGetMouseButton(hWindow, GLFW_MOUSE_BUTTON_LEFT);
                bPrevMouseRight = glfwGetMouseButton(hWindow, GLFW_MOUSE_BUTTON_RIGHT);
                for(int i = 0; i < 512; i++)
                {
                        bPrevKey[i] = glfwGetKey(hWindow, i);
                }

                if(dRealTime - dTime >= UPDATE_INTERVAL)
                {
                        dTime += UPDATE_INTERVAL;
                        if(dRealTime - dTime > UPDATE_INTERVAL * UPDATE_DEATH)
                        {
                                dTime = dRealTime - UPDATE_INTERVAL * UPDATE_DEATH;
                        }

                        // update

                        swEngineUpdate();

                        // errors

                        if(saGetErrorFlag()) bErrorFlag = true;
                        if(raGetErrorFlag()) bErrorFlag = true;

                        glfwSwapBuffers(hWindow);
                }

                if(!glfwGetWindowAttrib(hWindow, GLFW_FOCUSED))
                {
                        Sleep(2);
                }
        }
}

engine update is like:

Code:

void swEngineUpdate()
{
        // update

        uiUpdate();

        // render

        raRenderStart();

        uiRender();

        raRenderEnd();
}

--------------------------------------------

sorry for my crappy english, i hope u understood my question and can help me with the topic, im solving this question for a long time. also sorry for in-text attachments, can't find the spoiler button :/
Attached Images
  

What is the correct way of calling a self-contained posix thread in VC++?

$
0
0
pThread turns out to be NULL here.
Wondering what the correct way is...
Thanks
Jack

Code:

class CPF_Thread
{
public:
  unsigned int threadID;
  Coordinater coordinater;

  virtual UINT proc()
  {
          coordinater.iterate();
          return 0;
  }

 
  static unsigned __stdcall CPF( void* pParam )
  {
    CPF_Thread *pThread = (CPF_Thread*)pParam;
    return pThread->proc();
  }
 
  void run() { _beginthreadex( NULL, 0, &CPF_Thread::CPF, NULL, 0, &threadID ); }
};

Weird "bug" with CStatic controls

$
0
0
OK I just discovered something weird. If you set the "notify" property of a static control to true then any time you double click on that control it copies the text of the control to the clipboard. I've traced this down to something inside MFC because I can create a very simple dialog based app, with all the defaults, set the static control in the middle with "TODO: Place dialog controls here." to notify and if I run it and double click the static that text is copied to the clipboard every time.

This is using VS2010

Does anyone know of anyway to turn that off? We have a static control in our app that when double click launches a dialog that allows you to change a value. By copying the value of the static it overwrites whatever the user already has on their clipboard, which is usually what they intend to paste into the dialog. So it's very annoying. Plus I was always told it's bad practice to overwrite the clipboard without the user specifically requesting it.

Dan

Converting time into slandered and military in c++

$
0
0
Hi, this program is suppose to store input from a user (example 14 15 27) and output it three times. Once to confirm the input using the get function to recall the data, once to look like military time (14:15:27), and once to look like slandered time (2:15:27 p.m.).

The program runs, but this is what I'm getting:
Name:  Untitled.jpg
Views: 175
Size:  16.7 KB
I'm thinking its because I'm using the same integers to store two sets of data. I tried to create different integers for every set of data it didn't seem to fix the problem. The fact that the program is running makes trying to figure out where the problem quite confusing to say the least.

This is my code I would really appreciate if someone could point out the problem.

Code:

#include <iostream>

using namespace std;

class time
{
        private:
                int hr, min, sec;
        public:
                time();
                ~time();
                void SetTime(int hour, int minute, int second);
                int GetHour();
                int GetMinutes();
                int GetSeconds();
                void PrintUniv();
                void PrintStd();
};
int main()
{
        time wakeup, naptime;
        int hr, min, sec;

                cout << "enter wake up time in military format with space in between the numbers: " << endl;
                cin >> hr >> min>> sec;

                wakeup.SetTime(hr, min, sec);

                cout << "\nyou entered " << wakeup.GetHour() << " " << wakeup.GetMinutes() << " " << wakeup.GetSeconds();
                cout << "\nThe standard time is ";
       
                wakeup.PrintStd();
           
                cout << "\nThe universal time is ";
           
                wakeup.PrintUniv();
                  cout << endl;


                cout << "enter nap time in military format with space in between the numbers: "<< endl;
                cin >> hr >> min>> sec;

                naptime.SetTime(hr, min, sec);

                cout << "\nyou entered " << naptime.GetHour() << " " << naptime.GetMinutes() << " " << naptime.GetSeconds();
                cout << "\nThe standard time is ";
                naptime.PrintStd();
                    cout << "\nThe universal time is ";
                    naptime.PrintUniv();
                  cout << endl;


        system ("PAUSE");
        return 0;

}

time::time()
{
        int hr = 0;
        int min = 0;
        int sec = 0;

}
time::~time()
{
       
}

void time::SetTime(int hour, int minute, int second)
{
        hour = (hr >= 0 && hr < 24) ? hr : 0;
        minute = (min >= 0 && min < 60) ? min : 0;
        second = (sec >= 0 && sec < 60) ? sec : 0;

}

int time::GetHour()
{
        return hr;
}

int time::GetMinutes()
{
        return min;
}

int time::GetSeconds()
{
        return sec;
}

void time::PrintUniv()
{
        cout <<  hr << ":"  << min << ":"  << sec;
}

void time::PrintStd()
{
        cout << ((hr == 0 || hr == 12) ? 12 : hr % 12) << ":"  << min << ":" <<  sec << (hr < 12 ? " a.m." : " p.m.");
}

P.S. this is a homework and I'm required to use these particular functions.
Attached Images
 

How to avoid memory fragments?

$
0
0
I am developing a Visual C++ application. There is an object called CMyObject, as follows:

typedef CMap<UINT, UINT, void *, void*> CMyMap;

class CMyObject
{
public:
CMyMap *m_pMyMap;
…Some other member variables…
}

Some instances of CMyObject contains a map, some not. Therefore, to save memory, I define a pointer m_pMyMap and create a new CMap object only if the instance contains a map.

When I test my app, with the increase of the CMyObject instance, the number of memory blocks allocated and deallocated is also increasing. There are a lot of fragments during this period. To prevent this, I try to override the new/delete operator for CMyObject and CMyMap. But still find many fragments. So I try to trace into the MFC source codes for CMap. I find CMap is just using an internal buffer to store the hash table(m_pHashTable), as follows:

m_pHashTable = new CAssoc* [nHashSize];

And for each hash entry, it uses:

P = (CPlex *)new BYTE[sizeof(CPlex) + nMax *cbElement];

to allocate the spaces.

I believe these two may be the reason of the memory fragments and want to eliminate them. However, is there a way to override the new/delete operator for codes such as:

new CAssoc* [nHashSize]

and

(CPlex *)new BYTE[sizeof(CPlex) + nMax *cbElement]

so that the spaces will be allocated from my own memory manager instead of from the default heap?

MFC: PostMessage and Handling it without the hassle (and a question).

$
0
0
Something interesting I came up with while working on a project.
In a particular dialog I needed a lot of different PostMessage() cases, so that would typically have meant:
adding a message ID, Doing the postmessage which involved wrapping parameters into structs, adding a handlerfunction to the .h file, adding the handler function to the .cpp, adding an entry to the messagemap.

Then it hit me.. Why not have a single generic handler, and post a lambda instead of parameters. All our dialogs are derived from our own dialog class which derives from CDialog, so adding the handler once, I could have an easy way out of simple "do the following in a posted message" things.

In CxDialog.h, in the class definition:
Code:

public:
        typedef                        std::function<void()>        PostedFunction_type;
        void                        PostedFunction(PostedFunction_type func) const;
protected:
        LRESULT                        OnPostedFunction(WPARAM wParam, LPARAM lParam);

In CxDialog.cpp (derives from CDialog)
somewhere near the top:
Code:

#define WM_POSTEDFUNCTION                (WM_USER_INTF+8)
and in the messagemap
Code:

        ON_MESSAGE(WM_POSTEDFUNCTION, OnPostedFunction)
and add
Code:

class PostedFunctionWrapper        // Helper class, since we can't directly cast std::function to wParam.
{
public:
        PostedFunctionWrapper(ClInput::PostedFunction_type func) :
                                                func(func)
                                                {
                                                }
        void call() const        {
                                                        func();
                                                }
private:
        ClInput::PostedFunction_type        func;
};

void CxDialog::PostedFunction(PostedFunction_type func) const
{
        PostMessage(WM_POSTEDFUNCTION, reinterpret_cast<WPARAM>(new PostedFunctionWrapper(func)), 0);
}

LRESULT CxDialog::OnPostedFunction(WPARAM wParam, LPARAM /*lParam*/)
{
        std::auto_ptr<PostedFunctionWrapper> pPFW (reinterpret_cast<PostedFunctionWrapper*>(wParam));
        pPFW->call();
        return 0;
}


So now in our derived dialogs, we can do something like (for example in OnInitDialog()):
Code:

PostedFunction([](){ AfxMessageBox("Hello"); });
Which will then show the hello messagebox when the dialog has been properly initialized and made visible

It works, you do need to be careful if you pass stuff by reference ofc since you can't post references to local variables (they'll be gone by the time the message is processed).
Feel free to use this in your own projects, makes life for me and others on the team a lot easier at least.



I'm not entirely happy about the need for the wrapper class though, but attempts at casting the std::function to WPARAM directly failed. Is there a way to avoid the wrapper or to make this approach "better" ?

Populate METAFILEPICT struct given a HMETAFILE. Missing something simple?

$
0
0
Pretty simple problem it seems.

Code:

                        HMETAFILE hMetaFile = GetMetaFile(myMetaFile);

                        METAFILEPICT myMetaPict;

                        // ??? What can I do to populate the METAFILEPICT struct to access variables below.

                        myMetaPict.yExt;
                        myMetaPict.xExt;

How to define a name range with Excel Automation

$
0
0
Using Excel Automation in Visual Studio 2010 C++, how do I define a name? As a user of Excel, you can enter a name that then can be used in formulas to refer to a range of cells. The range changes as the user inserts columns or rows. My program has worked with various versions of Excel dating back to the early 2000’s. I have a bunch of classes derived from COleDispatchDriver: CXLApplication, CXLRange, CXLWorkbook, CXLWorkbooks, and CXLWorksheet that have many functions, but I have no documentation (anybody have any clues on where to find documentation?). Anyone know how to define a named range using functions of these classes (probably CXLRange)?

Thanks for any help,
Gary
Viewing all 3033 articles
Browse latest View live