How to perform Zooming with CHtmlEditCtrl in MFC - mfc

Can anyone help me to perform zooming on CHtmlEditCtrl ?
I displayed my html document on CHtmlEditCtrl.
Now I want my edit control to display same html document with different zooming level.
I saw this feature in InternetExplorer8.
Now I need to add this zooming feature to my MFC application.

ExecWB(OLECMDID_ZOOM, 0, &vFontSize, NULL)

Use OPTICAL_ZOOM as so;
VARIANT vaZoomFactor;
VariantInit (&vaZoomFactor);
V_VT(&vaZoomFactor) = VT_I4;
V_I4(&vaZoomFactor) = 50; //-- in this case, 50%
browserCtrl.ExecWB (OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, &vaZoomFactor, NULL);

Related

UXTheme: Draw Combobox Chevron Without Border

I'm trying to draw a custom control that should use the "combobox" theme class.
Using
m_hTheme = OpenThemeData(m_hWnd, _T("COMBOBOX"));
auto stateBG = ...; // depends on window state
DrawThemeBackground(m_hTheme, ps.hdc, CP_READONLY, stateBG, &clientRect, nullptr);
gives the correct background (read-only-look) without the chevron. But how do I add the chevron?
auto stateCV = ...; // depends on window state
DrawThemeBackground(m_hTheme, ps.hdc, CP_DROPDOWNBUTTON, stateCV, &rect, nullptr);
draws the chevron correctly, but with its own border and the chevron centered within the rect. So if I use the full client rect, I get this:
If I use a smaller rect so that the chevron is positioned correctly, I get a separated dropdown:
How do I get the "normal" look? - i.e like this:
Bonus Questions:
Is there any documentation that does a better job than MSDN? It's as sparse as most newer documentation, e.g. just listing "Parts and States", without describing their purpose (which is not always obvious), and whether it's DrawThemeBackground or ~Edgefor a particular item.
Do I still use the good old DrawFocusRectfor the focus rect?
GetThemeBackgroundContentRect calculates the expected rectable for iPartId=CP_READONLY, but for iPartId=CP_CUEBANNER, it returns the full client rectangle, so the cue text is badly aligned. Is this... normal?
Have you tried replacing CP_DROPDOWNBUTTON by CP_DROPDOWNBUTTONRIGHT ?
As a workaround you could use the ClipRect of DrawThemeBackground to cut off the left edge of the drop down button.
CRect clip_rect = rect;
clip_rect.DeflateRect(1, 0, 0, 0);
auto stateCV = ...; // depends on window state
DrawThemeBackground(m_hTheme, ps.hdc, CP_DROPDOWNBUTTON, stateCV, &rect, &clip_rect);

Drawing to the desktop via injection

