Armenian Knowledge Base  

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

Reply
 
LinkBack Thread Tools
Old 22.05.2004, 10:38   #1
Младенец
 
Join Date: 05 2004
Location: pakistan
Age: 33
Posts: 14
Downloads: 0
Uploads: 0
Reputation: 0 | 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
Reply With Quote
Old 22.05.2004, 11:13   #2
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 35
Posts: 21,717
Downloads: 2
Uploads: 0
Reputation: 250 | 7
Default

Cheat: mydialog * pdialog = this;
::EnumWindows(..., (LPARAM)pdialog);
Reply With Quote
Old 22.05.2004, 11:54   #3
Академик
 
greka's Avatar
 
Join Date: 09 2001
Location: inside myself
Posts: 5,369
Downloads: 0
Uploads: 0
Reputation: 18 | 5
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
    } 

Reply With Quote
Old 23.05.2004, 10:02   #4
Младенец
 
Join Date: 05 2004
Location: pakistan
Age: 33
Posts: 14
Downloads: 0
Uploads: 0
Reputation: 0 | 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
Reply With Quote
Old 23.05.2004, 10:03   #5
Младенец
 
Join Date: 05 2004
Location: pakistan
Age: 33
Posts: 14
Downloads: 0
Uploads: 0
Reputation: 0 | 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
Reply With Quote
Old 23.05.2004, 12:12   #6
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 35
Posts: 21,717
Downloads: 2
Uploads: 0
Reputation: 250 | 7
Default

Teh problem is in the first param. As you can deduce from error message.
Reply With Quote
Old 25.05.2004, 15:05   #7
Академик
 
greka's Avatar
 
Join Date: 09 2001
Location: inside myself
Posts: 5,369
Downloads: 0
Uploads: 0
Reputation: 18 | 5
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 With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 16:54.


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