Code Review?

Hello, I'm pretty new to OOP. I created my first Windows Console Application today and I was wondering if you guys could tell me any big mistakes that I may have made. Also any recommendations on better ways of doing things.

Do I have the right idea of how to use a class?

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include "captureScreen.h"
#include <string>

int main() {

	captureScreen myObj;
	std::cout << myObj.saveLocal() << std::endl;

	std::cout << myObj.saveTmp() << std::endl;


	return 0;
}


captureSreen.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#pragma once
#include <iostream>


class captureScreen
{
private:
	void takeNow(std::string fname);
public:
	captureScreen();
	std::string saveLocal();
	std::string saveTmp();
	~captureScreen();
};


captureSreen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "captureScreen.h"
#include <iostream>
#include <Windows.h>
#include <atlimage.h>


using namespace std;

captureScreen::captureScreen()
{
}

void captureScreen::takeNow(string fname) {
	int screenW, screenH;
	//GetScreenSize
	screenW = GetSystemMetrics(SM_CXVIRTUALSCREEN);
	screenH = GetSystemMetrics(SM_CYVIRTUALSCREEN);

	HDC myScreen = GetDC(NULL);
	HDC mySrnMemory = CreateCompatibleDC(myScreen);
	HBITMAP hBitmap = CreateCompatibleBitmap(myScreen, screenW, screenH);
	HGDIOBJ cobj = SelectObject(mySrnMemory, hBitmap);
	BitBlt(mySrnMemory, 0, 0, screenW, screenH, myScreen, 0, 0, SRCCOPY);

	CImage screenimg;
	screenimg.Attach(hBitmap);
	screenimg.Save(CA2W(fname.c_str()));
}


std::string captureScreen::saveLocal(){
	std::string fname = "myscreen.png";
	takeNow(fname);
	return fname;
}


std::string captureScreen::saveTmp(){
	string fname = "";
	FILE *sysPipe = _popen("echo %temp%", "rt");
	char cli[128];
	while (fgets(cli, sizeof(cli), sysPipe)){
		fname += cli;
	}
	//Remove lastchar (newline)
	fname.erase(fname.end() - 1);
	fname += "\\myScreen1000.png";
	takeNow(fname);
	return fname;
}


captureScreen::~captureScreen()
{
}
From a quick overview I would say the code looks ok, however it doesn't compile on my VS2013 Community. I got the followinf error:
line 27: error C2664: 'HRESULT ATL::CImage::Save(LPCTSTR,const GUID &) throw() const' : cannot convert argument 1 from 'ATL::CA2WEX<128>' to 'LPCTSTR'
Thanks for the reply.
Thats interesting. I wrote this on 2013 Pro (Trial) as 2013 Express didn't have the atlimage libraries. After reading your post I downloaded 2013 CE and to my surprise it has the atlimage library and everything else I needed.

Thanks you saved me a few hundred dollars! :-)

Anyways, I was able to compile it just find. Not sure whats happening.

I was going to upload the source but there isn't a way to do that on here. That I can find anyway.

You're likely using a different setting for Unicode than Thomas1965. It looks like you have it enabled and he does not.

The "W" in ATL::CA2WEX is for "wide"
@cire,

you are absolutely right. With Unicode settings it works.

Thanks you saved me a few hundred dollars! :-)

You are welcome. This CE is like the Pro version - just with some restrictions in terms of license.
Topic archived. No new replies allowed.