I'd like to draw to the desktop wallpaper area with directX 9 in particular. Under the icons and text above the wallpaper.
Similar to Okozo or one of VLC's modes, or Dreamscene.
So there's a lot of similar questions to this but no working examples or tutorials.This A simmilar question but different approach seems pretty useful. A few years ago I was searching and found this site and code.
It's perfect aside from one big issue the icon text gets blocky even with alpha blending. I tried a few fixes but I wasn't able to find any helpful documentation maybe I just wasn't using the right words for searching, maybe it's proprietary. I think I fixed that with a call to invalidate the desktop area but I can't really tell as in the process I messed up the alpha values for the text so it doesn't properly draw the font color. So how do I alter the text for proper alpha blending?
Pouet's links are all dead
I know I should post a snippet but I can't pin down where the problem is as it's more an unexpected feature.
I've been searching for this code for too long.
I'd like to write a Dreamscene like app witch can render dynamic contents other than just video files, and this one may be the most hopful solution.
I compiled your code in VS2010 Win7x64 and found:
Desktop icon text become transparent just like Dreamscene do when the window is like:
0x00150138 "Program Manager" Progman
0x000605D6 "" SHELLDLL_DefView
0x000C05BA "FolderView" SysListView32
Desktop icon text become normal but not clear enough when the window is like:
0x000B007C "" WorkerW
0x000605D6 "" SHELLDLL_DefView
0x000C05BA "FolderView" SysListView32
0x000C05BA "FolderView" SysListView32
0x000511E2 "" WorkerW
0x00150138 "Program Manager" Progman
I tried this method Draw Behind Desktop Icons in Windows 8 to make the window status always be like the second condition; and tried to draw on WorkerW window above Progman window with D3D, but got nothing rendered out.
So far there's nothing helpful, dumping the bitmap used by memoryDC may help, which I'll try latter.
If you got any further approach, please let me know.
It has been long time since I last use English, Sorry for my mistake if any.
Update:Clear Icon Text got!
add this under d3ddev->BeginScene();
d3ddev->SetSamplerState(0,D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
d3ddev->SetSamplerState(0,D3DSAMP_MAGFILTER, D3DTEXF_GAUSSIANQUAD);
and this:
HWND desktop = GetDesktopWindow();
HWND explorer = FindWindowEx(desktop, 0, _T("Progman"), _T("Program Manager"));
SendMessageTimeout(explorer, 0x052C, 0, 0, SMTO_NORMAL, 3000, NULL);
HWND defView = 0;
HWND worker = 0;
while(!defView) {
worker = FindWindowEx(desktop, worker, _T("WorkerW"), 0);
if(worker) {
defView = FindWindowEx(worker, 0, _T("SHELLDLL_DefView"), 0);
}
else break;
}
if (!worker){ /*DBG("First WorkerW failed");*/ return 0;}
worker = FindWindowEx(desktop, (HWND)worker, _T("WorkerW"), 0); //find the next WorkerW
if (!worker){ /*DBG("Created WorkerW not found");*/ return 0;}
Still drawing on the listView, but worker window must exist. This code runs with Aero Theme enabled only.

Zoom the picture within the picturebox of Visual Studio C++

I have a problem about zooming into the picture displayed in a picturebox Picture Control. The expected result is similar to the following link: A scrollable, zoomable, and scalable picture box. The picture is zoomed in within the picturebox. Note the picturebox is zoomed in.
However, this can be implemented in .NET Framework 2.0. I have searched some information on the Internet, but none used C/C++ Windows API of Visual Studio. How can I zoom a picture within a the picturebox Picture Control when I work on Windows Forms of Visual Studio C++ 2010. Thank you for anyone's reply.
I have faced the same issue and I searched a lot but didn't get the solution in cpp(freely available in c# and VB).
So finally i decided to implement it by my own. If your Image size is bigger than the picture box then only 1 level of zoom(original size of image) you can do with my implementation.
I will help you with the implementation. In current implementation
if you do left click of mouse it will ZoomIn and
if you do right click of mouse it will ZoomOut.
Assuming you have read the image file(.png, .jpg, .bmp, ...) in bmpPicture.
Bitmap ^bmpPicture = gcnew Bitmap(strFilename);// if not it can help
private: System::Void pictureBox1_Click(System::Object^ sender, System::EventArgs^ e) {
MouseEventArgs ^ms = (MouseEventArgs^)e;
if (ms->Button == System::Windows::Forms::MouseButtons::Left)
{
int pbx = ms->X;
int pby = ms->Y;
int img_x = (pbx * mwidth / pbwidth * 1.0f);
int img_y = (pby * mheight / pbheight * 1.0f);
pictureBox1->Location = System::Drawing::Point(pbx - img_x, pby - img_y);
pictureBox1->SizeMode = PictureBoxSizeMode::AutoSize;
pictureBox1->Image = bmpPicture;
}
else if(ms->Button == System::Windows::Forms::MouseButtons::Right)
{
int pbx = ms->X;
int pby = ms->Y;
pictureBox1->Location = System::Drawing::Point(0, 0);
pictureBox1->SizeMode = PictureBoxSizeMode::StretchImage;
pictureBox1->Image = bmpPicture;
}
}
Hope this will help you...
Without any source code, it is difficult to comment.
StackOverflow is for problem solving; we can troubleshoot your starting code and get it working and during the course of which we can also fine tune design.
Anyway, I would like to give some pointers:
One or two picture boxes: entirely depends on your UI requirement.
Showing full or partial region of an image: StretchBlt is a powerful
API that can be used to achieve. See MSDN documentation for details.
Which class to use for picture box: if MFC is being used, then
derive a class from CStatic, overload the OnPaint() and use
StretchBlt to paint the image.
Classes to use for image: CBitmap, CImage, Gdiplus::Image.
Each have their own pros and cons.
If transparent images/PNGs are to be suported, better go for CImage or Gdiplus::Image.
You can get enough info here: CBitmap CImage Gdiplus::Image
Hope this would give you some starter.

Why are not all texts of my MFC applicatiopn displayed using ClearType?

I've got an MFC application that is built with VC6. When ClearType is enabled (Windows XP) some texts are rendered smoothly, i.e. with ClearType, and others are not.
Dialog texts don't seem to ever get rendered with ClearType. Some list controls, however, have it enabled completely, others only in their headers.
What could be the reason for this? Where should I look to find out why it works only in some places and doesn't in others?
Update
As requested, here is an enlarged screenshot. Obfuscated but the important parts should be visible.
In List 1 only the heading is smooth, the content is not.
In List 2 both, heading and list items are smooth.
The Dialog at the bottom is not using ClearType either.
Bitmap fonts will never use ClearType. Usually you won't use a bitmap font, but I believe the default selected into a DC is the System font, which is bitmap.
ClearType is a quality property for fonts. You should get the LOGFONT for your CFont and set the lfQuality property. Here's an example.
CFont *pFont = CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT));
LOGFONT logFont;
pFont->GetLogFont(&logFont);
logFont.lfQuality = CLEARTYPE_NATURAL_QUALITY;
CFont font2;
font2.CreateFontIndirect(&logFont);
Note: you can use either CLEARTYPE_QUALITY or CLEARTYPE_NATURAL_QUALITY, test both to see which looks best.

