--- mstools/samples/ole/srvrdemo/srvrdemo.c 2018/08/09 18:20:49 1.1 +++ mstools/samples/ole/srvrdemo/srvrdemo.c 2018/08/09 18:21:50 1.1.1.2 @@ -19,6 +19,12 @@ HWND hwndMain = NULL; +// Used in converting units from pixels to Himetric and vice-versa +int giXppli = NULL; // pixels per logical inch along width +int giYppli = NULL; // 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; DOC docMain; @@ -109,7 +115,7 @@ static BOOL FailedUpdate(HWND); * CUSTOMIZATION: None * */ -int WinMain( +int APIENTRY WinMain( HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, @@ -243,6 +249,7 @@ static BOOL InitInstance (HANDLE hInstan INT iColor; + HDC hDC ; hInst = hInstance; @@ -283,6 +290,12 @@ static BOOL InitInstance (HANDLE hInstan // 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 +374,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; @@ -384,7 +397,7 @@ LONG APIENTRY MainWndProc break; case IDM_ABOUT: - DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About); + DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About); break; case IDM_NEW: @@ -563,7 +576,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 +611,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; @@ -745,17 +758,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); } @@ -903,15 +909,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); } @@ -1166,7 +1167,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; } @@ -1278,7 +1279,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) @@ -1327,3 +1328,7 @@ BOOL APIENTRY fnFailedUpdate (HWND hDlg return FALSE; } + + + +