|
Hello!
I'm making some kind of file viewer.
but I can't open "next file" in program....
I want to open files with NEXT or PREV button : like 'ACDsee'.
How can I do this?
I use OnOpenDocument for file open and use CDvApp::OnFileOpen().
first, I try CFileFind class to find files. but can not find current Dir and
that have only FindNextfile func.
following: using CFileDialog.
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter);
if(IDOK == fileDlg.DoModal())
{
OpenDocumentFile(fileDlg.GetPathName());
POSITION pos = fileDlg.GetStartPosition();
((CDvMenu*)pMenu)->NextPath = fileDlg.GetNextPathName(pos);
}
in this, NextPath have not 'next'. It is same as current-opened file's.
Why this?
|
|
|
|
|
Analysis of the posted code:
The 'GetStartPosition' and 'GetNextPathName' methods are used to run through a list of selected file names. To enable this kind of behaviour, your FileDialog must sport the 'OFN_ALLOWMULTISELECT' style. Now, when the dialog is shown, you must select multiple files by holding CTRL or SHIFT down when clicking names.
After the call to DoModal returns (you click Ok), the file list is ready, and can be browsed through by using the above mentioned methods. Remember to check the return values of GetStartPosition and GetNextPathName. First one returns NULL if there is no file list, and the latter returns NULL if the list has ended.
From your description, however, I understood that you wanted to create a quick file preview/browser application. For this purpose, you should approach the problem from a bit different perspective: create a list of existing files in a directory, and move through this list when the user is clicking the buttons.
The MFC class CFileFind is perfect for this purpose: first use it to enumerate the file names in the current directory, and save these to e.g. a list of CString objects (CString strList[MAX_NUMBER]). Now, at the start of the browsing, initialize the position integer (iPos) to zero, and open the file pointed to by strList[0]. When user clicks 'prev' or 'next', increase or decrease the iPos value and re-open the file. Remember to close the currently open file first, though, or you might end up with a HUGE memory leak of open file handles.
Here is a code fragment to get you started. It will enumerate through the current directory, accepting all files. These file names are written to a static CString list. This list must be a member of your application class, so it doesn't go out of scope after the enumeration returns.
void EnumerateFiles(void)
{
int iPos = 0;
CFileFind cfFinder;
BOOL bContinue = cfFinder.FindFile("*.*");
while (bContinue)
{
bContinue = cfFinder.FindNextFile();
strList[iPos] = cfFinder.GetFileName();
iPos++;
}
cfFinder.CloseSearch();
return;
}
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I'm using the class wizard in Visual Studio 6 to create OnLButtonDown() and OnLButtonDBClick() handlers, searching for hits in the same region. How do I avoid executing my OnLButtonDown() handler for double clicks?
Jason
|
|
|
|
|
If you used the App Wizard to create the project for you, then go to your main window's (Frame window or dialog) PreCreateWindow override. If you don't have this override yet, create it by using Class Wizard.
In this override, you must register a new window class (AfxRegisterWndClass) with 'CS_DBLCLKS' class style, and place the return value of the registration call to the class name member of the CREATESTRUCT structure. Now, whenever user double-clicks the mouse over your window, a WM_LBUTTONDBLCLK / WM_RBUTTONDBLCLK message is generated for the window.
Here's a code fragment to help you out:
BOOL CMyDerivedCWnd::PreCreateWindow(CREATESTRUCT& cs)<br />
{<br />
cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS, NULL, NULL, NULL);<br />
<br />
return CWnd::PreCreateWindow(cs);<br />
}
The single-click and the double-click are seperate events. You create the first by clicking once, and you generate the second by clicking twice quickly. So, when you do a quick double-click, only the double-click event is sent, providing that your window class style supports double-click messages, as specified above.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hmm, I must be using the wrong messages. I tried adding the code frament suggested, however, I'm getting the same results. When I double click the region, the single click (WM_LBUTTONDOWN) event is handled first, followed by the double click (WM_LBUTTONDBCLK) event. In other words, both event handlers are being called. Are these the correct messages to use for this?
Jason
|
|
|
|
|
If you need to have specific, unconditionally seperate handlers for the single-click and the double-click, then I think you should consider a completely different approach: capture the mouse and monitor it's clicks. If a click is made, and another click is not made in the next 20-50 ms, then a custom WM_LBUTTONDOWN message is generated, otherwise, a custom WM_LBUTTONDBLCLK message is made.
Doing this MFC-way would mean resorting to a little more than an outright hack..
This means that in addition the standard WM_ handlers, you must create more UINTs for custom WM_ messages, such as WM_CUSTOM_L/RBUTTONDOWN and WM_CUSTOM_L/RBUTTONDBLCLK (this would mean four new UINTs), which your application then handles. In the standard handlers, you calculate the time span between clicks, and determine the custom message based on these calculations.
A bit more work, but doable, I think. For example, add two timers, both with a custom WM_CUSTOM_TIMER1/2 message applied, to your application, which you start and stop with the clicks. When a WM_L/RBUTTONDOWN message is received, the timer is started. If a new message of same type is received and the timer is still running, then the timer is stopped and a WM_CUSTOM_L/RBUTTONDBLCLK message is generated. If the timer is allowed to run to it's first 'WM_CUSTOM_TIMER1/2' handler, it generates the WM_CUSTOM_L/RBUTTONDOWN and stops itself.
In addition to this, you should override the WindowProc member function to get a direct access to the window procedure and message handling of your application. Alternatively, you can also write the required message map entries manually. Use ON_MESSAGE ( <Message ID>, <function name> ) entries in the map.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
When you double-click, three messages are generated
WM_LBUTTONDOWN<br />
WM_LBUTTONUP<br />
WM_LBUTTONDBLCLK
You can set a timer in the LBUTTONDOWN handler, then if the LBUTTONDBLCLK message arrives, kill the timer. Otherwise, when the timer fires, run your single-click code (and also kill the timer, so it only fires once).
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain."
-- Paul Watson, Linux Zombie
|
|
|
|
|
Has any one ever worked with the BITMAPV4HEADER & BITMAPV5HEADER bitmaps? I know what versions of Windows these are supported on but have been unable to find any bitmaps using these headers. I am interested in adding support for these bitmap types to a class I have developed for using DIBs. I beleive my class will have no problem reading these files but the new data fields ,in these headers, will be ignored.
When should I use one of these newer headers?
Is there any examples of how and when to take advantage of these newer types?
I have searched the www and only found descriptions of the headers, plus one file that recongises BITMAPV4HEADER.
INTP
|
|
|
|
|
The BITMAPV5HEADER has enhanced support for JPEG compression, including the ability to pass a JPEG DIB to StretchDIBits(). I have the old MSDN98 docs - email me (thru CP) if you want me to send the BITMAPV5HEADER page to you.
|
|
|
|
|
Does anybody know of an easy to use class that I can use to popup the windows address book app (wab.exe) and get back the users selection, both the email address and the friendly name?
Or maybe an implementation of the "Select Recipients" dialog and the "To" address bar used in outlook express?
Basicly, I want to be able to let my users select recipients from their address book.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Frankly i'm a little shocked that you didn't look here first :
http://www.codeproject.com/cpp/wabapi.asp[^]
Granted, it doesn't popup the app, but you can throw the names in a listbox and let the users choose.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
cmk wrote:
i'm a little shocked that you didn't look here first
hmmmm, I am a little shocked too. I totally missed that article, thanks for the link
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
The path to wab.exe on any machine you can find by searching in the registry.
The default value of HKCR\.wab gives you the key where you will find the full path to wab.exe. On my XP this is HKCR\wab_auto_file, where you have to look at shell\open\command the default value of which contains the full path.
However the wab.exe (as far as I am concerned) cannot return the email address to an external app because, there is no button for this either. You just can open the default mail writer from it which is actually a ShellExecute with the selected email address from wab.exe.
The only way for you is to extract all emails and friendly names from wab.exe without showing it to the user and construct your own dialog with this data, which you can fully control.
The extraction of email addresses from wab is desribed here:
http://www.codeproject.com/file/findidaddressbook.asp[^]
Bunburry
|
|
|
|
|
Thanks for the link
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Dear all,
Do you know how to find the number of same items in two STL vectors.
if i have v1=[2,5,6,7,8] and v2=[3,5,7,9] the number the same items in both vectors is 2 which are 5 and 7. is there a effecint way to do this?
thanks.
Hesham.
|
|
|
|
|
|
Need some information or websites about how to send an SMS using visual c++ 6;P
nolan
|
|
|
|
|
There are two ways to send SMS :
1.You can connenct to the SMSC (SMS Center of your mobile operator) over the internet, and send message through it. This of course requires an internet connection as well as an account with your operator but it does not require a mobile phone.
An implementation:
http://www.codeproject.com/useritems/smpplib.asp
2.Your PC communicates directly with the phone over serial port, IrDA or Bluetooth, either in text or (which is more common) PDU mode
A goog starting point for the theory:
http://www.dreamfabric.com/sms/
Bunburry
|
|
|
|
|
Thank you so much for your help,I''ll try and get on to SMSC and will let you know how it goes,
thanks;)
nolan
|
|
|
|
|
i tried to create a button by declaring a CButton object in the CView::OnCreate message in my MFC SDI Application , but what i'v noticed that the button won't be created untill i declare the CButton object in the Class Declaration, thats weird ! why i can't declare and create the button in the class definition !?
thanx
|
|
|
|
|
Because of the way MFC works:
1. Construct an object you desire in the application. This can be anything from CButton to CPen, a CEdit or a CListBox, no matter. You can construct it statically (adding a static member to your parent class definition) or dynamically (by using a static pointer with the 'new' operation)
2. When the object is constructed, call it's 'Create' member method to create the underlying Windows object, and bind it to this MFC object.
3. When you no longer need the Windows object, call 'DeleteObject' to destroy it.
4. When you no longer need the MFC object, either let it pass out of scope so it's destructor is called (static members) or call 'delete' to release dynamically reserved memory.
Now, as for the code analysis you posted:
You created a CButton static object in the CView::OnCreate handler. This means that the MFC object is constructed. If you call the 'Create' member function, the underlying Windows object is created as well. When the handler call ends, the CButton destructor gets called, and it's existence straightforwardly ends.
You should go to the local library and pick up an MFC programming book. Knowledge in Windows programming also helps. This book would be able to clarify the functionality of MFC to you in detail, so you can get a better grasp of what it actually is and how it is used.
CodeProject sports a collection of good articles as well:
-Nishant S.'s excellent 'MFC under the hood' article http://www.codeproject.com/cpp/mfcprogflow.asp[^].
-Mehdi Mousavi 'Win32 vs MFC, part I' http://www.codeproject.com/cpp/mfc_architecture.asp[^].
-Joseph M. Newcomer with 'Attaching and Detaching objects' http://www.codeproject.com/cpp/attachdetachobj.asp[^].
You can find more from the 'General' and 'Beginners' sections of General -> C++/MFC area. Happy browsing
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
|
Hi, i'm making a class that has all static functions and variables in it. When i first made a few private static variables it gave me a linker error about unresolved externals. But then i found that if you initialized the values in your .cpp file then it didn't give those errors. But one of the variables i'm declaring is an array of a struct which is also declared as private in my class. But now my problem is, how do i initialize the array? i mean, i can't just initialize the array to NULL because well.. the types don't match. Here's an example:
.h file:
class blablabla
{
private:
struct somestruct
{
int int1;
int int2;
}
static somestruct myarray[10];
static int someint;
public:
}
.cpp file:
blablabla::someint = 0;
blablabla::myarray = ???
Kuniva
--------------------------------------------
|
|
|
|
|
This initializes the array to be filled with zeros.
blablabla::somestruct blablabla::myarray[10] = { };
- Mike
|
|
|
|
|
thanks! you forgot the 0 between the { and } though cause it wouldnt work at first
|
|
|
|
|