Drawing icons instead of bitmaps in a MFC CMenu?

I can use an bitmap in a menu
CMenu men;
CBitmap b;
b.LoadBitmap(IDB_0);
men.AppendMenu( MF_ENABLED,1,&b);
I can draw an icon into a DC
CImageList IL;
IL.Create(70, 14, ILC_COLOR16 | ILC_MASK, 1, 0);
IL.Add(AfxGetApp()->LoadIcon(IDI_0));
IL.Draw ( pDC, 0, rcIcon.TopLeft(), ILD_BLEND50 );
But I cannot find a simple way to show an icon in a menu. I would like to do this
CMenu men;
CBitmap b;
// here the miracle happens, load the icon into the bitmap
men.AppendMenu( MF_ENABLED,1,&b);
Seems like this should be possible.
This is the same question as this. However that question referred to the MFC feature pack, did not get answered, and has shown no activity for a month, so I thought it would be worthwhile to ask it again in reference to basic MFC.
I asked the question you reference.
The way to add (normal, 16-bit color) icons to menus is to make a toolbar with the same resource id as the menu you want to have icons in. You then assign id's to each of the toolbar buttons, the same id's as the menu entries. Make a wizard-generated new MFC application and you'll see how it works there.
The answers to the question I posted suggested that it should work the same for 32-bit images with transparency for the Feature Pack toolbars; I haven't gotten around to test it out though.
If your specific problem is how to make dynamically-generated menus, I think you should pass the id of an existing entry in a toolbar and then that image will be used.
Not a real answer to your question but maybe it'll point you in the right direction.
Good code. Please note that this shows the bitmap image but it is always good to remove the blank space left to the string (used for check/unchek) if you are showing the image.
I did like this.
MENUINFO mi;
mi.cbSize = sizeof(mi);
mi.fMask = MIM_STYLE;
mi.dwStyle = MNS_NOCHECK;
pcSubMenu->SetMenuInfo(&mi);
MENUITEMINFO mii;
mii.cbSize = sizeof mii;
mii.fMask = MIIM_BITMAP;
mii.hbmpItem = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_16_HELP),IMAGE_BITMAP,0,0,LR_SHARED |LR_VGACOLOR |LR_LOADTRANSPARENT);
pcSubMenu->SetMenuItemInfo(ID_CONTENTS,&mii,FALSE);
I think what you are looking for is very similar to what's described here...
www.codeguru.com/cpp/controls/menu/bitmappedmenus/article.php/c165/
mixed with what's described in www.codeproject.com/KB/shell/DynIcon.aspx
Still have to see if it will work.
Tamer
On Windows Vista/Windows7 you can not do that, it's either a 32 BGRA image or the menu is not drawn in the new UI style. There is no workaround, maybe ownerdrawing but i read the style API is not working correctly with menus, so i never tried to get deeper in it.
You should use 32bit BGRA Icons anyway.
In order to set up a bitmap for a menu, you need to call CMenu::SetMenuItemInfo() for each item with something like this:
MENUITEMINFO mii;
mii.cbSize = sizeof mii;
mii.fMask = MIIM_BITMAP;
mii.hbmpItem = bitmapHandle;
menu.SetMenuItemInfo(menuItem,&mii,TRUE);
A further complication with doing this is that this is okay for 256 colour bitmaps, but not full colour 32bit RGBA bitmaps - these will work, but only on Vista, and then only if you present the bitmap as pre-computed RGBA.
In practice, in my code I get round this by using another feature of menu icons, which is to set the hbmpItem to HBMMENU_CALLBACK, which allows a callback to draw the bitmap: I do that for Windows XP and before. The code gets a bit too complicated to post here. As an example, you could have a look at my code at
http://www.ifarchive.org/if-archive/infocom/interpreters/frotz/WindowsFrotzSrc.zip
Look in "MenuBar.h" and "MenuBar.cpp", particularly the code around MenuBar::SetBitmaps().