|
Rickard Andersson wrote:
Is it possible to do this:
// Timer one
SetTimer(1, 1000, NULL);
// Timer two
SetTimer(2, 1000. NULL);
Yes, of course. You should post some more code to show how you're setting them up and using them.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Ok, here is the OnTimer function:
All comments are writen in SWEDISH...
The problem was that when I try to launch open the dialog in timer 1 the KillTimer func doesn't seems to be called or something? The dialog boxs appears, and appears, and appears.... but when next minut comes then it can be called and timer 1 is killed... Hope I could explain it! And this happens when I have to timers in use at the same time
the reg vaiables are CHKLM objects, the registry class here from code project... is there anything else you want? PLEASE TELL ME!! IF YOU CAN TELL ME HOW TO AVOID THIS YOU'RE BEST!
void CReminderSEDlg::OnTimer(UINT nIDEvent)
{
reg.SetRegistryKey(_T("CodeCracker"));
switch(nIDEvent)
{
case 2:
{
// Hämta aktuell tid
CTime CurTime;
CurTime = CTime::GetCurrentTime();
// Spara den aktuella tiden i ett CString objekt
CString szCurTime;
szCurTime.Format("%d:%d", CurTime.GetHour(), CurTime.GetMinute());
//AfxMessageBox(szCurTime);
if( m_szKomIhagTid == szCurTime )
{
int ret = KillTimer(2);
CString str;
str.Format("%d",ret);
AfxMessageBox(str);
sndPlaySound("STANDARD2.WAV", SND_ASYNC);
CAlertDlg dlg;
dlg.DoModal();
reg.WriteProfileInt(_T("CMeddelandeDlg"), _T("Aktivate"), 0);
m_sPamin.SetBitmap(::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)));
m_KiTid = "";
Invalidate();
UpdateData(FALSE);
}
}
case 1:
{
// Hämta aktuell tid
CTime CurTime;
CurTime = CTime::GetCurrentTime();
// Spara den aktuella tiden i ett CString objekt
CString szCurTime;
szCurTime.Format("%d:%d", CurTime.GetHour(), CurTime.GetMinute());
// Hämta alarm tiden från registret
int nHour = reg.GetProfileInt(_T("CConfigDlg"), _T("Hours"), NULL);
int nMinute = reg.GetProfileInt(_T("CConfigDlg"), _T("Minutes"), NULL);
// Spara alarm tiden i ett CString objekt
CString szAlarmTime;
szAlarmTime.Format("%s:%s", Minutes(nHour), Minutes(nMinute));
if( szAlarmTime == szCurTime )
{
// Döda timer nu så vi inte får problem
KillTimer(1);
reg.WriteProfileInt(_T("CConfigDlg"), _T("Aktivate"), 0);
m_MorgonAlarm.SetBitmap(::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1)));
GetDlgItem(IDC_BUTTON3)->EnableWindow(TRUE);
m_VackTid = "";
Invalidate();
UpdateData(FALSE);
// Kolla om användaren harvalt en MP3 eller en WAV som alarm ljud
int Mp3OrWav = reg.GetProfileInt(_T("CLjudDlg"), _T("Mp3OrWav"), NULL);
if( Mp3OrWav == 1 ) // Det är en mp3
{
// Spela ljudet
PlayMp3(FALSE);
//AfxMessageBox("Mp3");
// Skapa fönstret som välkomnar di på morgonen
CWakeUpDlg dlg;
int i = dlg.DoModal(); // Visa det
if( i == IDOK ) // Fånga upp vad användaren tryckte på
{
//MCIWndStop(m_WndPlay);
PlayMp3(TRUE);
}
else if( i == IDCANCEL )
{
reg.SetRegistryKey(_T("CodeCracker"));
CString str;
str = reg.GetProfileString(_T("Main"), _T("MailPath"), NULL);
if( str.IsEmpty() == TRUE )
{
PlayMp3(TRUE);
CSystemTray::MaximiseFromTray(this);
}
else
{
PlayMp3(TRUE);
WinExec(str,SW_SHOW);
}
}
}
else
{
// Skapa fönstret som välkomnar dig på morgonen
CWakeUpDlg dlg;
// Spela ljudet
PlayWav(FALSE);
int i = dlg.DoModal();
if( i == IDOK )
{
PlayWav(TRUE);
CSystemTray::MaximiseFromTray(this);
}
else if( i == IDCANCEL )
{
reg.SetRegistryKey(_T("CodeCracker"));
CString str;
str = reg.GetProfileString(_T("Main"), _T("MailPath"), NULL);
if( str.IsEmpty() == TRUE )
{
PlayWav(TRUE);
CSystemTray::MaximiseFromTray(this);
}
else
{
PlayWav(TRUE);
WinExec(str, SW_SHOW);
}
}
}
}
}break;
default:
break;
}
CBitmapDialog::OnTimer(nIDEvent);
}
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
You need to put a break between your switch statements - as it stands, case 2 causes both blocks of code to execute.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
DAMN MOI!!!
You did it again you... Argh!!
I want your experience in my brain!!
A BIG F.U.C.K.I.N.G THANK YOU!!
!!!!!
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
I have a class derived from CWinThread. I create an instance of the object using new and then call CreateThread. So now I have a thread running. My question is:
What are the consequences, if any, if I call a member function of that object? Say I set the thread running then called the objects getCount() function. I've not had any luck with this. Just wondering if it's impossible or is there some stack issues I'm not aware of.
Seems like a strange question I hope I explained well enough. Lemme know if I didn't.
|
|
|
|
|
nay wrote:
I've not had any luck with this.
What do you mean?
nay wrote:
. Just wondering if it's impossible or is there some stack issues I'm not aware of.
You're asking if you can call member functions of the object you created using new, right? It should be OK; you'll just be calling the functions from within the original thread instead of the one just created.
Regards,
Alvaro
|
|
|
|
|
"I've not had any luck with this."
What I meant was I did call the function after I set the thread running. I was passing a pointer into the function. But as soon as I step into the function (in the debugger) the pointer is garbage. I thought it could be because the function is in the same object as a thread.
Alvaro Mendez wrote:
It should be OK; you'll just be calling the functions from within the original thread instead of the one just created.
Yeah that's what I thought but I wanted an un biased opinion. Thanks for the reply!
nay
|
|
|
|
|
I have a function that is called be visual basic to draw to a picturebox. What that picturebox has is some video on it and I want to be able to change the colours of the image. I am trying to use CreateDIBSection but I seem to be missing something as I can't change the colors. I know that I have the right DC because I can draw a rectangle on it but I can't seem to get a proper bit set. Here is my code:
void __stdcall OverlayMask(long hWnd, long MaskArray)
{
RECT rc;
LONG lWidth = 0;
LONG lHeight = 0;
BITMAPINFO bmi;
HBITMAP hbmp = NULL;
BYTE* bpDIBits = NULL;
GetClientRect((HWND)hWnd, &rc);
lWidth = rc.right - rc.left;
lHeight = rc.bottom - rc.top;
ZeroMemory(&bmi, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = lWidth;
bmi.bmiHeader.biHeight = lHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 24;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biXPelsPerMeter = 72;
bmi.bmiHeader.biYPelsPerMeter = 72;
HDC tmpDC = GetDC((HWND)hWnd);
hbmp = CreateDIBSection(
tmpDC, (LPBITMAPINFO)&bmi, DIB_RGB_COLORS,
(LPVOID*)&bpDIBits,
NULL, 0);
if (hbmp == NULL) AtlTrace("Unable to create DIB Section\n");
if (bpDIBits == NULL) AtlTrace("Unable to create DIBits\n");
HBRUSH hBrush = CreateSolidBrush(RGB(0xFF, 0x0F, 0xF0));
FillRect( tmpDC, &rc, hBrush ); // <- This works fine.
for (int i = 0; i < (lWidth*lHeight/3); i++) //<- This
{
*(bpDIBits++) = 0;
*(bpDIBits++);
*(bpDIBits++) = 0x66;
} // <- doesn't
AtlTrace("1) OverlayMask: %x %x", hWnd, MaskArray);
GdiFlush();
ReleaseDC((HWND)hWnd, tmpDC);
}
Thanks in advance,
Clint Singer
|
|
|
|
|
Well, after creating the DIB section (which I assume you have no problems with) and doing whatever you want with bpDIBits you will have to paint the bitmap by:- creating a DC compatible with tmpDC (use
CreateCompatibleDC for this),
- selecting the bitmap you've created into this compatible DC with
SelectObject(compatibleDC,hbmp) ,
- doing the actual painting to
tmpDC with BitBlt(tmpDC,0,0,lWidth,lHeight,compatibleDC,0,0,SRCCOPY)
Also, don't forget to clean everything up (compatibleDC ,hbmp ...)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I´m having trouble using "global" ado recordset pointers in a project.
I have a recordset in a +/- fixed window, that I want to used by other windows that are constantly beeing created and destroyed.
I can access the window pointer easily but when i try to access the recordset pointer the program crashes. The weird thing is that i can visualise the pointer in the debug windows correctly. the code is below, what am I dooing wrong?
class CMainFrame : public CFrameWnd{...
public:
_ConnectionPtr pCon;
CWnd *pTrabalhadoresView;
...}
class CDLG_TRABALHADORES_VIEW : public CResizableFormView{...
public:
_RecordsetPtr
pRstTrabalhadoresDados;
...}
void CDLG_TRABALHADORES_VIEW::OnInitialUpdate()
{...
pMain= (CMainFrame *)AfxGetMainWnd();
pRstTrabalhadoresDados.CreateInstance(__uuidof(Recordset));
pRstTrabalhadoresDados->Open("trabalhadoresdados",_variant_t((IDispatch *)pMain->pCon,true),adOpenDynamic,adLockOptimistic,adCmdTableDirect);
...}
void AnotherWindow::OnSomething(){...
CMainFrame* pMain= (CMainFrame *)AfxGetMainWnd();
CDLG_TRABALHADORES_VIEW* pTrabalhadoresView=(CDLG_TRABALHADORES_VIEW*)pMain->pTrabalhadoresView;
_RecordsetPtr pRstTrabalhadoresData=pTrabalhadoresView->pRstTrabalhadoresDados;
/* UNHANDLED EXCEPTION IN TEST.exe: 0xc0000005: Access violation */
...}
Texas
|
|
|
|
|
Texas:
You need to put the recordset, in the MainFrame and to Instance it in the MainFram. Also you can make the same in the CWinApp Class...
You will can access to the recordset from every window, using
<br />
CWinApp::_RecordsetPtr<br /> \
best Regards...
Chau!!! and good weekend!!!
Carlos Antollini.
Sonork ID 100.10529 cantollini
|
|
|
|
|
Hi,
If I want to find unwanted DLL in the system, how should I find it, is there any method available
Kindly reply me
Regards
John
|
|
|
|
|
Do you know the name of the DLL? If so, then it's just like finding any regular file on the system. FindFirstFile and FindNextFile are the APIs which immediately come to mind for doing that. The CFileFind class is an alternative if you're using MFC. Other than that, I don't know but I'm trying to remember an API call I came across a while back that would search the hard drive for you. If I remember, I'll post it.
Regards,
Alvaro
|
|
|
|
|
I am trying to replace spaces with newlines \n's in a file to create a single column then I can read the file using ReadString to get one value at a time but it doesn't work. It still thinks the file has the original set-up of rows and columns instead of just a single column. Can anyone explain why?
Here is the code...
CString cFilename = lpszPathName;
CStdioFile fDataFile,fDataCol;
CString szValue;
CString szRow;
fDataFile.Open(lpszPathName, CFile::modeRead);
fDataFile.ReadString(szRow);
int nFirst = szRow.Replace(" ","\n");
while(fDataFile.ReadString(szRow))
{
int nCol = szRow.Replace(" ","\n"); }
fDataFile.Close();
fDataCol.Open(lpszPathName, CFile::modeRead);
BOOL b = fDataCol.ReadString(szValue);
if(TRUE == b)
{
m_nRows = atoi(szValue);
}
b = fDataCol.ReadString(szValue);
if(TRUE == b)
{
m_nColumns = atoi(szValue);
}
m_nValues = (m_nRows*m_nColumns);
m_GraphData.SetSize(m_nRows);
int nRowCount;
int nColumnCount;
for (nRowCount = 0; nRowCount
|
|
|
|
|
Without looking at your code I'm going to guess that it's because you need to use \r\n instead of just \n. Try that and see if it makes a difference.
Regards,
Alvaro
|
|
|
|
|
does anyone know how i can use powerpoint presentation files in my MFC app and make a slide show in full screen with one? (like the slideshow in powerpoint itself). Is there an active-x container for this or something, or is the powerpoint format simple enough to create the slideshow from scratch?
Easiest way?
Thanx
Kuniva
|
|
|
|
|
Hello everyone.
My question and current task is kinda simple. All I need to do is to send an email to the network admin from my MFC application that runs 24/7 on the server box. Sometimes, for unknown reason, the server box freezes and the only possible action(if I solve this problem) is to send an "alert" message to the network admins that "box needs to be rebooted ASAP".
I know that there are lots of COM components(like ASP mail) out there that facilitate email protocols. As well, there is a number of socket API's and classes.
Does anyone know which way is the fastest and easiest for MFC app to send a simple email.
Big thanks in advance.
Kirill
|
|
|
|
|
Use ShellExecute with the program set to a mailto link protocol; i.e mailto:admin@company&subject="blah" etc... using &body. Not a very full answer but I've got some VC problems at the moment so can't access documentation.
--
Andrew.
|
|
|
|
|
How do i switch the Windows Media Player active-x control to fullscreen if its declared as m_cPlayer?
m_cPlayer.SetDisplaySize(?)
if so, what value?
Thanka
Kuniva
|
|
|
|
|
First, a big "thank you" to everyone who has been helping me. I know I've been asking a lot of stupid questions, but once I get this stuff relearned, I think I'll be fine.
So, here's the next stupid question. I've got an integer, and and I want it in a CString. For example:
//Before
int myint = 123;
//After
CString mystring = "123";
The problem is that when I try to assign it directly, it puts the character with the ASCII value of the int into the string (I think). Anyway, then I looked up itoa in MSDN, and found a solution. But you must pass itoa a character array to store the resulting text in. Anyway, the only way I know to make it work is like this:
char cDay[3] = " ";
_itoa(theTime.GetDay(), cDay, 10);
CString Day = cDay;
Anyway, the basic idea is that I changed it from an int to a char array, and then from a char array to a CString. But I'm sure there's a way to leave out the char array and just do it directly. Thanks again.
~Cam Desautels (BinaryUprising.com)
|
|
|
|
|
The following snippet of code is useful for writing numeric values into std::string s:
#include <sstream>
template <typename T> inline std::string tostring(const T& t)
{
std::ostringstream ostr;
ostr<<t;
return ostr.str();
} It must be trivial to adapt it for MFC CString s.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Ahh...yes, if I'm going to be doing a lot of conversions like that, a template would be a very good idea. But I don't really understand that code...I don't get what the binary shift does...but isn't there a more direct route?
~Cam Desautels (BinaryUprising.com)
|
|
|
|
|
Here's the most direct way, short of writing your own little function to do it:
CString Day;
Day.Format(_T("%d"), theTime.GetDay());
Regards,
Alvaro
|
|
|
|
|
|
Hi there,
can somebody tell me how to Change 'Capiton' text of a CPropertyPage at Runtime.
this
m_psp.pszTitle = "Test";
or this
SetWindowText("Test");
dosn't work
Thanks
Claus
|
|
|
|
|