|
Hi!
I need to make synchronization in my c++ function, and I don't know how to do that. Which library I can use?
( I heard about windows.h, but I don't see any methods for synchronization here... )
Thanks in advance!
Andry.
|
|
|
|
|
create a critical section object CRITCAL_SECTION cs; initialize it then call ::EnterCriticalSection(&cs) and ::LeaveCriticalSection(&cs) to surround the code you want to protect.
Push Framework - now released !
http://www.pushframework.com
|
|
|
|
|
Andry_st wrote: I need to make synchronization
Why ? is your application multithreaded ?
If no, don't bother.
If yes, have a look at mutex, semaphore, ...
read here : Thread Synchronization for Beginners[^]
Watched code never compiles.
|
|
|
|
|
Yes, it is multithreaded.
Good link, thx.
Just one question: what I must to #include to enable this code?
How I can see, this is a windows.h functions, right?
|
|
|
|
|
I've got an SDI application that displays JPG files in a list control. When one of those files is right-clicked, I am displaying the context menu that is associated with JPG files (this menu is the same one that Explorer uses). The problem is that every menu option is gray, thus TrackPopupMenu() returns 0 . Any ideas why?
I suspect some sort of handler is required and the framework is not finding one.
Thanks.
[edit]
Setting a new window procedure via SetWindowLong() and calling IContextMenu2::HandleMenuMsg() from within that seemed to do the trick.
[/edit]
- DC
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
modified on Tuesday, February 8, 2011 11:32 AM
|
|
|
|
|
DavidCrow wrote: this menu is the same one that Explorer uses
What do you mean by that ? you load the explorer menu or just make it look like the exporer menu?
I think you need to have handlers for you menu item; or you can use the option TPM_RETURNCMD to have TrackPopupMenu return the item selected item; then you will need to handle the state of the items manually.
Watched code never compiles.
|
|
|
|
|
Maximilien wrote: What do you mean by that ? you load the explorer menu or just make it look like the exporer menu?
Meaning it is one in the same. I go through all of the COM and Shell stuff to create and display the context menu, like:
LPSHELLFOLDER folderParent;
DesktopFolder->BindToObject(pidlParent, 0, IID_IShellFolder, (LPVOID *) &folderParent);
LPITEMIDLIST pidlFile;
folderParent->ParseDisplayName(AfxGetMainWnd()->GetSafeHwnd(), 0, (LPWSTR) ((LPCTSTR) strFile), &ulEaten, &pidlFile, 0);
LPCONTEXTMENU CM;
folderParent->GetUIObjectOf(AfxGetMainWnd()->GetSafeHwnd(), 1, (LPCITEMIDLIST *) &pidlFile, IID_IContextMenu, 0, (LPVOID *) &CM);
HMENU hMenu = CreatePopupMenu();
DWORD dwFlags = CMF_CANRENAME;
CM->QueryContextMenu(hMenu, 0, 1, 0x7fff, dwFlags);
int Cmd = TrackPopupMenu(...);
Maximilien wrote: ...or you can use the option TPM_RETURNCMD to have TrackPopupMenu return the item selected item...
All of the menu items are gray, so TrackPopupMenu() is only going to return 0 .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
thanks. I did not know that (getting the explorer menu).
(you could do a tip/tricks entry for that!, but for now, I'm just bookmarking it).
Max.
Watched code never compiles.
|
|
|
|
|
Maximilien wrote: (you could do a tip/tricks entry for that!, but for now, I'm just bookmarking it).
I'm actually working on an actual application that uses this stuff. Once done, I'll see if it's post-worthy.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Is there any inbuild function available to implement Incremental Search in CRicheditview?
|
|
|
|
|
According to MSDN FindText[^] can search starting from a given character position. Use the chrg and chrgText members of the FINDTEXT[^] structure to set and get the ranges, and lpstrText to set the text to search for.
Edit: this is for rich edit
|
|
|
|
|
Hello,
i use C++ with Windows Forms for development.
As you knows in form we can use many controls and i want 2 re size each control as per the system resolution. so if anybody knows then please help me.........
|
|
|
|
|
ddgalande wrote: i want 2 re size each control as per the system resolution.
I am not sure what problem you are having with this but you can get the screen resolution from the GetSystemMetrics()[^] function. How you use that information to resize your controls is up to you, but I presume you just want to apply some scaling to them.
I must get a clever new signature for 2011.
|
|
|
|
|
hi,
i did not got your answer.
My question is that suppose my screen resolution is 1024x768 and i have designed my GUI as per the current resolution.
by using following code i can get my systems current resolution
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
MessageBox::Show("Screen Resolution is : " +monitor_width +" x " + monitor_height, "Dnyan", MessageBoxButtons::OK, MessageBoxIcon::Information);
double xRatio = monitor_height / 800.00;
double yRatio = monitor_width / 600.00;
}
public: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
monitor_height=Screen::PrimaryScreen->Bounds.Height;
monitor_width=Screen::PrimaryScreen->Bounds.Width;
}
Now suppose my project is in network and one persons system resolution is 800x600 second person screen resolution is 1024x768 and others is different
in this case i want to adjust control default location as well as its size as per screen resolution
then please tel me how its possible in C++ with Windows platform (in .net IDE)
Please help me
|
|
|
|
|
You will need to adjust the size of your form, and all the controls, before you display it. I would guess that you need to find some calculation that will optimise it for different size screens. It would probably be best to design it for the lowest resolution and adjust upwards for the higher ones.
I must get a clever new signature for 2011.
|
|
|
|
|
I am sure there are some articles covering that subject here on CP. Just look in the Dialog and Windows article section.
|
|
|
|
|
Hi all,
I am using SortItems function to sort my list. I am using it this way
m_list.SortItems(2,TRUE);
In Visual studio 2008 its compiling ok but in VS-2010 its giving a error
error C2664: 'CListCtrl::SortItems' : cannot convert parameter 1 from 'int' to 'PFNLVCOMPARE'
to remove this error i write my line in this form
m_list.SortItems((PFNLVCOMPARE)2,TRUE);
the error is removed but it is not sorting the list either...
How can i make it work ?
Thanks in advance
|
|
|
|
|
According to MSDN[^], you must pass the address of a 'comparison function' (have also a look at the provided code sample).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
using this method also gives same error
error C2664: 'CListCtrl::SortItems' : cannot convert parameter 1 from 'int (__stdcall CItemDlg::* )(LPARAM,LPARAM,LPARAM)' to 'PFNLVCOMPARE'
|
|
|
|
|
Please show us both the code and the error.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
m_List.InsertColumn(0,"Name",100,100);
m_List.InsertColumn(1,"Number",100,100);
m_List.InsertItem(0,"Item1");
m_List.SetItemText(0,1,"2");
m_List.InsertItem(1,"Item2");
m_List.SetItemText(1,1,"3");
m_List.InsertItem(2,"Item3");
m_List.SetItemText(2,1,"1");
I want to sort these items according to second column i.e "number" column
int CALLBACK CItemDlg::MyCompareProc(LPARAM lParam1, LPARAM lParam2,
LPARAM lParamSort)
{
UNREFERENCED_PARAMETER(lParamSort);
return (int)(lParam1 - lParam2);
}
void CItemDlg::OnBnClickedButton1()
{
m_List.SortItems(&CItemDlg::MyCompareProc, 0);
}
when i compile this code, it shows this error
error C2664: 'CListCtrl::SortItems' : cannot convert parameter 1 from 'int (__stdcall CItemDlg::* )(LPARAM,LPARAM,LPARAM)' to 'PFNLVCOMPARE'
Thanks for helping
|
|
|
|
|
MyCompareProc cannot be an ordinary member of the class (must be a global function or a static class member). We should blame MSDN for providing a broken code sample.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Should be:
m_List.InsertColumn(0,"Name",100,100);
m_List.InsertColumn(1,"Number",100,100);
int x = m_List.InsertItem(0,"Item1");
m_List.SetItemText(x,1,"2");
x = m_List.InsertItem(1,"Item2");
m_List.SetItemText(x,1,"3");
x = m_List.InsertItem(2,"Item3");
m_List.SetItemText(x,1,"1");
int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
UNREFERENCED_PARAMETER(lParamSort);
return (int)(lParam1 - lParam2);
}
void CItemDlg::OnBnClickedButton1()
{
m_List.SortItems(MyCompareProc, 0);
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
|
I want to display image which is in fits format in my application like an image viewer.
thanks in advance
|
|
|
|
|