Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters

Reply
 
Thread Tools

::EnumWindows in MFC
Old 22.05.2004, 09:38   #1
Младенец
 
Join Date: 05 2004
Location: pakistan
Age: 41
Posts: 14
Rep Power: 0
Question ::EnumWindows in MFC

Hi:

I want to use ::EnumWindows() in MFC.
But have a problem in last argument.

I want if i click on a button in dialog box ::EnumWindows() API should call.
I write this code:

void mydialog:nButton1()
{
::EnumWindows((WNDENUMPROC)EnumWindowsProc, LPARAM(this));
}


But i have an error message that this operator should not use in global functions.

So how i gain last argument, what value of last argument (LPARAM) i pass to this function?


Burhan

Old 22.05.2004, 10:13   #2
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 43
Posts: 21,717
Rep Power: 9
Default

Cheat: mydialog * pdialog = this;
::EnumWindows(..., (LPARAM)pdialog);
__________________
http://аvitya.livejournal.com
Хотели, как лучше, а получилось даже хуже...
Лозунг шахматиста: На каждый шах - ответим матом!

Old 22.05.2004, 10:54   #3
Академик
 
greka's Avatar
 
Join Date: 09 2001
Location: inside myself
Posts: 5,369
Rep Power: 6
Default

the second parameter in that "EnumWindows()" shold be pointer to some data structure you're willing to fill in by your callback function, say, misc. parameters ot the window you'll find during window enumeration or smth. else.


PHP Code:
BOOL CALLBACK EnumWindowCallBack(HWND hwndLPARAM lParam

    
FINDWINDOWHANDLESTRUCT pfwhs = (FINDWINDOWHANDLESTRUCT * )lParam
    
DWORD ProcessId
    
CString Title
    
GetWindowThreadProcessId hwnd, &ProcessId ); 

    
// note: In order to make sure we have the MainFrame, verify that the title 
    // has Zero-Length. Under Windows 98, sometimes the Client Window ( which doesn't 
    // have a title ) is enumerated before the MainFrame 

    
CWnd::FromHandlehwnd )->GetWindowText(Title);
    if ( 
ProcessId  == pfwhs->ProcessInfo->dwProcessId && Title.GetLength() != 0
    { 
        
pfwhs->hWndFound hwnd;
        
pfwhs->pid pfwhs->ProcessInfo->dwProcessId;
        return 
false
    } 
    else 
    { 
        
// Keep enumerating 
        
return true
    } 

__________________
И повешенные могут качаться в неположенную сторону. /С.Е.Лец/

another Error
Old 23.05.2004, 09:02   #4
Младенец
 
Join Date: 05 2004
Location: pakistan
Age: 41
Posts: 14
Rep Power: 0
Default another Error

Quote:
Originally Posted by Agregat
Cheat: mydialog * pdialog = this;
::EnumWindows(..., (LPARAM)pdialog);
I use this:
mydialog * pdialog = this;
::EnumWindows(..., (LPARAM)pdialog);

But have an error:

error C2440: 'type cast' : cannot convert from '' to 'int (__stdcall *)(struct HWND__ *,long)'
None of the functions with this name in scope match the target type


Any Idea?
Burhan

Siir i dont want this.
Old 23.05.2004, 09:03   #5
Младенец
 
Join Date: 05 2004
Location: pakistan
Age: 41
Posts: 14
Rep Power: 0
Default Siir i dont want this.

Quote:
Originally Posted by greka
the second parameter in that "EnumWindows()" shold be pointer to some data structure you're willing to fill in by your callback function, say, misc. parameters ot the window you'll find during window enumeration or smth. else.


PHP Code:
BOOL CALLBACK EnumWindowCallBack(HWND hwndLPARAM lParam

    
FINDWINDOWHANDLESTRUCT pfwhs = (FINDWINDOWHANDLESTRUCT * )lParam
    
DWORD ProcessId
    
CString Title
    
GetWindowThreadProcessId hwnd, &ProcessId ); 

    
// note: In order to make sure we have the MainFrame, verify that the title 
    // has Zero-Length. Under Windows 98, sometimes the Client Window ( which doesn't 
    // have a title ) is enumerated before the MainFrame 

    
CWnd::FromHandlehwnd )->GetWindowText(Title);
    if ( 
ProcessId  == pfwhs->ProcessInfo->dwProcessId && Title.GetLength() != 0
    { 
        
pfwhs->hWndFound hwnd;
        
pfwhs->pid pfwhs->ProcessInfo->dwProcessId;
        return 
false
    } 
    else 
    { 
        
// Keep enumerating 
        
return true
    } 


Sir i dont want to fill 2nd parameter lparam in callback function.
I want to know how i call ::EnumWindow() in MFC dialog application.
I try to call this function through a button, but i dont know what i pass to 2nd argument (LPARAM) of this function?

If u have sample project of this then plz send me.

Burhan

Old 23.05.2004, 11:12   #6
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 43
Posts: 21,717
Rep Power: 9
Default

Teh problem is in the first param. As you can deduce from error message.
__________________
http://аvitya.livejournal.com
Хотели, как лучше, а получилось даже хуже...
Лозунг шахматиста: На каждый шах - ответим матом!

Old 25.05.2004, 14:05   #7
Академик
 
greka's Avatar
 
Join Date: 09 2001
Location: inside myself
Posts: 5,369
Rep Power: 6
Default

I've already past-ed the sample function to you.

Could you tell me why're you passing "this" ?
If you don't need it then pass NULL as a second param.

The error appears because your "EnumWindowsProc()" does not appropriate to the expected one.
The prototype I've already shown to you, will repeat below:

PHP Code:
BOOL CALLBACK EnumWindowCallBack(HWND hwndLPARAM lParam
__________________
И повешенные могут качаться в неположенную сторону. /С.Е.Лец/
Reply




Реклама:
реклама
Buy text link .

All times are GMT. The time now is 04:25.
Top

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.