--- mstools/samples/ole/srvrdemo/srvrdemo.c 2018/08/09 18:20:49 1.1 +++ mstools/samples/ole/srvrdemo/srvrdemo.c 2018/08/09 18:23:58 1.1.1.3 @@ -17,7 +17,13 @@ /* Global variable definitions */ -HWND hwndMain = NULL; +HWND hwndMain = 0; + +// Used in converting units from pixels to Himetric and vice-versa +int giXppli = 0; // pixels per logical inch along width +int giYppli = 0; // pixels per logical inch along height + + // Since this is a not an MDI app, there can be only one server and one doc. SRVR srvrMain; @@ -109,9 +115,9 @@ static BOOL FailedUpdate(HWND); * CUSTOMIZATION: None * */ -int WinMain( - HANDLE hInstance, - HANDLE hPrevInstance, +int APIENTRY WinMain( + HINSTANCE hInstance, + HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow ){ @@ -143,13 +149,14 @@ int WinMain( BOOL fMoreMsgs = TRUE; while (fMoreMsgs) { + if (srvrMain.lhsrvr == 0) OleUnblockServer (srvrMain.lhsrvr, &fMoreMsgs); } // We have taken care of all the messages in the OLE queue fUnblock = FALSE; } - if (!GetMessage(&msg, NULL, NULL, NULL)) + if (!GetMessage(&msg, NULL, 0, 0)) break; if( !TranslateAccelerator(hwndMain, hAccelTable, &msg)) { @@ -186,7 +193,7 @@ static BOOL InitApplication( HANDLE hIns wc.lpszClassName = "MainClass"; wc.lpfnWndProc = (WNDPROC)MainWndProc; - wc.style = NULL; + wc.style = 0; wc.cbClsExtra = 4; wc.cbWndExtra = 0; wc.hInstance = hInstance; @@ -243,6 +250,7 @@ static BOOL InitInstance (HANDLE hInstan INT iColor; + HDC hDC ; hInst = hInstance; @@ -278,11 +286,17 @@ static BOOL InitInstance (HANDLE hInstan if (!hwndMain) return FALSE; - szClient[0] = NULL; + szClient[0] = '\0'; lstrcpy (szClientDoc, "Client Document"); // Initialize global variables with LOGPIXELSX and LOGPIXELSY + hDC = GetDC (NULL); // Get the hDC of the desktop window + giXppli = GetDeviceCaps (hDC, LOGPIXELSX); + giYppli = GetDeviceCaps (hDC, LOGPIXELSY); + ReleaseDC (NULL, hDC); + + return TRUE; } @@ -361,7 +375,7 @@ static BOOL ExitApplication (BOOL fUpdat * */ LONG APIENTRY MainWndProc - (HWND hwnd, UINT message, DWORD wParam, LONG lParam ) + (HWND hwnd, UINT message, WPARAM wParam, LONG lParam ) { LPOBJ lpobj; @@ -374,7 +388,7 @@ LONG APIENTRY MainWndProc if (fWaitingForDocRelease) { ErrorBox ("Waiting for a document to be revoked.\n\rPlease wait."); - return NULL; + return 0; } switch (wID) @@ -384,7 +398,7 @@ LONG APIENTRY MainWndProc break; case IDM_ABOUT: - DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About); + DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About); break; case IDM_NEW: @@ -411,7 +425,7 @@ LONG APIENTRY MainWndProc fRevokeSrvrOnSrvrRelease = TRUE; - if (!CreateNewDoc (NULL, "(Untitled)", doctypeNew)) + if (!CreateNewDoc (0, "(Untitled)", doctypeNew)) { ErrorBox ("Serious Error: Cannot create new document."); break; @@ -550,7 +564,7 @@ LONG APIENTRY MainWndProc default: return DefWindowProc(hwnd, message, wParam, lParam); } - return NULL; + return 0; } @@ -563,7 +577,7 @@ LONG APIENTRY MainWndProc * CUSTOMIZATION: None * */ -BOOL APIENTRY About (HWND hDlg, UINT message, DWORD wParam, LONG lParam) +BOOL APIENTRY About (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { @@ -598,7 +612,7 @@ BOOL APIENTRY About (HWND hDlg, UINT me * */ LONG APIENTRY ObjWndProc - (HWND hwnd, UINT message, DWORD wParam, LONG lParam) + (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static BOOL fCapture = FALSE; static struct {RECT rect; POINT pt;} drag; @@ -626,7 +640,7 @@ LONG APIENTRY ObjWndProc if (fWaitingForDocRelease) { ErrorBox ("Waiting for a document to be revoked.\n\rPlease wait."); - return NULL; + return 0; } // Get coordinates of object relative to main window's client area. GetWindowRect (hwnd, (LPRECT)&rect); @@ -643,7 +657,7 @@ LONG APIENTRY ObjWndProc if (fWaitingForDocRelease) { ErrorBox ("Waiting for a document to be revoked.\n\rPlease wait."); - return NULL; + return 0; } BringWindowToTop (hwnd); @@ -728,7 +742,7 @@ LONG APIENTRY ObjWndProc default: return DefWindowProc(hwnd, message, wParam, lParam); } - return NULL; + return 0; } @@ -745,17 +759,10 @@ LONG APIENTRY ObjWndProc * CUSTOMIZATION: None * */ -VOID DeviceToHiMetric (HWND hwnd, LPPOINT lppt) +void DeviceToHiMetric ( LPPOINT lppt) { - HDC hdc = GetDC(hwnd); - - SetMapMode(hdc, MM_HIMETRIC); - DPtoLP (hdc, lppt, 1); - - lppt->y *= -1; - - ReleaseDC(hwnd,hdc); - + lppt->x = MulDiv (lppt->x, HIMETRIC_PER_INCH, giXppli); + lppt->y = MulDiv (lppt->y, HIMETRIC_PER_INCH, giYppli); } @@ -840,7 +847,7 @@ VOID EmbeddingModeOff (VOID) /* Change File menu so it contains "Save As..." instead of */ /* "Save Copy As..." */ ModifyMenu(hMenu, IDM_SAVEAS, MF_BYCOMMAND|MF_STRING, IDM_SAVEAS, - "Save As.."); + "Save &As.."); /* In non-embedded mode, the user can create new objects. */ EnableMenuItem(hMenu, menuposObject, MF_BYPOSITION | MF_ENABLED); @@ -903,15 +910,10 @@ static VOID GetWord (LPSTR *plpszSrc, LP * CUSTOMIZATION: None * */ -VOID HiMetricToDevice (HWND hwnd, LPPOINT lppt) +void HiMetricToDevice ( LPPOINT lppt ) { - HDC hdc = GetDC(hwnd); - - SetMapMode(hdc, MM_HIMETRIC); - - LPtoDP (hdc, lppt, 1); - - ReleaseDC(hwnd,hdc); + lppt->x = MulDiv (giXppli, lppt->x, HIMETRIC_PER_INCH); + lppt->y = MulDiv (giYppli, lppt->y, HIMETRIC_PER_INCH); } @@ -950,7 +952,7 @@ LPOBJ HwndToLpobj (HWND hwndObj) */ static BOOL CreateUntitledDoc (INT nCmdShow) { - if (!CreateNewDoc (NULL, "(Untitled)", doctypeNew)) + if (!CreateNewDoc (0, "(Untitled)", doctypeNew)) return FALSE; CreateNewObj (FALSE); ShowWindow(hwndMain, nCmdShow); @@ -1039,7 +1041,7 @@ static BOOL ProcessCmdLine (LPSTR lpszLi } } - if (!CreateDocFromFile (szBuf, NULL, doctypeFromFile)) + if (!CreateDocFromFile (szBuf, 0, doctypeFromFile)) { // File not in proper format. if (fEmbedding) @@ -1166,7 +1168,7 @@ VOID SetHiMetricFields (LPOBJ lpobj) pt.x = lpobj->native.nWidth; pt.y = lpobj->native.nHeight; - DeviceToHiMetric (hwndMain, &pt); + DeviceToHiMetric ( &pt); lpobj->native.nHiMetricWidth = pt.x; lpobj->native.nHiMetricHeight = pt.y; } @@ -1262,7 +1264,7 @@ VOID Wait (BOOL *pf) if (!fMoreMsgs) // if there are no more messages in the OLE queue, go to system queue { - if (GetMessage (&msg, NULL, NULL, NULL)) + if (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); @@ -1278,7 +1280,7 @@ static BOOL FailedUpdate(HWND hwnd) } -BOOL APIENTRY fnFailedUpdate (HWND hDlg, UINT message, DWORD wParam, LONG lParam) +BOOL APIENTRY fnFailedUpdate (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) @@ -1308,7 +1310,7 @@ BOOL APIENTRY fnFailedUpdate (HWND hDlg { CHAR szMsg[200]; - szMsg[0] = NULL; + szMsg[0] = '\0'; wsprintf( szMsg, @@ -1327,3 +1329,7 @@ BOOL APIENTRY fnFailedUpdate (HWND hDlg return FALSE; } + + + +