finding hInstance

This is a discussion on finding hInstance within the Windows Programming forums, part of the Platform Specific Boards category; ok here I go. PHP Code: BOOL GetClassInfo (             HINSTANCE hInstance ,             LPCTSTR lpClassName ,             LPWNDCLASS lpWndClass            );  This is ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    21

    finding hInstance

    ok here I go.


    PHP Code:
    BOOL GetClassInfo
              
    HINSTANCE hInstance
              
    LPCTSTR lpClassName
              
    LPWNDCLASS lpWndClass
              
    ); 
    This is the function i want to use.
    What i want to do is use GetClassInfo();, inside a loop, to check the caption of all the windows.
    Then when i find the window with what i'm looking for (i.e. " - WinProxy")
    or when i don't find it... take action.
    My Question is, how do i get the hInstance of all the different windows?

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    An easier to use but dangerous function is FindWindow, search the windows board for it, it has been discuessed plenty of times, so im sure you will find something that will help you.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Don't forget:

    Code:
    typedef struct _WNDCLASS {    // wc 
        UINT    style; 
        WNDPROC lpfnWndProc; 
        int     cbClsExtra; 
        int     cbWndExtra; 
        HANDLE  hInstance; 
        HICON   hIcon; 
        HCURSOR hCursor; 
        HBRUSH  hbrBackground; 
        LPCTSTR lpszMenuName; 
        LPCTSTR lpszClassName; 
    } WNDCLASS;
    You can just use the hInstance member of the WNDCLASS structure.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789


    Far easier - GetModuleHandle(NULL)...the return is a HMODULE, but they are the same as HINSTANCE under Win32

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    21
    How do I find lpClassName?
    And does it stay the same after I shut down the program and re-open it?

    I've gotten it to work.
    Code:
    	HWND hMainWnd = FindWindow(NULL," - WinProxy");
    	if(hMainWnd == NULL){
    		printf("Process not found\n");
    	}else{
    		printf("process found\n");
    	}
    An easier to use but dangerous function is FindWindow, search
    How is this function dangerous?

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Sorry...I misread your question.....

    IF you want to cycle through the windows to find a specific window, then the best and most efficent option IMO is EnumWindows

    Code:
    #include <iostream>
    #include <iomanip>
    #include <cstring>
    #include <windows.h>
    
    using std::cout;
    using std::endl;
    using std::hex;
    
    BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam){
    
    	const int nSize = 100;
    	char szBuff[nSize] = {0};
    	char* str = (char*)lParam;
    
    	if(GetWindowText(hwnd,szBuff,nSize)){
    		if(!strcmp(str,szBuff)){
    			cout << hex;
    			cout << "Found the window called " << str;
    			cout << " on HWND number " << hwnd << endl;
    			return FALSE;
    		}
    	}
    
    	return TRUE;
    }
    
    
    int main(){
    
    	char *szWinName = "Calculator";
    
    	EnumWindows(EnumWindowsProc,(LPARAM)szWinName);
    
    	return 0;
    
    }
    This searches for the calculator program that comes with windows, but just change it as you wish for the window you need

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>How do I find lpClassName?<<

    GetClassName

    You can use it within the enumeration technique provided by Fordy with the hwnd parameter passed to the EnumWindowsProc.

    Alternatively, store the class name of interest in a variable of suitable scope.

    eg of GetClassName use:
    Code:
    TCHAR chClassName[256];
    int nSuccesIsNumCharsCopied = GetClassName(hwnd,chClassName,256);
    if (nSuccessIsNumCharsCopied == 0)
      {
      //error - use GetLastError to get more info
      }
    Last edited by Ken Fitlike; 10-08-2002 at 04:33 PM.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    FYI: The HINSTANCE passed to GetClassInfo should be NULL for native types (buttons, edits, etc...)
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ - Win32 - Finding out selected treeview item
    By The Architect in forum Windows Programming
    Replies: 2
    Last Post: 11-01-2007, 06:14 AM
  2. Really Need Help With My Opengl Camera!!!!
    By psychopath in forum Game Programming
    Replies: 13
    Last Post: 05-28-2004, 03:05 PM
  3. MFC :: Finding Child Window of a CWnd* Object?
    By SyntaxBubble in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2003, 09:06 AM
  4. Global HINSTANCE?
    By confuted in forum Windows Programming
    Replies: 6
    Last Post: 06-24-2003, 02:13 AM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 06:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21