dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

CreateButton
Goto page 1, 2  Next
 
dev.gamez.lv Forum Index -> Programmēšana
View previous topic :: View next topic  
Author Message
elvman
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 09 Apr 2003
Posts: 1278
Location: Kuldiga

PostPosted: Thu Dec 02, 2004 3:35 pm    Post subject: CreateButton

Kaads nevareetu pateikt kaa ieksh visual c++ dabuut kauko liidziigu createbutton. Es zinu ieksh comctrls.h ir funkcija CreateToolbar, bet nav kaada funkcija CreateButton vai kaukas tamliidziigs. Varbuut ar SendCommand var uztaisiit PushButton.
_________________
long time; /* know C */
Back to top
View user's profile Visit poster's website
Vecais_Dumais_Laacis
Guru
Guru


Joined: 29 Jan 2004
Posts: 800

PostPosted: Thu Dec 02, 2004 3:40 pm    Post subject:

ar CreateWindow kautkaa apmeeram taa

hButton=CreateWindow ("BUTTON", "Button", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 10, 10, 100, 40, hWnd, CHILD1, ghInstance, NULL);
ShowWindow (hButton, SW_SHOW);
_________________
...un ja bites buutu laachi...
Back to top
View user's profile
gazz



Joined: 03 Jan 2004
Posts: 355
Location: Teika

PostPosted: Thu Dec 02, 2004 4:47 pm    Post subject:

aha - wisas kontroles win32 api ir wienkaarshi logi kam WNDPROC ir jau defaultaa defineeta. Uzmeklee MSDN/PlatformSDK ko tik weel tur newar sabuuweet!
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Thu Dec 02, 2004 7:13 pm    Post subject:

Ja grib programmēt C++ nevis C, tad iesaku palūrēt WTL: http://wtl.sourceforge.net/
http://www.codeproject.com/wtl/ (piemēri)
Back to top
View user's profile Send e-mail
gazz



Joined: 03 Jan 2004
Posts: 355
Location: Teika

PostPosted: Fri Dec 03, 2004 8:19 am    Post subject:

wtl prieksh iesaaceeja buus manshkiet biki taa kaa par sarezhgjiitu(deeelj kreisaas templeitu sintakses). IMO -Wispirms buutu labaak iemaaciitiis win32 API un tikai tad kjerties klaat WTL saprotot kaa tas wiss tur apakshaa straadaa.
Back to top
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: Fri Dec 03, 2004 11:30 am    Post subject:

Templeitiem ir kreisa sintakse? A kam tad nav kreisa sintakse?
Back to top
View user's profile Send e-mail
WhiteShadow



Joined: 23 Sep 2004
Posts: 26
Location: Valmiera

PostPosted: Tue Dec 14, 2004 10:59 am    Post subject: grr..

Nu, piemeeram, taadu imho labi zinaamu lietu kaa Smart Pointers vispaar bez templeitiem nevar uzveidot, e.g. piemeers no manas toposhaas speeles:

Code:
.
.
class sfcReferenceCounter
{
public:
    template <class T>
    static void AddReference(T *pObject)
    {
        pObject->AddReference();
    }

    template <class T>
    static void RemReference(T *pObject)
    {
        pObject->RemReference();
    }
};

template <class T>
class sfcPointer
{
public:
    sfcPointer();
    sfcPointer(T *pObject);
    ~sfcPointer();

    void operator = (T *pObject);
    const T *operator -> () const;
    T *operator -> ();
    bool operator ! () const;
    bool IsValid() const;

private:
    T *m_pObject;
};
.
.


so, par to "kreiso sintaksi" var piekrist/nepiekrist, bet tas, ka templates ir deriigs instruments daudzos gadiijumos, tas ir viennoziimiigi Exclamation
_________________
Black holes are where God divided by zero.
Back to top
View user's profile Send e-mail
gazz



Joined: 03 Jan 2004
Posts: 355
Location: Teika

PostPosted: Tue Dec 14, 2004 1:05 pm    Post subject:

Jautaajums bija - kaa c++ war uztaisiit win32 pogu. Ja ir shaads jautaajums tad pienjemu ka cilweeks ir tikai nesen saacis apguut c++ un sarezhgjiitaakas lietas jautaataajam ir sweshas. Par templeitu noderiigumu nemaz negribu apstriideet, tas ir speeeks Wink)). Lieta ir tur ka metodies iekshaa WTL iisti neizprotot templeitus un win32api, bilde buus weel tumshaaka, njemot weeraa piemeeram taadu apstaakli ka WTL naw dokumentaacijas, un piemeeram shaads kods izraisiitu diezgan lielu neizpratni
Code:
template <class T, COLORREF t_crBrushColor>
class CPaintBkgnd : public CMessageMap {
public:
    CPaintBkgnd() { m_hbrBkgnd = CreateSolidBrush(t_crBrushColor); }
    ~CPaintBkgnd() { DeleteObject ( m_hbrBkgnd ); }
 
    BEGIN_MSG_MAP(CPaintBkgnd)
        MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
    END_MSG_MAP()
 
    LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
      T* pT = static_cast<T*>(this);
      HDC dc = (HDC) wParam;
      RECT rcClient;
 
        pT->GetClientRect ( &rcClient );
        FillRect ( dc, &rcClient, m_hbrBkgnd );
        return 1;    // we painted the background
    }
protected:
    HBRUSH m_hbrBkgnd;
};

class CMyWindow : public CWindowImpl<CMyWindow, CWindow, CFrameWinTraits>,
                  public CPaintBkgnd<CMyWindow, RGB(0,0,255)>
{
    DECLARE_WND_CLASS(_T("My Window Class"));
    typedef CPaintBkgnd<CMyWindow, RGB(0,0,255)> CPaintBkgndBase;
 
    BEGIN_MSG_MAP(CMyWindow)
        MESSAGE_HANDLER(WM_CLOSE, OnClose)
        MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
        COMMAND_HANDLER(IDC_ABOUT, OnAbout)
        CHAIN_MSG_MAP(CPaintBkgndBase)
    END_MSG_MAP()
   
    LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
        DestroyWindow();
        return 0;
    }
 
    LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
        PostQuitMessage(0);
        return 0;
    }
 
    LRESULT OnAbout(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) {
        MessageBox ( _T("Sample ATL window"), _T("About MyWindow") );
        return 0;
    }
};

Tieshi WTL paraadaas shii templeitu "kreisaa sintakse". Un ja tew taa neliekas kreisa - acumirklii paskaidro ko noziimee T* pT = static_cast<T*>(this); Wink. Sho kodu panjeemu no www.codecorners.com WTL beginneru 1. tutoriaalja. Ne par welti pashaa saakumaa ir rakstiits
You need to know MFC, and know it well enough that you understand what's behind the message map macros, and can edit the code marked "DO NOT EDIT" with no problems.
You need to know Win32 API programming, and know it well. If you learned Windows programming by going straight into MFC, without learning how messages work at the API level, you are unfortunately going to have trouble in WTL. If you don't know what a message's WPARAM and LPARAM mean, you should read other articles (there are lots of them here at CodeProject) so you understand.
You need to know C++ template syntax.


Secinaajumaa simple as that - iemaacies win32api un tad shtuko par taadaam lietaam kaa WTL.
Back to top
View user's profile Send e-mail
WhiteShadow



Joined: 23 Sep 2004
Posts: 26
Location: Valmiera

PostPosted: Thu Dec 16, 2004 1:17 pm    Post subject: an answer :)

Quote:
paskaidro ko noziimee T* pT = static_cast<T*>(this);

kaapeec ne?
Code:
T *pT
- pT ir noraade (pointer) uz nezinaamu tipu T, kas specificeets augstaak ar
Code:
template <class T.. >
.

Code:
static_cast<T*>(this)
- static_cast paarveido vienu tipu par otru, savukaart es domaaju, ka tu zini, kas ir this

P.S. Zinaamu neskaidriibu var ieviest tas, kas templeita deklaraacijaa izmanto vaardu class, kaut gan tips var buut jebkursh. Shai gadiijumaa solution ir viens - template <class T> vietaa izmanto template <typename T>
_________________
Black holes are where God divided by zero.
Back to top
View user's profile Send e-mail
gazz



Joined: 03 Jan 2004
Posts: 355
Location: Teika

PostPosted: Thu Dec 16, 2004 2:07 pm    Post subject:

nu tas iisteniibaa bija retorisks jautaajums Wink
Back to top
View user's profile Send e-mail
GiGa
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 25 Sep 2003
Posts: 887

PostPosted: Thu Dec 16, 2004 7:30 pm    Post subject:

