I am trying to extract the icon from an executable which is associated with html files. On my system, html files are associated with Chrome.
My code is:
std::unique_ptr<wxFileType> c_type(wxTheMimeTypesManager->GetFileTypeFromExtension("html"));
if (c_type)
{
wxIconLocation location;
c_type->GetIcon(&location);
WORD index = 0;
HICON hicon = ExtractAssociatedIcon(wxGetInstance(), (LPWSTR)location.GetFileName().ToStdString().c_str(), &index);
wxIcon icon;
bool res=icon.CreateFromHICON(WXHICON (hicon));
wxBitmap bmp;
bmp.CopyFromIcon(icon);
if(bmp.IsOk())
MenuItem->SetBitmap(bmp);
}
The icon will be associated with a menu item and when the menu pops up:
It is seen that rather than the Chrome icon, I am seeing a different one. I tried it with different file extensions (xlsx, docx, rtf...) and every time I am getting the same icon.
What am I missing?
Thanks in advance.
By the way, I am using wxWidgets 3.1.3 on Windows 10.
Related
In the visual studio dialog editor i can add a MFC Property Grid control to the dailog. How can i customize its content, and set options like allowing the user to edit the contents of it when the program using it is running, or how i can change the contents of it using c++?
When i add something like a button or and edit control it displays on the dailog box when the program is running, while when i add a MFC Property Grid the dailog isnt even being displayed.
Here is a picture of the visual studio dialog editor and a MFC property control grid in the middle of the dailog with contents i dont know how to change.
Simple tutorial of CMFCPropertyGridCtrl:
1.Create a dialog-based MFC project, drag a CMFCPropertyGridCtrl into it, and adjust the size. Then change the ID for the control to IDC_MFCPROPERTYGRID_TEST, and use Add Varible to add a variable m_propertyGrid to the control. Change the setting of Notify to True.
Description Rows Count refers to the number of rows in the description section below.
Enable Description Area indicates whether to enable the following description function.
Enable Header indicates whether to start the header.
Mark Modified Properties indicates whether to highlight the changes.
2.Set interface
Add the following code in OnInitDialog()
HDITEM item;
item.cxy=120;
item.mask=HDI_WIDTH;
m_propertyGrid.GetHeaderCtrl().SetItem(0, new HDITEM(item));
Add content
Add the following code in OnInitDialog()
CMFCPropertyGridProperty* pProp2 = new CMFCPropertyGridProperty(
_T("choose"),
_T("select"),
_T(""));
pProp2->AddOption(_T("1"));
pProp2->AddOption(_T("2"));
pProp2->AddOption(_T("3"));
pProp2->AllowEdit(FALSE); //Editing of options is not allowed
m_propertyGrid.AddProperty(pProp2);
The three parameters passed in when calling the constructor are item name, default options and description text.
Also, you could add drop-down menu:
CMFCPropertyGridProperty* pProp2 = new CMFCPropertyGridProperty(
_T("choose"),
_T("select"),
_T(""));
pProp2->AddOption(_T("1"));
pProp2->AddOption(_T("2"));
pProp2->AddOption(_T("3"));
pProp2->AllowEdit(FALSE); //Editing of options is not allowed
m_propertyGrid.AddProperty(pProp2);
In addition, there are three similar projects:
CMFCPropertyGridColorProperty * pProp3 = new CMFCPropertyGridColorProperty(
_T("colour"), RGB(0, 111, 200));
m_propertyGrid.AddProperty(pProp3);
CMFCPropertyGridFileProperty * pProp4 = new CMFCPropertyGridFileProperty(
_T("open file"), TRUE, _T("D:\\test.txt"));
m_propertyGrid.AddProperty(pProp4);
LOGFONT font = { NULL };
CMFCPropertyGridFontProperty * pProp5 = new CMFCPropertyGridFontProperty(
_T("select font"), font);
m_propertyGrid.AddProperty(pProp5);
Finally, This is the final program running interface:
I am creating a Qt application and I have an image that I want to use for a button instead of text. Unfortunately all that shows up is an empty button.
I've tried two different methods to get it to show up with the same results for both methods.
Code for Method 1:
ui->setupUi(this);
QPixmap pix(":/svg/resources/menu.svg");
int w = ui->menuButton->width();
int h = ui->menuButton->height();
ui->menuButton->setMask(pix.scaled(w,h,Qt::KeepAspectRatio).mask());
I found the info for the second method here: Adding image to QPushButton on Qt
Code for Method 2:
ui->setupUi(this);
QIcon icon(":/svg/resources/menu.svg");
ui->menuButton->setIcon(icon);
Could someone please help me figure out why my image isn't showing up and the button is just empty?
In my project using .svg images as button icons are no problem, maybe the button size is missing, try:
ui->menuButton->setIcon(QIcon(":/svg/resources/menu.svg"));
ui->menuButton->setToolTip("optional tooltip");
ui->menuButton->setFixedSize(QSize(28,28));
Assuming you stored your icons correctly in a resource file. If not, create a new:
right click on your top project folder (in the project-tree) -> Add new.. -> choose Qt on the left an Qt Resource File on the right window -> a new Window apears.
Add Prefix -> Add Files (your icon)
You use .svg image format. Are you sure your application load image format plugin for .svg? Image plugins must be in directory "imageformats" in current directory of your application. Avaliable plugins you can find in Qt directory .../Desktop/Qt/<version>/<mingw or msvc>/plugins/imageformats
I have a code that gets the window handle that the mouse cursor is pointing at, and I am required to determine if the mouse cursor points at a window that is not a part of the task bar. My code is able to recognize if I'm pointing at the task bar, the start button and the show desktop button (on windows 7). But I am not able to recognize if I'm pointing on the thumbnails view of combined windows (see image below).
This is the code that I use to recognize the task bar:
m_hTaskBar = FindWindow("Shell_TrayWnd", "");
m_hTaskBar = GetAncestor(m_hTaskBar, GA_ROOT);
// This code is at a mouse move event:
POINT p;
GetCursorPos(&p);
HWND hWnd = GetAncestor(WindowFromPoint(p), GA_ROOT);
m_hSelectedWin = hWnd;
bool isTaskBar = m_hSelectedWin == m_hTaskBar || GetParent(m_hSelectedWin) == m_hTaskBar;
How can I check if the cursor points at the thumbnails view of combined windows? Thanks.
I have managed to find a solution:
FindWindow("TaskListThumbnailWnd", "");
I used Spy++ to find the class name of the taskbar thumbnails window.
Spy++ can be used from Visual Studio (Tools > Spy++).
You can also find it through Autohotkey Window Spy.
I'm trying to set a custom icon into my program but nothing happens.
I created an icon using this tool.
I created a resource file with contents:
MYICON1 ICON "glider.ico"
I added the resource file into my Visual Studio 2013 project and set its type to "Resource Compiler". Type "Resource" doesn't work ("invalid or corrupt file: cannot read at 0x1A")
I load the icon with the following code when creating a window:
wc.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( MYICON1 ) ); // MYICON1 is defined in Resource.h as 101.
Just to make sure that I have correctly understood your question…Everything compiles fine when you set the type of your resource file to "Resource Compiler", right? That is the correct setting, leave it there. The other stuff is for .NET applications.
So the problem is just that you aren't seeing the icon? What size icon did you create in the editor? The LoadIcon function is extremely old and can only load icons with the default size, generally 32x32. If you want to load icons with a different size, you will need to use the LoadImage function instead. Over 99% of the time, that's the function you should call to load icons. I haven't used LoadIcon in years.
HICON hIcon = static_cast<HICON>(::LoadImage(hInstance,
MAKEINTRESOURCE(MYICON1),
IMAGE_ICON,
48, 48, // or whatever size icon you want to load
LR_DEFAULTCOLOR);
Like Retired Ninja suggests in his comment, be sure to test the return values of functions when the code doesn't work as expected. For example, test whether hIcon is NULL. If so, the LoadImage function failed, and you need to figure out why. Most likely, the parameters you passed were incorrect. Either there is no resource with that ID in your application module, or there is no icon with the corresponding size in the icon file.
Another tip for debugging purposes is to use one of the built-in system icons. If you can see that icon, you know everything is working correctly, and you can start swapping things out to load your custom icon. For example:
HICON hIcon = static_cast<HICON>(::LoadImage(NULL,
MAKEINTRESOURCE(IDI_WARNING),
IMAGE_ICON,
0, 0,
LR_DEFAULTCOLOR | LR_SHARED | LR_DEFAULTSIZE));
That should show the standard warning icon, like the one you see in a message box. If that works, but loading your own icon doesn't work, the problem is very likely to be with the .ico file that you created.
You can set your icon resource like this and use Load Icon' with w c ex h Icon and w c ex h Icon Sm. It sets the project output icon and program icon at the same time.
'IDI_MAIN_ICON ICON "cellphone.ico"
'Load Icon( h Instance, MAKEINTRESOURCE(IDI_MAIN_ICON));'
I am building a textEdit application with MFC. Is there a way to create a hyperlink automatically when a user write web address? It's like when you write a web address "www.google.com" the application detects web address and create a hyperlink right away. I have searched documents that explains about this, but couldn't find it..
and i couldn't make it..
i already have made notepad but i couldn't add the function of hyperlink on the notepad.
the following sentences are functions of hyperlink.
Clicking the text needs to open a browser window to the location specified by the text.
The cursor needs to change from the standard arrow cursor to a pointing index finger when it moves over the control.
The text in the control needs to be underlined when the cursor moves over the control.
A hyperlink control needs to display text in a different color—black just won't do.
The features that I added are:
5.A hyperlink control once visited needs to change color.
6.The hyperlink control should be accessible from the keyboard.
7.It should install some kind of hooks to allow the programmer to perform some actions when the control has the focus or when the cursor is hovering over the control.
Among the functions, What I mostly want to complete is the first one.
If I click a Hyperlink text, it should be linked to a browser window on the Internet.
Please answer and help me. Thanks.
Just use a CRichEditCtrl control (remember to call AfxInitRichEdit2 in your InitInstance). Call SetAutoURLDetect. Done.
Unfortunately this is not enough to make it work. It will display text that resembles URL as blue underlined but it will not invoke the link.
This will have to be handled by additional code. This will set needed event mask:
long lMask = m_RichEditCtrl.GetEventMask();
m_RichEditCtrl.SetEventMask(lMask | ENM_LINK);
m_RichEditCtrl.SetAutoURLDetect();
Also reflected EN_LINK will has to be handled to follow the link. For example:
void CHyperLinkInEditView::OnEnLink(NMHDR *pNMHDR, LRESULT *pResult)
{
ENLINK *p_Link = reinterpret_cast<ENLINK *>(pNMHDR);
if(p_Link && p_Link->msg == WM_LBUTTONDOWN)
{
//int iRange = m_RichEditCtrl.GetTextRange(p_enLinkInfo->chrg.cpMin, p_enLinkInfo->chrg.cpMax);
m_RichEditCtrl.SetSel(p_Link->chrg);
CString szLinkString = m_RichEditCtrl.GetSelText ();
ShellExecute(m_hWnd, L"Open", szLinkString, NULL, NULL, SW_MAXIMIZE);
}
*pResult = 0;
}
All of the above will solve requirement 1, 2, 3 (partially –text is underlined always), and 4.
I do not quite understand 5, 6 and 7.
Could you elaborate?