How to change the background of the child window from an MDI Visual C++ 2008 application - visual-c++

I have an MDI Visual C++ 2008 application based on MFC. I am trying to find a way to use an image as background for the child window (child frame). I have been looking on various sites but I can't seem to find a solution. Does anyone know how to implement this?

It is always the same way when you want to change the background of a window.
Handle the WM_ERASEBKGND (OnEraseBkGnd). Draw the bitmap on the given DC and return TRUE
Either use StretchBlt or use it as a brush.
BOOL CMyClientWnd::OnEraseBkgnd(CDC* pDC)
{
CBrush* pbrushOld = pDC->SelectObject(&m_brush);
CRect rect;
pDC->GetClipBox(&rect);
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
pDC->SelectObject(pbrushOld);
return TRUE;
}

Related

How to start building a GUI toolkit for wayland

I want to create a GUI toolkit for my desktop environment (because neither gtk nor qt don't fit to my needs) but I don't know how to start. I don't want a cross-platform or display-server independent library, theming options, configurable icons etc. just a few basic widgets for making wayland clients. (widgets like button, entry, label, window and images... and I want to use CSD if it's important)
My problem is that I can't understand how graphics work in wayland (in X you only need to create a window and use XDrawLine etc. right?) also I don't know how to write a graphical toolkit. Can you give me some articles or recommendations on how can I do this?
The easiest way to create a wayland client is to use the wayland-client library. Basically, it abstracts the wire format.
example:
#include <stdio.h>
#include <wayland-client.h>
int main(void)
{
struct wl_display *display = wl_display_connect(NULL);
if (display) {
printf("Connected!\n");
} else {
printf("Error connecting ;(\n");
return 1;
}
wl_display_disconnect(display);
return 0;
}

Multiple Views for a Document in MDI Application MFC

