|
PJ Arends wrote:
Is there a better way than using FindWindow to get the window handle to the dialog that pops up when a call is made to InternetConnectAttempt()
You could try setting a CBT hook just before the call to InternetAttemptConnect(). This is what MFC does to map HWNDs to CWnds. Then store the HWND so you can use it later. You could test the class name if you know it doesn't change, or even check some of the controls in the dialog box.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Yeah, that might work. I could set up the hook to catch any window creation routine. The problem comes that I do not know which windows will be created. I do not know their class names or their window captions. What should be consistant though is the process ID (at least according to spy++, Window Properties, Process tab, Process ID). I know that there will be only one visible top level window created by my app when I call InternetAttemptConnect but there may be others created by other apps.
So I guess my next question would be how would I go about getting the process ID of the window???
<EDIT>GetWindowThreadProcessId() will do the trick</EDIT>
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
PJ Arends wrote:
So I guess my next question would be how would I go about getting the process ID of the window???
<edit>GetWindowThreadProcessId() will do the trick
That's one way, although when the hook is called, the window has not been created yet, so it probably won't work. The other way is that because the hook procedure is called in the context of the process/thread creating the window, GetCurrentProcessId() will give the process ID of the window the hook is called for.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Actually, it does seem to be working
MSDN[^] says "At the time of the HCBT_CREATEWND notification, the window has been created" so calling GetWindowThreadProcessId returns the correct window handle to the dialup dialog.
Thanks for the tip
In the dll:
HINSTANCE hInst = 0;
HHOOK hook = 0;
HWND hWnd = 0;
DWORD ProcessID = 0;
static LRESULT CALLBACK CBTHook(int, WPARAM, LPARAM);
__declspec(dllexport) BOOL SetDUDWCHook(DWORD _ProcessID)
{
if (!hook)
{
hook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTHook, hInst, 0);
if (hook)
{
ProcessID = _ProcessID;
return TRUE;
}
}
return FALSE;
}
__declspec(dllexport) void ClearDUDWCHook()
{
if (hook && UnhookWindowsHookEx(hook))
{
hook = 0;
hWnd = 0;
ProcessID = 0;
}
}
__declspec(dllexport) void KillDUD()
{
if (hWnd && IsWindow(hWnd))
{
PostMessage(hWnd, WM_CLOSE, 0, 0);
PostMessage(hWnd, WM_CLOSE, 0, 0);
ClearDUDWCHook();
}
}
static LRESULT CALLBACK CBTHook(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HCBT_CREATEWND && !hWnd)
{
HWND Window = (HWND)wParam;
CBT_CREATEWND *pCW = (CBT_CREATEWND *)lParam;
DWORD Process = 0;
GetWindowThreadProcessId(Window, &Process);
if (Process == ProcessID)
hWnd = Window;
}
return CallNextHookEx(hook, nCode, wParam, lParam;
}
In the my program I call SetDUDWCHook() before InternetConnectAttempt() and ClearDUDWCHook() after. If the user presses the "Stop" button I call KillDUD(). Works like a charm. Thanks again.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
PJ Arends wrote:
Actually, it does seem to be working
MSDN[^] says "At the time of the HCBT_CREATEWND notification, the window has been created" so calling GetWindowThreadProcessId returns the correct window handle to the dialup dialog.
Learn something new every day
Glad to be of help
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi, I am doing a project doing image processing using C++. But I dont know how to load image (jpg or bmp) into MFC. And I need to make the image into graylevel image. also I need to get the graylevel of each pixel. Someone introduce me VFW, but I still cannot find out how to load image and get information of it... really need your help... Thanks...
coding, coding, still coding...
|
|
|
|
|
have a look at the cximage library here on cp ... it will do all that and more ... and u can study the source code to see how it does it too
"there is no spoon" biz stuff about me
|
|
|
|
|
Check out the CBitmap class and (H)BITMAP structure on MSDN.
You can use the CBitmap class to determin the RGB color of each pixel.
Hope this helps.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
If you want to make advanced image processing application;
- First use DirectDraw to proceed display images.
- Learn .jpeg, .bmp file format
- Learn .bmp, .jpeg file compression decompression.
ICImageCompress(...) and ICIamgeDecompress(...) defined vfw.h will be helpful
|
|
|
|
|
Hi Again,
I have a low-level mouse hook that I'm using to capture input and then later reproduce it with SendInput.
Here's what I have:
INPUT input;<br />
::ZeroMemory(&input,sizeof(input));<br />
<br />
input.type=INPUT_MOUSE;<br />
input.mi.dx=nX;<br />
input.mi.dy=nY;<br />
input.mi.dwFlags=MOUSEEVENTF_WHEEL|MOUSEEVENTF_ABSOLUTE;<br />
<br />
MSLLHOOKSTRUCT* mHook=(MSLLHOOKSTRUCT*)lParam;
<br />
input.mi.mouseData=(int)(short)HIWORD(mHook->mouseData);
<br />
SendInput(1,&input,sizeof(INPUT));
The message will be sent, however, it has no effect. I've tried input.mi.mouseData=mHook->mouseData, but that will only scroll the mouse up, and msdn clearly indicates that the sign of the high-word indicates the direction. I've also tried multiplying by WHEEL_DELTA, with no effect.
How can I send the correct mouse movement event?
Thanks,
Aaron Stubbendieck
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Dear All,
I want to get the name of all tables of an ODBC datasource selected by user at runtime.
I am using Visual C++ 6.0 with MFC.
Any help regarding retrival of database schema of an ODBC database.
Thanks in advance
|
|
|
|
|
i think it depends on what database you are using. For Oracle is would be
select table_name from user_tables;
or for views
select view_name from user_views;
ODBC may provide a generic way to do this but I dont know
|
|
|
|
|
Hi, I want to know is it possible to make multiple CRecordset derived class in 1 project?? Because I tried to add another CRecordset derived class to my Single Document Project, It couldn't run... Please help.... I need to connect to different Tables seprately not all in one...
Thank YOu
|
|
|
|
|
Why not something like:
CDatabase database;<br />
CString sSql;<br />
<br />
sDriver = GetExcelDriver();<br />
if (sDriver.IsEmpty())<br />
{<br />
AfxMessageBox("No Excel ODBC driver found");<br />
return;<br />
}<br />
<br />
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s", sDriver, m_sFileName);TRY<br />
{<br />
database.Open(NULL, false, false, sDsn);<br />
<br />
CRecordset recset(&database);<br />
<br />
sSql = "SELECT Date, Heure, " + m_sColumn + " FROM [Feuil1$A1:IV65536] WHERE Operateur='SFR'";<br />
<br />
recset.Open(CRecordset::forwardOnly, sSql, CRecordset::readOnly);
while (!recset.IsEOF())<br />
{<br />
recset.GetFieldValue(m_sColumn, sValue);<br />
recset.GetFieldValue("Date", sDate);<br />
recset.GetFieldValue("Heure", sHeure);<br />
<br />
if(-1 != sDate.Find(strDate))<br />
{<br />
int iSpacePos = sHeure.Find(" ");<br />
if(-1 != iSpacePos)<br />
{<br />
sTime = sHeure.Right(sHeure.GetLength() - iSpacePos);<br />
sTime.TrimLeft();<br />
sTime.TrimRight();<br />
<br />
sHour = sTime.Mid(0, 2);<br />
sMinutes = sTime.Mid(3, 2);<br />
sSeconds = sTime.Mid(6, 2);<br />
<br />
CTime tTime(2000, 1, 1, atoi(sHour), atoi(sMinutes), atoi(sSeconds));<br />
m_aTimes.Add(tTime);<br />
}<br />
<br />
m_doubleArray.Add(atof((LPCTSTR)sValue));<br />
}<br />
<br />
recset.MoveNext();<br />
}<br />
database.Close();<br />
<br />
}<br />
CATCH(CDBException, e)<br />
{<br />
AfxMessageBox("Database error: " + e->m_strError);<br />
}<br />
END_CATCH;
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
fba218 wrote:
...is it possible to make multiple CRecordset derived class in 1 project??
Sure it is.
fba218 wrote:
It couldn't run
Meaning what? Did you get a runtime error, assertion, exception?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
This is the code I used to create my own message box in win32.
char *tstr;
BOOL CALLBACK DProc (HWND hDlog, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
SetDlgItemText(hDlog,IDC_TEXTMSG,tstr);
SetWindowPos(hDlog,HWND_BOTTOM,600,500,NULL,NULL,SWP_NOSIZE);
return TRUE;
}
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
DestroyWindow (hDlog);
return TRUE;
}
case WM_DESTROY:
DestroyWindow (hDlog);
return TRUE;
case WM_CLOSE:
DestroyWindow (hDlog);
return TRUE;
default:
return DefWindowProc(hDlog, message, wParam, lParam);
}
return FALSE;
}
int MsgBox(char *textstr, HWND hParDlg)
{
tstr = textstr;
HWND hDg = 0;
HINSTANCE hIn = NULL;
hDg = CreateDialog (hIn,
MAKEINTRESOURCE (IDD_MSGDLG),
hParDlg,
DProc);
if (!hDg)
{
MessageBox (0, "CreateDialog returned NULL", "Warning", MB_ICONEXCLAMATION | MB_OK);
return 1;
}
else
{
ShowWindow(hDg, SW_SHOW);
UpdateWindow(hDg);
}
MSG msg;
int status;
while ((status = GetMessage (& msg, 0, 0, 0)) > 0)
{
if (status == -1)
return -1;
if (!IsDialogMessage (hDg, & msg))
{
TranslateMessage ( & msg );
DispatchMessage ( & msg );
}
}
return 0;
}
I call this function in various places to dispaly my message box. eg. MsgBox("Cannot open the file",hDialog);
It's creating the displaying the message box but after closing the message box the control is not returned to my parent Dlg (hDilaog). What did I missed here?
Plz someone help.
Thanks in advance.
|
|
|
|
|
magee81 wrote:
while ((status = GetMessage (& msg, 0, 0, 0)) > 0)
Try this:
while ((status = GetMessage (& msg, 0, 0, 0)) > 0 && IsWindow(hDg)) Basically, your message loop would only terminate when it received a WM_QUIT, which would terminate your application.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I've created 2 classes with baseclass CDialog. The first class should show the other dialog while working.
I've done it that way:
void CTestDlg::OnTest() <br />
{<br />
UpdateData(TRUE);<br />
CWaitDialog *wd=new CWaitDialog;<br />
<br />
if (!::IsWindow(wd->GetSafeHwnd()))<br />
wd->Create(IDD_DIALOG2, this);<br />
<br />
wd->ShowWindow(SW_SHOW); <br />
<br />
<br />
wd->EndDialog(0);<br />
wd=NULL;<br />
<br />
<br />
UpdateData(FALSE);<br />
delete wd;<br />
}
The second dialog shows up, but I can not move it or it doesn't react on
input. When I show the dialog only without letting the first dialog do his work the second reacts as expected. So my question is how to create modeless windows like the one when copying or saving files? I think of the typical "work in progess" dialogs, showing the effort and let you quit the action.
|
|
|
|
|
you could try doing some message pumping in the "word to do" section. it could be that the modeless dialog is never given a chance to process any windows messages.
Software | Cleek
|
|
|
|
|
It might be the reason. Since I'm not very familiar with that topic, any recommends?
|
|
|
|
|
here's a basic MsgPump function:
<br />
void MsgPump(DWORD dwLen )<br />
{<br />
MSG m_msgCur;
<br />
CWinApp *pWinApp = AfxGetApp(); <br />
<br />
DWORD dInitTime = GetTickCount();<br />
<br />
while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE) &&<br />
(GetTickCount() - dInitTime < dwLen) )<br />
{<br />
pWinApp->PumpMessage();<br />
}<br />
<br />
}<br />
Call this periodically in the code where you do your work. You don't have to call it all the time, just once in a while. The dwLen is the number of ticks to wait. 200 is a good default.
-c
Software | Cleek
|
|
|
|
|
Thank you! It worked perfect. Even when dwLen=1 it is enough to make the second dialog accessable.
|
|
|
|
|
ryuki wrote:
wd->EndDialog(0);
EndDialog() is specific to modal dialog boxes.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Alternatively to the message pump, you can create a worker thread to do your job. There are some excellent articles in CodeProject about it (here for instance)
|
|
|
|
|
Hello, all. I'm trying to have the program I'm writing raise its class and thread priorities on a button click. I can change the thread priorities just fine, but I'm having trouble with the priority class. Here's the code from the function that I'm using to change the priorities:
HANDLE Hand;
BOOL Check;
DWORD Error;
Hand = GetCurrentThread();
Check = SetPriorityClass(Hand, HIGH_PRIORITY_CLASS);
Error = GetLastError();
Check = SetThreadPriority(Hand, THREAD_PRIORITY_HIGHEST);
Error = GetLastError();
Does anybody have any idea why I can change the thread priority but not the priority class?
Thanks,
Phillip
|
|
|
|
|