Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ethan

Classes

This topic is 6067 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Can somebody tell me if i must have an Console Application or can i use Win32 Application for classes?

Share this post


Link to post
Share on other sites
Advertisement
If i''m understanding your question right, any c++ application can take advantage of classes, it''s built in to the language, not the output platform.

Share this post


Link to post
Share on other sites
Well that all depends on what commands exactly you are using...some will only work in console mode, some in 16/32 bit windows mode, etc.

what are the exact commands you are using?

Share this post


Link to post
Share on other sites
quote:
Original post by Ethan
Hi,
Can somebody tell me if i must have an Console Application or can i use Win32 Application for classes?

Just checking: OOP/C++ classes have NOTHING to do with Window classes. Hope you know that.

class CMyObject // OO class in C++
{
CMyObject() : m_iData(0)
{
}
int GetData() { return m_iData; }
private:
int m_iData;
}

// using in a console app:
#include <iostream>
int main(int argc, char *argv[])
{
using namespace std;
CMyObject *pMyObj = new CMyObject();
cout << pMyObj->GetData() << endl;
return 0;
}


Window class:

#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPCTSTR lpCmdLine, int nCmdShow)
{
// declare and define window class:
WNDCLASSEX wc;
wc.cbClsSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = szClassName;
wc.lpszMenuName = NULL;

// register window class with Windows:
if(!RegisterClassEx(&wc))
return -1;

// go on to create window, display etc here
...
return 0;
}

As you can see, object-oriented classes have nothing to do with window classes. Window classes can only be used in full-fledged Win32 Applications (entry point WinMain).

[EDIT]: damn tags!



I wanna work for Microsoft!

Edited by - Oluseyi on November 7, 2001 12:53:13 PM

Share this post


Link to post
Share on other sites
quote:
Original post by Oluseyi
Window classes can only be used in full-fledged Win32 Applications (entry point WinMain).


No. Any Win32 application (whether windowed or console) can use window-classes and open windows etc. (and a windowed Win32 application can open a console-window if necessary).

Share this post


Link to post
Share on other sites
quote:
Original post by Dactylos
No. Any Win32 application (whether windowed or console) can use window-classes and open windows etc. (and a windowed Win32 application can open a console-window if necessary).

I took a wild shot with that one. I''ve written "windowed" Win32 applications with consoles, so I should have guessed the inverse would be possible. However, how do you obtain the HINSTANCE of the application (to supply to the window class)?



I wanna work for Microsoft!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
GetModuleHandle(NULL) will get your HINSTANCE.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Oluseyi
[quote]Original post by Ethan
Hi,
Can somebody tell me if i must have an Console Application or can i use Win32 Application for classes?

Just checking: OOP/C++ classes have NOTHING to do with Window classes. Hope you know that.

class CMyObject // OO class in C++
{
CMyObject() : m_iData(0)
{
}
int GetData() { return m_iData; }
private:
int m_iData;
}




Just a minor point, you''ve missed a semi-colon at the end of your class...

class CMyObject
{
...
}; // semi-colon is vital

I would also recommend the following while we''re on the topic...

int GetData() const { return m_iData; }

Since you''re not modifying any of the members of the class, the function is logically const.

HTH,

Stuart.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!