From: Giovanni Dicanio on 5 Nov 2009 17:44 "Joseph M. Newcomer" <newcomer(a)flounder.com> ha scritto nel messaggio news:g7g6f5l5sqpknm5halasilt39hfc68im4d(a)4ax.com... > I've found that multi-monitor awareness is no longer > optional. You are right. Be multi-monitor aware could complicate code, but it is a good benefit for the end user. Giovanni
From: Aegis Delacour on 6 Nov 2009 20:55 Thanks for the answers. im guessing this is what you mean... HWND hdc = CreateWindow(); HDC GetDC( HWND hdc ); but im not too sure about the parameters, could you help me fill it in plz? HWND CreateWindow( LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam );
From: Joseph M. Newcomer on 6 Nov 2009 23:05 See below... On Fri, 6 Nov 2009 17:55:42 -0800 (PST), Aegis Delacour <eloquent1(a)gmail.com> wrote: >Thanks for the answers. >im guessing this is what you mean... > >HWND hdc = CreateWindow(); **** In MFC, you would create a subclass of CWnd, e.g., class CMyFullScreen : public CWnd { }; you would do this using the "Add New Class" function in VS. Therefore, you would NOT be calling CreateWindow. Also, you would never call GetDC; that piece of code is completely irrelevant **** >HDC GetDC( HWND hdc ); **** Having created the class, you would now create a window. You need a variable which you declare in a place (such as some view class you are using, or dialog class, or something, but NOT a local variable); for example put it in your CLowerEicasDlg class CMyFullScreen screen; then in response to a button click you would do void CLowerEicasDlg::OnSomeCondition() { LPCTSTR classname = AfxRegisterWndClass(0); screen.CreateEx(0, NULL, WS_OVERLAPPED | WS_VISIBLE, x0, y0, width, height, NULL, NULL); } Note that error detection and recovery is left as an Exercise For The Reader. Also, I did not specify x0, y0 and width, height since I leave those up to you to figure out. They may be local variables you compute on the fly in OnSomeCondition method, or class variables of CLowerEicasDlg that you have computed earlier. Then to your CMyFullScreen class, you will add an OnPaint handler using the ClassWizard: void CMyFullScreen::OnPaint() { CPaintDC dc(this); ... do your drawing here } Note that you do not ever, under any circumstances, do a GetDC. In those very rare and exotic situations where you might need to draw outside the OnPaint handler, you would declare a CClientDC variable, but you do not have that situation here. **** > >but im not too sure about the parameters, could you help me fill it in >plz? > > >HWND CreateWindow( > LPCTSTR lpClassName, > LPCTSTR lpWindowName, > DWORD dwStyle, > int x, > int y, > int nWidth, > int nHeight, > HWND hWndParent, > HMENU hMenu, > HINSTANCE hInstance, > LPVOID lpParam >); **** This would be the raw API. But you are programming in MFC and this is irrelevant. Note that your calls on CreateDC are also irrelevant. If you wanted to create a memory DC to reduce flicker, you would declare CDC memDC; memDC.CreateCompatibleDC(&dc); and work with the MFC methods for doing the drawing. joe **** Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Aegis Delacour on 9 Nov 2009 06:12 wow thanks for the great replies but to be honest im a little confused, i apologize for so many 'newbie' questions cause well im pretty new to this coding. so from what i get this is what i see... CMyFullScreen screen; //This is a variable class CMyFullScreen : public CWnd { //Should anything go in here? }; void screeny() //i don't need the 'condition here as i will be using a function call to link here to display the image { LPCTSTR classname = AfxRegisterWndClass(0); screen.CreateEx(0, NULL, WS_OVERLAPPED | WS_VISIBLE, 0, 0, 1280, 768, NULL, NULL); } void CMyFullScreen::OnPaint() { CPaintDC dc(this); ... do your drawing here int dest_x, dest_y, width, height; dest_x=0; dest_y=0; width=800; height=900; FIBITMAP *fibmp_img = FreeImage_Load(FIF_JPEG, "screen1.JPG", JPEG_DEFAULT); StretchDIBits(hdcC, dest_x, dest_y, width, height, 0, 0, width, height, FreeImage_GetBits(fibmp_img), FreeImage_GetInfo (fibmp_img), DIB_RGB_COLORS, SRCCOPY); FreeImage_Unload(fibmp_img); dc.BitBlt(0, 0, bmpWidth, bmpHeight, &MemDC, 0, 0,SRCCOPY ); } CMyFullScreen::LoadFromFile(const CString & filename) //Whats this function for as i already drew the image in OnPaint dialog right? { // FreeImage class fipWinImage img; #ifdef _UNICODE img.loadU("Screeny1.jpg"); #else img.load("Screeny1.jpg"); #endif ..... // CRect with the image size CRect r(CPoint(0,0), CSize(img.getWidth(), img.getHeight())) ; // assuming MemDC is a protected CDC member variable of CMyFullScreen // also a CBitmap member ( created CreateCompatibleBitmap) is selected in // that MemDC img.draw(MemDC.GetSafeHdc(), r); .... }
From: Joseph M. Newcomer on 9 Nov 2009 09:14
See below... On Mon, 9 Nov 2009 03:12:42 -0800 (PST), Aegis Delacour <eloquent1(a)gmail.com> wrote: >wow thanks for the great replies but to be honest im a little >confused, i apologize for so many 'newbie' questions cause well im >pretty new to this coding. > >so from what i get this is what i see... > >CMyFullScreen screen; //This is a variable > >class CMyFullScreen : public CWnd { >//Should anything go in here? >}; *** Since you will derive this by using Visual Studio's "Add Class" mechanism, you will start out with a LOT of stuff there, but it doesn't matter, because it is automatically generated for you. You will also add an OnPaint handler to the class once you have created it. **** > > >void screeny() //i don't need the 'condition here as i will be using a **** Presumably this is a member function of some class. **** >function call to link here to display the image > { > LPCTSTR classname = AfxRegisterWndClass(0); > screen.CreateEx(0, > NULL, > WS_OVERLAPPED | WS_VISIBLE, > 0, 0, > 1280, 768, > NULL, > NULL); > } > >void CMyFullScreen::OnPaint() > { > CPaintDC dc(this); > ... do your drawing here > > int dest_x, dest_y, width, height; **** It is poor style to use commas in declaration lists. One variable, one line: CPoint dest; CSize size; **** > dest_x=0; > dest_y=0; > width=800; > height=900; **** dest.x = 0; dest.y = 0; size.cx = 800; size.cy = 900; Why use int when there are nicer data types for expressing these concepts? **** > > FIBITMAP *fibmp_img = FreeImage_Load(FIF_JPEG, "screen1.JPG", > JPEG_DEFAULT); > StretchDIBits(hdcC, dest_x, dest_y, width, height, 0, 0, width, > height, FreeImage_GetBits(fibmp_img), FreeImage_GetInfo >(fibmp_img), **** Where id hdcC come from? **** > DIB_RGB_COLORS, SRCCOPY); > FreeImage_Unload(fibmp_img); > > dc.BitBlt(0, 0, bmpWidth, bmpHeight, &MemDC, 0, 0,SRCCOPY ); > > } > > > > >CMyFullScreen::LoadFromFile(const CString & filename) //Whats this >function for as i already drew the image in OnPaint dialog right? **** I have no idea. The concept seems to be left over from your old code. The only thing you need is the #ifdef code. **** >{ >// FreeImage class >fipWinImage img; > >#ifdef _UNICODE >img.loadU("Screeny1.jpg"); **** This should be img.loadU(L"Screen1.jpg"); **** >#else >img.load("Screeny1.jpg"); >#endif >.... > >// CRect with the image size >CRect r(CPoint(0,0), CSize(img.getWidth(), img.getHeight())) ; > >// assuming MemDC is a protected CDC member variable of CMyFullScreen >// also a CBitmap member ( created CreateCompatibleBitmap) is selected >in >// that MemDC >img.draw(MemDC.GetSafeHdc(), r); >... > >} Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm |