home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
desk.zip
/
DESKTOP.C
next >
Wrap
Text File
|
1994-01-10
|
12KB
|
265 lines
/****************************************************************************/
/* Sends messages to Desktop - OS/2 2.x */
/* Instructions: Find the modifiable section to add desktop popup */
/* menu items and follow the comments. */
/* Author: Brian McManamon CIS - 73243,166 */
/* To compile this program using IBM CSET/2 - icc /B"/pmtype:pm" desktop.c */
/* Warning: This program is provided as is. It has hung my desktop in */
/* some cases becauses some messages have been lost. This is a temporary */
/* solution for a specific problem until the WPS development team publishes */
/* a supported solution. */
/**** Make sure all program names are present and can be found in the ****/
/**** path before running this program or your desktop will hang. ****/
/****************************************************************************/
#define INCL_WIN
#include <os2.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define OS2_DESKTOP "Desktop"
#define MENU_ITEM_SETTINGS "Menu Item Settings"
#define FIELD2 0x0245 /* Id of program name entry field */
#define IDM_LOCKUP 0x02C1 /* This id can be used to lock the Desktop */
#define IDM_OPEN_SETTINGS 0x0070 /* Id to open the settings notebook */
#define IDM_CREATE 0x023D /* Id of create pushbutton on menu page */
#define IDM_OK 0x00B9 /* Id of OK pushbutton in create dialog */
#define SORT 0x138B /* Id of sort checkbox on sort page */
#define QUERYPAGEID(Itemid1, Itemid2) \
WinSendMsg(Itemid1, BKM_QUERYPAGEID, (MPARAM)Itemid2, \
MPFROM2SHORT(BKA_PREV, BKA_MAJOR))
#define array_size sizeof(menu) / (sizeof(menu[0][0]) + sizeof(menu[0][1]))
/****************************************************************************/
/* Modifiable section */
/* The following array defines the menu names and their */
/* corresponding program names as they would appear in the desktop popup */
/* menu. You can add or edit this array for your own items. */
/****************************************************************************/
char menu[][2][30]={
"OS/2 ~Window", "CMD.EXE"
/****************************************************************************/
/* End modifiable section */
/****************************************************************************/
};
/***************************************************************************/
/* */
/* FUNCTION CreateMenuItem: */
/* DESCRIPTION: */
/* Creates Menu Items on the Desktop Popup menu */
/* */
/***************************************************************************/
void CreateMenuItem
(
PSZ pszItem1,
PSZ pszItem2,
HWND hwndmenu,
HWND hwndmenupage
)
{
HWND hwndentry1,
hwndentry2;
/****************************************************************************/
/* Send a message to access the Menu Item Settings dialog */
/****************************************************************************/
WinSendMsg (hwndmenupage, WM_COMMAND,
MPFROMSHORT(IDM_CREATE),
MPFROM2SHORT (CMDSRC_PUSHBUTTON, TRUE));
/****************************************************************************/
/* Retrieve the handle to the description entry field and set its text */
/****************************************************************************/
hwndentry1 = WinQueryFocus(HWND_DESKTOP);
WinSetWindowText(hwndentry1, pszItem1);
/****************************************************************************/
/* Retrieve the handle to the Menu Item Settings dialog and use it to */
/* retrieve the handle to the second entry field, then set its text */
/****************************************************************************/
hwndmenu = WinQueryWindow(hwndentry1, QW_PARENT);
hwndentry2 = WinWindowFromID(hwndmenu, FIELD2);
WinSetFocus(HWND_DESKTOP, hwndentry2);
WinSetWindowText(hwndentry2, pszItem2);
/****************************************************************************/
/* Send a message to close the dialog */
/****************************************************************************/
WinSendMsg (hwndmenu, WM_COMMAND,
MPFROMSHORT(IDM_OK),
MPFROM2SHORT (CMDSRC_PUSHBUTTON, TRUE));
return;
}
/***************************************************************************/
/* */
/* FUNCTION SortCheck: */
/* DESCRIPTION: */
/* Checks the sort menu items checkbox on the sort page */
/* */
/***************************************************************************/
HWND SortCheck
(
HWND hwndNotebookFrame,
HWND hwndNotebookClient,
ULONG sort_page
)
{
HWND hwndsortpage,
hwndsortcheck;
BOOL fsuccess;
/****************************************************************************/
/* Turn to Sort page in the notebook and retrieve its window handle */
/****************************************************************************/
fsuccess = (ULONG)WinSendMsg(hwndNotebookClient,
BKM_TURNTOPAGE,
MPFROMLONG(sort_page),
MPVOID);
hwndsortpage = (ULONG)WinSendMsg(hwndNotebookFrame,
BKM_QUERYPAGEWINDOWHWND,
(MPARAM)sort_page,
MPVOID);
/****************************************************************************/
/* Get the checkbox window handle and set its state to on */
/****************************************************************************/
hwndsortcheck = WinWindowFromID(hwndsortpage, SORT);
WinSendMsg (hwndsortcheck, BM_SETCHECK, MPFROMSHORT(1), MPVOID);
WinSendMsg (hwndsortpage,
WM_CONTROL,
MPFROM2SHORT(SORT, BN_CLICKED),
MPFROMLONG(hwndsortcheck));
return hwndsortpage;
}
/***************************************************************************/
/* */
/* Main Procedure */
/* */
/***************************************************************************/
int main
(
int argc,
char *argv[]
)
{
HAB hab;
HMQ hmq;
HENUM henum;
HWND hwndDesktopFrame;
HWND hwndNotebookFrame;
HWND hwndNotebookClient;
HWND hwndmenupage;
HWND hwndmenu;
HWND hwndsortpage;
ULONG lockup_page;
ULONG general_page;
ULONG window_page;
ULONG file_page;
ULONG menu_page;
ULONG background_page;
ULONG sort_page;
BOOL fsuccess;
APIRET rc;
INT i;
static CHAR szBuffer[128];
static CHAR *pszDesktop = OS2_DESKTOP;
static CHAR *pszMenu = MENU_ITEM_SETTINGS;
hab = WinInitialize (0);
hmq = WinCreateMsgQueue (hab, 0);
/****************************************************************************/
/* Get window handle of Workplace Shell Desktop Frame */
/****************************************************************************/
henum = WinBeginEnumWindows (HWND_DESKTOP);
hwndDesktopFrame = WinGetNextWindow (henum);
while (hwndDesktopFrame)
{
WinQueryWindowText (hwndDesktopFrame, sizeof szBuffer, szBuffer);
if (strcmp (szBuffer, pszDesktop) == 0)
break;
hwndDesktopFrame = WinGetNextWindow (henum);
}
WinEndEnumWindows (henum);
/****************************************************************************/
/* Send a message to Desktop Frame Window to Open Settings */
/****************************************************************************/
WinSendMsg (hwndDesktopFrame, WM_COMMAND, MPFROMSHORT(IDM_OPEN_SETTINGS),
MPFROM2SHORT (CMDSRC_MENU, TRUE));
/****************************************************************************/
/* Get window handle of Desktop Settings Notebook Frame Window */
/****************************************************************************/
henum = WinBeginEnumWindows (HWND_DESKTOP);
hwndNotebookFrame = WinGetNextWindow (henum);
while (hwndNotebookFrame)
{
WinQueryWindowText (hwndNotebookFrame, sizeof szBuffer, szBuffer);
if (strcmp (szBuffer, pszDesktop) == 0)
break;
hwndNotebookFrame = WinGetNextWindow (henum);
}
WinEndEnumWindows (henum);
/****************************************************************************/
/* Get window handles and pageids of Settings notebook */
/****************************************************************************/
hwndNotebookClient = WinQueryWindow(hwndNotebookFrame, QW_TOP);
lockup_page = (ULONG)WinSendMsg(hwndNotebookClient,
BKM_QUERYPAGEID,
MPVOID,
MPFROM2SHORT(BKA_LAST, BKA_MAJOR));
general_page = (ULONG)QUERYPAGEID(hwndNotebookClient, lockup_page);
window_page = (ULONG)QUERYPAGEID(hwndNotebookClient, general_page);
file_page = (ULONG)QUERYPAGEID(hwndNotebookClient, window_page);
menu_page = (ULONG)QUERYPAGEID(hwndNotebookClient, file_page);
background_page = (ULONG)QUERYPAGEID(hwndNotebookClient, menu_page);
sort_page = (ULONG)QUERYPAGEID(hwndNotebookClient, background_page);
/****************************************************************************/
/* Turn to Menu page in the notebook and retrieve its window handle */
/****************************************************************************/
fsuccess = (ULONG)WinSendMsg(hwndNotebookClient,
BKM_TURNTOPAGE,
MPFROMLONG(menu_page),
MPVOID);
hwndmenupage = (ULONG)WinSendMsg(hwndNotebookFrame,
BKM_QUERYPAGEWINDOWHWND,
(MPARAM)menu_page,
MPVOID);
/****************************************************************************/
/* Call the CreateMenuItem function to create the separate menu items */
/****************************************************************************/
for (i=0; i<array_size; i++)
CreateMenuItem(menu[i][0], menu[i][1], hwndmenu, hwndmenupage);
/****************************************************************************/
/* Call the SortCheck function to set the checkbox state on */
/****************************************************************************/
hwndsortpage = SortCheck(hwndNotebookFrame, hwndNotebookClient, sort_page);
/****************************************************************************/
/* Close the Settings notebook and terminate the process */
/****************************************************************************/
WinPostMsg (hwndNotebookFrame, WM_CLOSE, MPVOID, MPVOID);
WinDestroyMsgQueue (hmq);
WinTerminate (hab);
return 0;
}