Click here to Skip to main content
15,886,810 members
Articles / Desktop Programming / Win32

Windows Development in C++, Working with Menus

Rate me:
Please Sign up or sign in to vote.
4.96/5 (60 votes)
3 Jan 2015CPOL19 min read 171.9K   4.1K   163  
Windows API, menus, C++ lambda expressions, std::enable_shared_from_this
#pragma once

#ifndef __HWINAPPLICATION_H__
#define __HWINAPPLICATION_H__

#include "hwindef.h"
#include "hwinmessage.h"
#include "hwinform.h"
#include "hwinclass.h"


namespace harlinn
{
    namespace windows
    {

        class MessageLoop : public Object
        {
        public:
            typedef Object Base;
            HWIN_EXPORT MessageLoop();
            HWIN_EXPORT virtual ~MessageLoop();

            HWIN_EXPORT virtual int Run();
        protected:
            HWIN_EXPORT virtual int GetMessage(Message& message);
            HWIN_EXPORT virtual int TranslateMessage(Message& message);
            HWIN_EXPORT virtual Message::Result DispatchMessage(const Message& message);
        };



        class Application : public Component
        {
            friend class Control;

            static Application *currentApplication;

            std::shared_ptr<WindowClasses> windowClasses;

            std::map<HWND, Control*> controls;

            HWIN_EXPORT void AddControl(HWND hWnd, Control* control);
            HWIN_EXPORT void RemoveControl(HWND hWnd);
            HWIN_EXPORT Control* GetControl(HWND hWnd);

        public:
            typedef Component Base;
            HWIN_EXPORT Application( );
            HWIN_EXPORT virtual ~Application();

            HWIN_EXPORT static std::shared_ptr<Application> Current();

            HWIN_EXPORT virtual int Run(std::shared_ptr<Form> mainform );

            HWIN_EXPORT virtual int Run(std::shared_ptr<Form> mainform, std::shared_ptr<MessageLoop> messageLoop );

            HWIN_EXPORT std::shared_ptr<const WindowClasses> GetWindowClasses() const;
            HWIN_EXPORT std::shared_ptr<WindowClasses> GetWindowClasses();
            HWIN_EXPORT static std::shared_ptr<WindowClass> GetWindowClass(const String& theClassName );
            HWIN_EXPORT static std::shared_ptr<WindowClass> GetWindowClass(const wchar_t* theClassName );
        };
    };
};




#endif //__HWINAPPLICATION_H__

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Sea Surveillance AS
Norway Norway
Chief Architect - Sea Surveillance AS.

Specializing in integrated operations and high performance computing solutions.

I’ve been fooling around with computers since the early eighties, I’ve even done work on CP/M and MP/M.

Wrote my first “real” program on a BBC micro model B based on a series in a magazine at that time. It was fun and I got hooked on this thing called programming ...

A few Highlights:

  • High performance application server development
  • Model Driven Architecture and Code generators
  • Real-Time Distributed Solutions
  • C, C++, C#, Java, TSQL, PL/SQL, Delphi, ActionScript, Perl, Rexx
  • Microsoft SQL Server, Oracle RDBMS, IBM DB2, PostGreSQL
  • AMQP, Apache qpid, RabbitMQ, Microsoft Message Queuing, IBM WebSphereMQ, Oracle TuxidoMQ
  • Oracle WebLogic, IBM WebSphere
  • Corba, COM, DCE, WCF
  • AspenTech InfoPlus.21(IP21), OsiSoft PI


More information about what I do for a living can be found at: harlinn.com or LinkedIn

You can contact me at espen@harlinn.no

Comments and Discussions