I have a MDI application in which there are some reports and the Reports are printed and print preview in way that the was given by the MFC Printing Architecture.
But now the scenario changed and the Reports need to be formatted as a HTML File and need to be shown in the different perspective, based on a preference. I have choose a solution based on the Application architecture as there are many Document/View in my CWinApp. Created all Doc/view Templates there and the new Doc/View will be created based on the setting, once the application starts.
class CMyWinApp: public CWinApp
{
public:
virtual BOOL InitInstance();
protected:
}
BOOL CMyWinApp::InitInstance()
{
// Lot of Code Here
CreateDocumentTemplates();
}
void CMyWinApp::CreateDocumentTemplates()
{
// Some Other Doc/Templates are here
if(m_bNewView) // Based on the Setting I am creating the new View and Old Doc
{
pDocTemplate = new CMultiDocTemplate(
IDR_REPORTS,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CMyFrame), // custom MDI child frame
RUNTIME_CLASS(CMyNewView));
pDocTemplate->SetContainerInfo(IDR_TYPE_CNTR_IP);
AddDocTemplate(pDocTemplate);
}
else // This is a Old View and Doc
{
pDocTemplate = new CMultiDocTemplate(
IDR_REPORTS,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CMyFrame), // custom MDI child frame
RUNTIME_CLASS(CMyView));
pDocTemplate->SetContainerInfo(IDR_TYPE_CNTR_IP);
AddDocTemplate(pDocTemplate);
}
}
Now the scenario is, this preference can be set anytime and the further Reports need to be shown in a appropriate context.
How this can be achieved on the run time? Please help me :(
In your app class, create and save both CMultiDocTemplate pointers from your CreateDocumentTemplates function and use these to create your documents on demand(e.g override ID_FILE_NEW/ID_FILE_OPEN or similar). Look at OpenDocumentFile of CDocTemplate.
Then in your OnFileNew function or similar you can use something like this:
if(m_bNewView) {
m_pNewDocTemplate->OpenDocumentFile(...);
}
else {
m_pOldDocTemplate->OpenDocumentFile(...);
}
I would integrate CMyNewView in CMyView, if you need to switch the view dynamically. If you work with at least Visuals Studio 2008 (incl. feature pack), I recommend deriving your view class from CTabView to switch the view of the document using a handy tab next to the horizontal scrollbar of the child window.

Render bitmap to SpriteBatch in DirectXTK

I need to port some C++ application to Windows Phone 8 (it is already on Android, iOS, WinCE and Win32). Currently I need to solving how to display graphic. I can get rendered bitmap from core application and I after succesfully initialize DirectXTK I'm able to render some DDS texture (DirectXTK::SpriteBatch). Now I need to transform my bitmap to texture and then render it. Can you help me with this out? Or is there some way to put bitmap directly to backbuffer and show it on display without SpriteBatch?
Thank you very much
Tomas
DirectX toolkit has WICTextureLoader. You can use it instead of DDSTextureLoader for loading .bmp(bitmap) file. Hope this help!
http://directxtk.codeplex.com/wikipage?title=WICTextureLoader&referringTitle=DirectXTK
Since WICTextureLoader is not supported on Windows Phone 8 the only way to render a bitmap to a texture is by mapping the texture to the CPU and copy your bitmap resource onto the mapped texture's resource.
ID3D11DeviceContext::Map()
http://msdn.microsoft.com/en-us/library/windows/desktop/ff476457(v=vs.85).aspx
D3D11_MAPPED_SUBRESOURCE mappedBuffer;
HRESULT hr = pContext->Map(pTexture, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedBuffer);
if(hr == S_OK)
{
// copy your bitmap onto mappedBuffer.pData
...
pContext->Unmap(pTex, 0);
}

Is there a Direct 3D equivalent of glxinfo?

I need to make sure my machine can create a D3D window before even trying to open it. How can I do so?
I've found the equivalent of glxinfo for directX -- it's called dxdiag and is provided by Microsoft. This lets you output an xml file with a D3dStatus field (which says "not available" in my case).
You probably want to take a look at DeviceCaps. It should be able to tell you the capabilities of the device so that you don't try to create a window that it doesn't support.
Actually glxinfo does create a OpenGL window and creates a OpenGL context, but never maps it to the screen. One must create a OpenGL context to get all the information, like glxinfo does.
If you use Direct3D11 you can use this code
// Determines feature level without creating a device.
D3D_FEATURE_LEVEL determineHighestSupportedFeatureLevel()
{
HRESULT hr = E_FAIL;
D3D_FEATURE_LEVEL FeatureLevel;
hr = D3D11CreateDevice(
nullptr,
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
0,
nullptr,
0,
D3D11_SDK_VERSION,
nullptr,
&FeatureLevel,
nullptr );
if(FAILED(hr))
{
throw std::runtime_exception("Determine the highest supported Direct3D11 feature level failed.");
}
return FeatureLevel;
}

How to change the border style of applications main window in visual c++ win32 API

I have an application in Visual c++ (Win32 API). In my application the main window boarder is displayed in old windows styled. I have tried changing the wndWc.style values to WS_OVERLAPPED,WS_POPUP and other which are given in WinUser.h but there is no change in the appearance of the main window were as all my pop-up window are displayed in windows 7 style how this can be rectified. Any help in this regards will be highly appreciated. I have attached both the images the main window and the pop up window.
Code :
// our window class
WNDCLASS wndWc;
// ---------------------------------------------------------
// fill window class members
// ---------------------------------------------------------
wndWc.style = CS_GLOBALCLASS;
wndWc.lpfnWndProc = (WNDPROC) WndProc;
wndWc.cbClsExtra = 0;
wndWc.cbWndExtra = 0;
wndWc.hInstance = GetModuleHandle(NULL);
wndWc.hIcon = NULL;
wndWc.hCursor = LoadCursor(0, IDC_ARROW);
wndWc.hbrBackground = (HBRUSH)GetStockObject(0);
wndWc.lpszMenuName = NULL;
wndWc.lpszClassName = "XYZ";
// register class
if (!RegisterClass(&wndWc)) return false;
// ---------------------------------------------------------
// get actual screen resolution
int iSw = (WORD)GetSystemMetrics(SM_CXSCREEN); // height
int iSh = (WORD)GetSystemMetrics(SM_CYSCREEN); // height
// make a rectangle on the center of the screen
RECT rc = {(iSw - iWidth)/2, (iSh - iHeight)/2, width, height};
// create the window. the spaces on the window title
// are just to make sure this will be visible when the region
// is active. just run the app and you'll understand. =)
hWnd = CreateWindow("XYZ", "XYZ",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT, width,height,
NULL, NULL, GetModuleHandle(NULL), NULL);
It could be that your EXE has been flagged to run in compatibility mode for a previous OS version. Right-click the EXE, choose Properties, then ensure everything is switched off on the Compatibility tab. (Especially "Disable visual themes" and "run this program in compatibility mode for...")
Failing that...
It's unusual to need to do anything at all, but try this at the start of the app:
SetThemeAppProperties(STAP_ALLOW_NONCLIENT|STAP_ALLOW_CONTROLS)
If that doesn't work, try explicitly setting the theme for your window:
SetWindowTheme(hWnd, "WINDOW", NULL);
FWIW, I pasted your code in to a new Visual Studio 2008 project created using the "Win32 project" wizard, and it came out with a Windows 7 border. You usually have to go out of your way not to get the border, in fact.
There could be something unusual about the EXE you are building, like a flag in the EXE's header being set incorrectly. e.g. If it isn't specifying that it is a Windows GUI app, or maybe there are some version fields...
The EXE's manifest may also play a part, but I just tried deleting the manifest completely and my program still got a themed window, so it's probably not that.
If you look closely, you'll see that it's not just the border. The close button also uses the old visual style. Therefore, it's not sufficient that you change the window style. You must indicate that your app is Vista- and Aero-aware

Resources