mIRC Home    About    Download    Register    News    Help

Print Thread
#227664 17/11/10 08:42 PM
Joined: Dec 2002
Posts: 251
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 251
I never could figure out how to individually make windows desktop windows like queries or channels with a command, /window -d #chan doesn't work and I've asked before and most people just state alt+o > Display > Options > click on "windows..." button or right click a window and click the Desktop option in the treebar/switchbar. Either way, i wrote a very simple dll to access the win32 API called SetParent which allowed me to use $window(whatever).hwnd and send it to $window(-1).hwnd and boom, its a desktop window. This worked great up until the 7.x series. on mIRC 6.35 the window works fine if it was forced to a new parent, on 7.x series even tho it is now a desktop window i can't use it at all. not sure if this really is a bug or what not, probably should be a feature suggestion but we all know how long it takes for those to get implemented smile

Joined: Dec 2002
Posts: 251
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 251
dll code dll.h:

Code:
#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */


class DLLIMPORT DllClass
{
  public:
    DllClass();
    virtual ~DllClass(void);

  private:

};


#endif /* _DLL_H_ */

typedef struct
{
 DWORD mVersion;
 HWND mHwnd;
 BOOL mKeep;
} LOADINFO;


the .cpp file
Code:
#include <windows.h>
#include "dll.h"

DllClass::DllClass()
{

}


DllClass::~DllClass ()
{

}


BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                       DWORD reason        /* Reason this function is being called. */ ,
                       LPVOID reserved     /* Not used. */ )
{
    switch (reason)
    {
      case DLL_PROCESS_ATTACH:
        break;

      case DLL_PROCESS_DETACH:
        break;

      case DLL_THREAD_ATTACH:
        break;

      case DLL_THREAD_DETACH:
        break;
    }

    /* Returns TRUE on success, FALSE on failure */
    return TRUE;
}

//Define mIRC Variables
HWND mIRC_hwnd;
LPSTR mData;
HANDLE hFileMap;

// Token stuff
char* gettok(char *data, int pos, char *C, int all)
{
    char*  Token;
    int    i;
    char data2[1024];
    lstrcpy(data2,data);
    Token = strtok(data2,C);
    for (i = 1; Token && (i < pos); i++) {

      if (i == (pos-1) && all) return strtok(NULL,"");
      else Token = strtok(NULL,C);
    }
    if (all) return strtok(data,"");
    //if (!Token)
    //  lstrcpy(Token,"\0");
    return Token;
}

int numtok(char *data, char *C)
{
    char* Token;
    char data2[1024];
    int i = 0;
    lstrcpy(data2,data);
    Token = strtok(data2,C);
    while (Token) {
      Token = strtok(NULL,C);
      i++;
    }
    return i;
}

//Define Function for mIRC to call
extern "C" __declspec(dllexport) void __stdcall LoadDll(LOADINFO *);
extern "C" __declspec(dllexport) int __stdcall UnloadDll(int);
extern "C" __declspec(dllexport) int __stdcall SetWParent(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause);

//Define The Functions
void __stdcall LoadDll(LOADINFO *li)
{
 hFileMap = CreateFileMapping(INVALID_HANDLE_VALUE,0,PAGE_READWRITE,0,4096,"mIRC");     
 mData = (LPSTR)MapViewOfFile(hFileMap,FILE_MAP_ALL_ACCESS,0,0,0);
 mIRC_hwnd = li->mHwnd;
 li->mKeep = FALSE;
}

int __stdcall UnloadDll(int mTimeout)
{
	if (!mTimeout) 
	{ 
      UnmapViewOfFile(mData);
      CloseHandle(hFileMap);
      return 1; 
	}
    return 0;
}

int __stdcall SetWParent(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)
{
 HWND child = (HWND)atoi(gettok(data,1," ",0));
 HWND owner = (HWND)atoi(gettok(data,2," ",0));

 if ((IsWindow(child)) && (IsWindow(owner))) { SetParent(child,owner); }
 return 1;
}


like previously stated, works great on the non-unicode versions of mIRC. gives me the ability to individually make windows desktop or not without having to mark types as automatic desktop windows.

Joined: Jul 2006
Posts: 4,020
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,020
Remove the WS_CHILD style of the window after using setParent and you're good, tried on 7.1.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 251
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 251
so what something like

Code:
long styles;
styles = GetWindowLong(child,GWL_STYLE);
styles &= ~WS_CHILD;
SetWindowLong(child,GWL_STYLE,styles);


I'll give it a shot but theres no garuntee I always use setparent to make a window a desktop window.

Joined: Dec 2002
Posts: 251
T
Talon Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 251
HAH that worked! thanks Wims, but it still is bizarre, my Channel window has no controls, no minimize/maximize/close/etc.. its just got a caption bar.



EDIT: actually i figured it out, i set parent to the desktop when it was maximized, if its not maximized, when i send it to the desktop the controls are there, minimizing/maximizing any window brings the controls back to the window also if they aren't there.

Last edited by Talon; 18/11/10 12:46 AM.
Joined: Jul 2006
Posts: 4,020
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,020
I can't reproduce that, whatever the window state is before using setParent, I don't lose the buttons on the title/caption bar, I'm on window xp, did you try using the dll instead of your ?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 3,840
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 3,840
Unfortunately using SetParent() results in a number of side-effects, so I would not recommend it. mIRC never uses SetParent() and instead recreates the entire window whenever you move it between mIRC and the desktop.


Link Copied to Clipboard