Mazliet offtopics, bet tomeer gribaas pajautaat. Es te meeginu iebraukt kaapeec tieshi un kadaas situaacijaas jaalieto tie static_cast un dynamic_cast utt, un gribu zinaat vai sheit nevar
Code:
T* pT = static_cast<T*>(this);
vietaa iztikt ar
Code:
T* pT = (T*)(this);
?
_________________
Back to top
View user's profile Send e-mail
gazz



Joined: 03 Jan 2004
Posts: 355
Location: Teika

PostPosted: Thu Dec 16, 2004 7:36 pm    Post subject:

nu shajaa gadiijumaa tas jau arii bija tas triks galwenais. 100 % paarliecinaats neesu bet shkiet ka ideja bija, lai paatrinaatu koda izpildes laiku neizmantojot virtuaalo funkciju table. Par cik kompilatoram ir zinaams T tips jau kompileeshanas laikaa, tad attieciigi var mapot funkcijas izsaukumu neizmatojot virtuaalo funkciju tabli. Un otrs punkts - laikam esot ka jau kompileeshanas laikaa var izkjert paaris bagus. Palabojiet mani ja kljuudos.
Back to top
View user's profile Send e-mail
GiGa
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 25 Sep 2003
Posts: 887

PostPosted: Thu Dec 16, 2004 7:42 pm    Post subject:

Ok, taadu specifiku es iipashi (nu labi, nemaz Smile ) nepaarzinu, bet vaitad
Code:

T* pT = (T*)(this);

gadiijumaa kompilaators arii nezinaas T tipu un nevarees veikt taadu pashu optimizaaciju? Vai arii ir kaads "apsleeptais" iemesls kaapeec vinsh to nevar 100% droshi dariit?
_________________
Back to top
View user's profile Send e-mail
chaosman



Joined: 28 Oct 2003
Posts: 64
Location: Rīga

PostPosted: Thu Dec 16, 2004 8:16 pm    Post subject:

GiGa wrote:
Mazliet offtopics, bet tomeer gribaas pajautaat. Es te meeginu iebraukt kaapeec tieshi un kadaas situaacijaas jaalieto tie static_cast un dynamic_cast utt, un gribu zinaat vai sheit nevar
Code:
T* pT = static_cast<T*>(this);
vietaa iztikt ar
Code:
T* pT = (T*)(this);
?


Taa krutaak :)

Vispaar laikam doma ir tada, ka jebkura casting operaacija ir slikta un neveelama (potenciali kljuudu izraishosha) un programmeetaaji refaktoreejot kodu veeleesies tikt no tam valjaa.
Quote:

Once you understand this and are presented with a buggy program, your first inclination may be to look for casts as culprits. But how do you locate C-style casts? They are simply type names inside of parentheses, and if you start hunting for such things you’ll discover that it’s often hard to distinguish them from the rest of your code.

Standard C++ includes an explicit cast syntax that can be used to completely replace the old C-style casts. The explicit cast syntax is such that you can easily find them, as you can see by their names:

(c) Bruce Eckel, Thinking in C++

Kaapeec konkreetaaja gadiijumaa vispaar vajadziiga tipa paarveidoshna uzreiz nevaru pateikt, bet droshi vien kautkas saistiits ar daudzkaarsho mantoshanu. Varbuut lai izsauktu pareizo GetClientRect tad ja "this" ir mantots no vairaakaam klaseem.

P.S. elvman avataara bez shaubaam izskataas kichiigi, tomeer druksku mazaaku jau nu gan vareetu.
Back to top
View user's profile
WhiteShadow



Joined: 23 Sep 2004
Posts: 26
Location: Valmiera

PostPosted: Fri Dec 17, 2004 9:53 am    Post subject: hmm

Nu, tas, ka casting operations ir kkas more "buggy" kaa jebkas cits, laikam gan nebuus taisniiba.
Bet visi shie .._cast<>() ir nepiecieshami gadiijumos, ja kompilators absoluuti nevar paarveerst vienu tipu par otru ar function-style casts, kaa arii tad, ja vajag paarveerst viena tipa pointeru par otru (tas pats T* pT = (T*)(this); )
_________________
Black holes are where God divided by zero.
Back to top
View user's profile Send e-mail
Display posts from previous:   
dev.gamez.lv Forum Index -> Programmēšana All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group