|
I wrote a set of functions for displaying a progress window while CopyFileEx() runs. The only problem is that the cancel button on the window won't work. Well, actually it will work if I display a message box right before I create the window, which I haven't been able to explain yet... Anyway, here is the full code for it, less the headers:
#include "global_definitions.h"
#include <windows.h>
#include <commctrl.h>
#include "debug.h"
#include "memory.h"
#include "stringio.h"
#include "window_classes.h"
void InitProgressWindowClass(void);
int CopyFileProgressEx(LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName, DWORD dwCopyFlags, HWND hWndParent, char * title, char * message, BOOL popup, DWORD parentUpdate);
DWORD WINAPI ProgressWindowThread(LPVOID lParam);
INT_PTR CALLBACK ProgressWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
LRESULT ProgressWindow_OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam);
DWORD CALLBACK CopyProgressRoutine(LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred, LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData);
void InitProgressWindowClass(void)
{
WNDCLASSEX wc = {0};
wc.cbSize = sizeof(wc);
wc.lpszClassName = "Progress Window";
wc.hInstance = GetModuleHandle(NULL);
wc.lpfnWndProc = ProgressWindowProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_BTNFACE);
wc.cbWndExtra = sizeof(PROGRESSINFO *);
RegisterClassEx(&wc);
}
int CopyFileProgressEx(LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName, DWORD dwCopyFlags, HWND hWndParent, char * title, char * message, BOOL popup, DWORD parentUpdate)
{
PROGRESSINFO * pip = ClearMemAlloc(sizeof(PROGRESSINFO));
BOOL error;
BOOL cancel = 0;
DWORD threadId;
if(!title)
title = "";
if(!message)
message = "";
pip->title = title;
pip->message = message;
pip->popup = popup;
pip->cancel = &cancel;
pip->hWndParent = hWndParent;
pip->parentUpdate = parentUpdate;
SetFocus(hWndParent);
CreateThread(NULL, 0, ProgressWindowThread, pip, 0, &threadId);
while(!pip->hWndProgress)
Sleep(0);
error = CopyFileEx(lpExistingFileName, lpNewFileName, CopyProgressRoutine, pip, NULL, dwCopyFlags);
if(!error)
return 1;
else if(cancel)
return 2;
return 0;
}
DWORD WINAPI ProgressWindowThread(LPVOID lParam)
{
MSG msg;
DWORD exitCode = 0;
PROGRESSINFO * pip = (PROGRESSINFO *) lParam;
DWORD dwStyle = (pip->hWndParent != NULL ? WS_CHILD : 0) | WS_VISIBLE;
RECT progressCords;
if(pip->popup)
{
progressCords.left = GetSystemMetrics(SM_CXSCREEN) / 2 - PROGRESSWINDOW_WIDTH / 2;
progressCords.top = GetSystemMetrics(SM_CYSCREEN) / 2 - PROGRESSWINDOW_HEIGHT / 2;
dwStyle |= WS_POPUPWINDOW;
}
else
{
dwStyle |= WS_DLGFRAME;
GetClientRect(pip->hWndParent, &progressCords);
progressCords.left = (progressCords.right - progressCords.left) / 2 - PROGRESSWINDOW_WIDTH / 2;
progressCords.top = (progressCords.bottom - progressCords.top) / 2 - PROGRESSWINDOW_HEIGHT / 2;
}
pip->hWndProgress = CreateWindowEx(
0,
"Progress Window",
pip->title,
dwStyle,
progressCords.left,
progressCords.top,
PROGRESSWINDOW_WIDTH,
PROGRESSWINDOW_HEIGHT,
pip->hWndParent,
NULL,
GetModuleHandle(NULL),
pip);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GetExitCodeThread(GetCurrentThread(), &exitCode);
ExitThread(exitCode);
ErrorMessage("Abnormal thread termination", NULL, NULL, MB_ICONEXCLAMATION, 1);
return FALSE;
}
INT_PTR CALLBACK ProgressWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CREATE:
return ProgressWindow_OnCreate(hWnd, wParam, lParam);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case BN_CLICKED:
*(((PROGRESSINFO *)(GetWindowLongPtr(hWnd, GWL_USERDATA)))->cancel) = 1;
break;
}
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
free((void *) GetWindowLongPtr(hWnd, GWL_USERDATA));
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
LRESULT ProgressWindow_OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
PROGRESSINFO * pip = *(PROGRESSINFO **) lParam;
RECT rect;
SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG) pip);
GetClientRect(hWnd, &rect);
pip->progressBar = CreateWindowEx(
WS_EX_CLIENTEDGE,
PROGRESS_CLASS,
NULL,
WS_CHILD | WS_VISIBLE | PBS_SMOOTH,
rect.left + 2,
PROGRESSWINDOW_HEIGHT / 2 - GetSystemMetrics(SM_CYVSCROLL),
rect.right - 5,
GetSystemMetrics(SM_CYVSCROLL),
hWnd,
0,
GetModuleHandle(NULL),
NULL);
pip->hWndStatic = CreateWindowEx(
0,
"Static",
NULL,
WS_CHILD | WS_VISIBLE | SS_CENTER,
rect.left + 2,
rect.top + 10,
rect.right - 5,
rect.top + 20,
hWnd,
0,
GetModuleHandle(NULL),
NULL);
SetWindowText(pip->hWndStatic, pip->message);
pip->hWndCancel = CreateWindowEx(
0,
"Button",
NULL,
WS_CHILD | WS_VISIBLE | BS_TEXT | BS_PUSHBUTTON,
((rect.right - rect.left) / 2) + rect.left - 30,
rect.bottom - 30,
60,
24,
hWnd,
0,
GetModuleHandle(NULL),
NULL);
SetWindowText(pip->hWndCancel, "Cancel");
pip->hWndProgress = hWnd;
SetFocus(pip->hWndCancel);
return FALSE;
}
DWORD CALLBACK CopyProgressRoutine(LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred, LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData)
{
int i;
unsigned __int64 biasBit = 0x8000000000000000;
int progressRange;
int progressAchieved;
PROGRESSINFO * pip = lpData;
if(!pip->progressBias)
{
if(!(TotalFileSize.QuadPart & 0xFFFFFFFF80000000))
pip->progressBias = 0;
else
{
for(i = 33; i; i--)
{
if(biasBit & TotalFileSize.QuadPart)
break;
biasBit = biasBit>>1;
}
pip->progressBias = 32 - i;
}
}
progressRange = (int) (TotalFileSize.QuadPart>>(pip->progressBias + 1));
progressAchieved = (int) (TotalBytesTransferred.QuadPart>>(pip->progressBias + 1));
SendMessage(pip->progressBar, (UINT) PBM_SETRANGE32, (WPARAM) 0, (LPARAM) progressRange);
SendMessage(pip->progressBar, (UINT) PBM_SETPOS, (WPARAM) progressAchieved, (LPARAM) 0);
if(pip->parentUpdate && pip->lastParentUpdate + pip->parentUpdate >= GetTickCount())
UpdateWindow(pip->hWndParent);
pip->lastParentUpdate = GetTickCount();
if(TotalFileSize.QuadPart == TotalBytesTransferred.QuadPart)
{
PostMessage(pip->hWndProgress, WM_CLOSE, 0, 0);
return PROGRESS_CONTINUE;
}
if(*pip->cancel)
{
PostMessage(pip->hWndProgress, WM_CLOSE, 0, 0);
return PROGRESS_CANCEL;
}
else
return PROGRESS_CONTINUE;
}
|
|
|
|
|
Anyone know of any samples on how to write a streaming audio server??
|
|
|
|
|
Check out the DirectSound samples in the DirectX SDK.
The SDK does not provide an out-of-the-box streaming server solution. However the examples (in native C++ and in C#) give you a good introduction to the handling the audio data.
Can't comment about the network aspects.
|
|
|
|
|
Do u mean u want to stream uncompressed PCM format? if so u can refer Multimedia SDK .
Dharani babu S
redindian
|
|
|
|
|
say i have
char strdata[100];
strcpy(strdata,"0.0000136");
float f;
the call
sscanf(strdata,"%f",&f) ; // works ok (ie f gets the correct value)
// but I cannot get
// need precision upto 6 places
sscanf(strdata,"%.6f",&f) ;
// I need formatted input
// to work
Please help .
|
|
|
|
|
I have a graph which plots 14 million points. I want to include a scroll bar which would be sized based on the visible portion of the graph. initally all 14 million points are displayed. User can then use zoom function to zoom the graph where a max of 450 points can be seen. I am not able to include the scroll bar function. can anyone tell me what are the properties i need to set in the Scrollbar info structure?
thanks,
|
|
|
|
|
First, I really appreciate that you spend your time to read my question.
Hi! I try to build a class that has several functions. Some of them will return string.
But my complier say I have something wrong.
The complier show the message that undefine error.
Please help me to figure out. Thank you.
I paste my complete code below
// filename:studentinfo.h
class studentinfo
{
public:
void set_lastname(string);
void set_firstname(string);
void set_ssn(string);
void set_age(int);
void set_phone(string);
string show_lastname();
string show_firstname();
string show_ssn();
int show_age();
string show_phone();
private:
string lastname;
string firstname;
string ssn;
int age;
string phone;
};
// filename:studentinfo.cpp
#include <iostream>
#include <string>
#include "studentinfo.h"
//--------------------------------------------------------------------------------
// The following functions declare for my class.
//--------------------------------------------------------------------------------
string studentinfo::show_lastname()
{
return lastname;
}
string studentinfo::show_firstname()
{
return firstname;
}
string studentinfo::show_ssn()
{
return ssn;
}
int studentinfo::show_age()
{
return age;
}
string studentinfo::show_phone()
{
return phone;
}
void studentinfo::set_lastname(string text)
{
lastname=text;
}
void studentinfo::set_firstname(string text)
{
firstname=text;
}
void studentinfo::set_ssn(string text)
{
ssn=text;
}
void studentinfo::set_age(int number)
{
age=number;
}
void studentinfo::set_phone(string text)
{
phone=text;
}
|
|
|
|
|
Are you sure it's string not CString?
|
|
|
|
|
|
The standard string type is std::string , you can add using namespace std; after the includes to avoid adding the std:: prefix everywhere.
|
|
|
|
|
is there any way to guarantee a PC thread run at 200ms+_100ms period interval? Timer or multimedia timer seems don't fit.
|
|
|
|
|
Well, there's always the Sleep() funtion. I'm not sure how gurenteed the amount of time it waits is though.
Edit: Just checked. It's not gurenteed to resume excecution after the given time period, but you could probobly fix that with a heavy priority boost or something.
|
|
|
|
|
Yes I set the thread to high priority, it still won't guarantee. by the way, what is heavy priority boost?
|
|
|
|
|
I told you in a previous post that you can't have any such guarantees with a non-realtime OS like Windows. If you don't trust me, read this article[^].
Can you use some RTOS, like QNX[^]?
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
I have a win32 app and copy MFC code into it.
but the app can not be compiled now because of MFC classes.
MFC is in "Use MFC in a static library".
how to change settings for compiling?
thx
includeh10
|
|
|
|
|
Create two Win32 apps, tick 'use MFC' for one. Diff the files, and make sure you have all those things set in your own code.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi there!
I've got a problem with a simple, self-written DialogBar.
The DialogBar is not amazing at all, it simply displays a Dialog in a dockable ControlBar and is part of a DLL. If I try to create the DialogBar (in my MainFrame-Class), it fails and the control bar can not be created.
After a little research, I found out that the following line in the MFC-Core failed:
<br />
HWND hWnd = ::CreateWindowEx(cs.dwExStyle, cs.lpszClass,<br />
cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy,<br />
cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams);<br />
Another strange thing I found out while researching:
<br />
m_wndDialog.Create("bla fasel", this, 123456, WS_VISIBLE|WS_CHILD|CBRS_FLYBY|CBRS_SIZE_DYNAMIC|CBRS_TOOLTIPS)<br />
In that line a pointer to the parent window is passed to the Create() method (here this) of the DialogBar which is in the DLL.
If I verify the this-pointer before I enter the Create() method the member m_hWnd is valid and seems to be correct. But if I enter the Create() method (is a call to the DLL method), the m_hWnd of the parent window pointer becomes NULL.
Anybody out there with a solution to the problem?
Thanks in advance!
Axel
|
|
|
|
|
While coding in C# in the Visual Studio .NET 2003 IDE, one is able to mark regions using #region and #endregion.
Is a similar option available when coding in Visual C++?
|
|
|
|
|
you should be able to right-click in your editor window, go to 'Outlining' on the popup menu, and get a list of options there.
Who are all these people and what are they doing in my house?...Me in 30 years, inside a grocery store
My articles[^]
bdiamond
|
|
|
|
|
Hi
I have some 4 views all derived from CFormView. There is no system default menu in all. But i want to hang one menu in one of the view like Tools-->Copy.
I tried some options but it is failed. Can anybody tell me how to create this menu using CMenu class or with some other method??
Thanks in advance
Shailesh
|
|
|
|
|
Hello,
Given a CDocument object, how does one do about knowing the ID of the resource (the IDR_resource ) which was associated to the document template?
Thanks,
David
|
|
|
|
|
I have a project that is taking WAAAAYYYY too much time to compile... ( IMHO )
all files are C++ and are using precompile headers.
I use Program Database ( Zi ), minimal build ( and link ).
the only thing that I'm not sure, is that some of my source files are in subfolders of the main project file, and do
#include "../stdafx.h"
can that be a problem ?
also, there's a vc7.idb and vc7.pdb that are created ( and recreated ) quite often, I assume that the .pdb is the program database, but is it supposed to be recreated at every couple of files ?
THanks.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
With minimal build and link enabled, it can take longer and longer to compile and link because certain files are hashed, instead of being rewitten every time. You might try a FULL rebuild (or rebuild all) periodically to keep this thrashing to a minimum. I see this same problem with VC 6.0 when I have incremental link enabled.
The PDB must correlate the lines in your source with the locations on the executables, so it is common for that to rebuild each time you recompile and relink.
|
|
|
|
|
BOOL Cfirstw32mfcApp::InitInstance()
{
SetRegistryKey(_T("Natural_Demon"));
...
..
..
}
this works perfect ...
the data retrieved from the registry is nicely update in the GUI
BOOL Cfirstw32mfcDlg::OnInitDialog()
{
..
...
...
..
EDIT1 = AfxGetApp()->GetProfileString("Settings", "email", "your login");
EDIT2 = AfxGetApp()->GetProfileString("Settings", "password", "details here..");
return FALSE; // return TRUE unless you set the focus to a control
}
this works perfectly ...
HRESULT Cfirstw32mfcDlg::OnButtonOK(IHTMLElement* /*pElement*/)
{
AfxGetApp()->WriteProfileString("Settings", "email", "hi");
AfxGetApp()->WriteProfileString("Settings", "password", "do");
return NULL;
}
but why doesn't this work ...?
HRESULT Cfirstw32mfcDlg::OnButtonOK(IHTMLElement* /*pElement*/)
{
UpdateData(FALSE);
AfxGetApp()->WriteProfileString("Settings", "email", EDIT1);
AfxGetApp()->WriteProfileString("Settings", "password", EDIT2);
return NULL;
}
if i do this ...
UpdateData();, UpdateData(FALSE); or this UpdateDialogControls(this, FALSE);
nothing works
EDIT1 en EDIT2 are empty and the registry get's updated with empty values.
where am i mistaking here?
thnx in advance.
kind regards,
marco
|
|
|
|
|
Your Data Exchange handler function might not be set up correctly.
The Data Exchange might be overwriting the data in your edit field controls, or no member variables are setup to write into the controls.
It looks like you fill them in OnInitDialog, but you should do that in DoDataExchange.
|
|
|
|
|