14 #include "openwidedll.h"
15 #include "openwideres.h"
17 #include "owSharedUtil.h"
19 int dlgUnits2Pix(HWND hwnd
, int units
, BOOL bHorz
)
22 SetRect(&r
, 0,0,units
,units
);
23 MapDialogRect(hwnd
, &r
);
24 return (bHorz
) ? r
.right
: r
.bottom
;
27 int pix2DlgUnits(HWND hwnd
, int pix
, BOOL bHorz
)
30 SetRect(&r
, 0,0,10,10);
31 MapDialogRect(hwnd
, &r
);
32 return (bHorz
) ? (pix
/ r
.right
) : (pix
/ r
.bottom
);
36 * Function source : C:\Code\lcc\Proto\util.c */
37 void Error(char *szError
, ...)
41 va_start(vl
, szError
);
42 _vsnprintf(szBuff
, 256, szError
, vl
); // print error message to string
43 OutputDebugString(szBuff
);
44 MessageBox(NULL
, szBuff
, "Error", MB_OK
); // show message
49 UINT APIENTRY
OFNHookProcOldStyle(
50 HWND hdlg
, // handle to the dialog box window
51 UINT uiMsg
, // message identifier
52 WPARAM wParam
, // message parameter
53 LPARAM lParam
// message parameter
62 char *Prompt_File_Name(int iFlags
, HWND hwOwner
, const char *pszFilter
, const char *pszTitle
)
64 static char szFileName
[MAX_PATH
]; // store selected file
65 char szDefFilter
[] = "All Files\0*.*\0\0"; // default filter
68 ZeroMemory(&ofn
, sizeof(ofn
));
69 ofn
.lStructSize
= sizeof(ofn
);
71 szFileName
[0] = 0; // mark the file name buffer as empty;
73 ofn
.hwndOwner
= hwOwner
;
74 // If a filter is supplied, use it. Otherwise, use default.
75 ofn
.lpstrFilter
= (pszFilter
) ? pszFilter
: szDefFilter
;
76 ofn
.lpstrFile
= szFileName
; // where to store filename
77 ofn
.nMaxFile
= MAX_PATH
; // length of filename buffer
78 ofn
.lpstrTitle
= pszTitle
; // title if supplied
82 ofn
.Flags
= OFN_EXPLORER
// use new features
83 | OFN_CREATEPROMPT
// create files if user wishes
85 | OFN_PATHMUSTEXIST
// what it says
86 | OFN_HIDEREADONLY
; // hide the read-only option
90 for(i
=0; pszFilter
[i
]!=0; i
++)
93 char *sp
= strchr(&pszFilter
[i
], '.');
94 if(sp
) ofn
.lpstrDefExt
= sp
+1;
96 if(!GetSaveFileName(&ofn
))
102 // ofn.lpfnHook = OFNHookProcOldStyle;
103 // ofn.Flags = OFN_ENABLEHOOK;
104 ofn
.Flags
= OFN_EXPLORER
// use new features
105 | OFN_FILEMUSTEXIST
// file names must be valid
106 | OFN_PATHMUSTEXIST
// and paths too.
107 | OFN_HIDEREADONLY
; // hide the read-only option
108 // dbg("Address of OFN data is %p, structsize is %lu", &ofn, ofn.lStructSize);
109 if(!GetOpenFileName(&ofn
))
114 while (PeekMessage(&msg, hwOwner, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE));*/
120 TCHAR
*lbGetItemText(HWND hwLB
, int iItem
)
122 TCHAR
*szText
= NULL
;
124 len
= SendMessage(hwLB
, LB_GETTEXTLEN
, iItem
, 0) + 1;
127 szText
= malloc(len
+1 * sizeof(char));
128 if(!szText
) return NULL
;
129 len
= SendMessage(hwLB
, LB_GETTEXT
, iItem
, (LPARAM
)szText
);
136 static int AddRem_TrayIcon(HICON hIcon
, char *szTip
, HWND hwnd
, UINT uMsg
, DWORD dwState
, DWORD dwMode
){
140 memset(&nid
, 0, sizeof(NOTIFYICONDATA
));
141 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
143 nid
.uFlags
= NIF_MESSAGE
| (hIcon
? NIF_ICON
: 0) | (szTip
? NIF_TIP
: 0);
145 nid
.uCallbackMessage
= uMsg
;
149 strncpy(nid
.szTip
, szTip
, 63);
153 //nid.dwState = dwState;
154 return (Shell_NotifyIcon(dwMode
, &nid
) != 0);
159 int Add_TrayIcon(HICON hIcon
, char *szTip
, HWND hwnd
, UINT uMsg
, DWORD dwState
){
160 return AddRem_TrayIcon(hIcon
, szTip
, hwnd
, uMsg
, dwState
, NIM_ADD
);
164 void EndTrayOperation(void)
166 NOTIFYICONDATA nid
= {0};
167 nid
.cbSize
= sizeof(NOTIFYICONDATA
);
168 Shell_NotifyIcon(NIM_SETFOCUS
, &nid
);
172 int Rem_TrayIcon(HWND hwnd
, UINT uMsg
, DWORD dwState
){
173 return AddRem_TrayIcon(NULL
, NULL
, hwnd
, uMsg
, dwState
, NIM_DELETE
);
177 BOOL
delFile(HWND hwnd
, const char *szFile
)
179 SHFILEOPSTRUCT shlOp
= {0};
181 shlOp
.wFunc
= FO_DELETE
;
182 shlOp
.pFrom
= szFile
;
183 shlOp
.fFlags
= FOF_ALLOWUNDO
| FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
| FOF_NO_CONNECTED_ELEMENTS
| FOF_NORECURSION
;
184 return (SHFileOperation(&shlOp
) == S_OK
);
191 BOOL
fileExists (const char *path
)
195 if (GetFileAttributes (path
) == 0xFFFFFFFF)
197 errCode
= GetLastError ();
198 if (errCode
== ERROR_FILE_NOT_FOUND
199 || errCode
== ERROR_PATH_NOT_FOUND
)
201 //dbg ("fileExists? getLastError gives %d", errCode);
206 // CreateLink - uses the Shell's IShellLink and IPersistFile interfaces
207 // to create and store a shortcut to the specified object.
209 // Returns the result of calling the member functions of the interfaces.
212 // lpszPathObj - address of a buffer containing the path of the object.
213 // lpszPathLink - address of a buffer containing the path where the
214 // Shell link is to be stored.
215 // lpszDesc - address of a buffer containing the description of the
218 HRESULT
CreateLink(LPCSTR lpszPathObj
, LPCSTR lpszPathLink
, LPCSTR lpszDesc
)
223 // Get a pointer to the IShellLink interface.
224 hres
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
225 &IID_IShellLink
, (LPVOID
*)&psl
);
230 // Set the path to the shortcut target and add the description.
231 psl
->lpVtbl
->SetPath(psl
, lpszPathObj
);
232 psl
->lpVtbl
->SetDescription(psl
, lpszDesc
);
234 // Query IShellLink for the IPersistFile interface for saving the
235 // shortcut in persistent storage.
236 hres
= psl
->lpVtbl
->QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
242 // Ensure that the string is Unicode.
243 MultiByteToWideChar(CP_ACP
, 0, lpszPathLink
, -1, wsz
, MAX_PATH
);
245 // TODO: Check return value from MultiByteWideChar to ensure success.
246 // Save the link by calling IPersistFile::Save.
247 hres
= ppf
->lpVtbl
->Save(ppf
, wsz
, TRUE
);
248 ppf
->lpVtbl
->Release(ppf
);
250 psl
->lpVtbl
->Release(psl
);
255 int cbAddString(HWND hwCB
, const char *szStr
, LPARAM lpData
)
257 int idx
= SendMessage(hwCB
, CB_ADDSTRING
, 0, (LPARAM
)szStr
);
260 int res
= SendMessage(hwCB
, CB_SETITEMDATA
, idx
, lpData
);
263 SendMessage(hwCB
, CB_DELETESTRING
, idx
, 0);
270 int getDlgItemRect(HWND hwnd
, UINT uID
, LPRECT pr
)
272 if(!IsWindow(hwnd
) || !pr
)
274 HWND hwCtl
= GetDlgItem(hwnd
, uID
);
277 if(!GetWindowRect(hwCtl
, pr
))
279 MapWindowPoints(NULL
, hwnd
, (LPPOINT
)&pr
->left
, 2);
285 BOOL
waitForMutex(void)
290 ghMutex
= OpenMutex(SYNCHRONIZE
, FALSE
, OW_MUTEX_NAME
);
294 dwRes
= WaitForSingleObject(ghMutex
, INFINITE
);
302 //dbg("Mutex wait failed");
309 void releaseMutex(void)
313 ReleaseMutex(ghMutex
);