用getDC(0)获得屏幕DC后,如何释放.




After painting with a common device context, the ReleaseDC function must be called to release the device context. 

This function releases a device context (DC), freeing it for use by other applications. The effect of ReleaseDC depends on the type of device context. 

int ReleaseDC( 
  HWND hWnd, 
  HDC hDC
); 
Parameters
hWnd 
Handle to the window whose device context is to be released. 
hDC 
Handle to the device context to be released. 
Return Values
The return value specifies whether the device context is released. 

1 indicates that the device context is released. 

Zero indicates that the device context is not released.

Remarks
The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common device context. 

An application cannot use the ReleaseDC function to release a device context that was created by calling the CreateDC function; instead, it must use the DeleteDC function. 

Requirements
OS Versions: Windows CE 1.0 and later.
Header: Winuser.h.
Link Library: Coredll.lib, Winmgr.lib.

//这跟你学的什么语言有什么关系,,API一样可以调用啊,,
只要是getDC返回的,,,都可以用 ReleaseDC 释放,,
屏幕的句柄为0,,所以ReleaseDC的时候第一个参数也为0





vc中怎样得到电脑屏幕的宽和高?



vc中怎样得到电脑屏幕的宽和高?然后将应用程序的主窗口在第一次运行出来的位置在自己想要的位置,谢谢指教!


我有更好的答案




Visual C++中获取屏幕宽和高的函数为GetSystemMetrics(int nIndex),其结果为像素值。其中索引值nIndex在获取屏幕宽时为SM—CXSCREEN,在获取屏幕高时为SM—CYSCREEN。举例如下: 

  BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) 

  { // 设置窗口风格 

  //... 

  // 设置窗口位置 

   cs.x=GetSystemMetrics(SM—CXSCREEN) /2; 

   cs.y=GetSystemMetrics(SM—CYSCREEN) /2; 

   //设置窗口的宽和高(屏幕宽和高的一半) 

   cs.cx=GetSystemMetrics(SM—CXSCREEN)/2; 

   cs.cy=GetSystemMetrics(SM—CYSCREEN)/2; 

   return CFrameWnd::PreCreateWindow(cs);} 
在第一次运行出来的位置在自己想要的位置
用MoveWindow 和SetWindowPos
SetWindowPos可以完成MoveWindow的功能,也能完成MoveWindow不能完成的功能   
  MoveWindow只是移动窗口的位置和大小   
    
  SetWindowPos还可以设置窗口的Z-ORDER、显示隐藏窗口等等