GetWindowRect和GetWindDC GetClientRect和GetDC 在标题栏输入文字

#include <Windows.h>
#include <stdio.h>
//#include "resource.h"
//#include <afxwin.h>
#include <math.h>

#define TWO_PI (2.0*3.1415926)
LRESULT CALLBACK MyWindowProc(
							  HWND hwnd, 
							  UINT uMsg, 
							  WPARAM wParam, 
							  LPARAM lParam 
							  ); 
void DrawRectangle(HWND hwnd);
int cxClient,cyClient;
int WINAPI WinMain(  HINSTANCE hInstance,  HINSTANCE hPrevInstance, LPSTR lpCmdLine,  int nShowCmd )
{
	HWND hwnd;
	WNDCLASS wndclass;
	MSG msg;
	static TCHAR MyAppName[]=TEXT("My first windows app");
	wndclass.style=CS_HREDRAW|CS_VREDRAW;
	wndclass.lpfnWndProc=MyWindowProc;
	wndclass.cbClsExtra=0;//预留的额外空间
	wndclass.cbWndExtra=0;
	wndclass.hInstance=hInstance;
	wndclass.hIcon=::LoadIcon(NULL,IDI_INFORMATION);
	wndclass.hCursor=::LoadCursor(NULL,IDC_ARROW);//::LoadCursor(hInstance,MAKEINTRESOURCE(IDC_CURSOR1));
	wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName=NULL;
	wndclass.lpszClassName=TEXT("My first windows app");
	if (!RegisterClass(&wndclass))
	{
		int i=GetLastError();
		//char str[25]={0};
		wchar_t chResult[128]={0};
		_itow(i,chResult,10);
		//sprintf(str,TEXT("%d"),i);
		//sprintf(buffer,L"Key State = 0X%X  ",key_state);
		MessageBox(NULL,chResult,TEXT("Error"),MB_OK);
		//AfxMessageBox(TEXT("Error") );
	}
	hwnd=CreateWindow( MyAppName,
		TEXT("My first windows"),
		WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
		CW_USEDEFAULT ,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		NULL,NULL,
		hInstance,
		NULL
		);
	ShowWindow(hwnd,SW_SHOWNORMAL); 
	//ShowWindow(hwnd,iCmdShow);
	UpdateWindow(hwnd);
	while(TRUE)
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if(msg.message==WM_QUIT)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
			DrawRectangle(hwnd);
	}
	
	return msg.wParam;
}
LRESULT CALLBACK MyWindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	static HRGN hRgnClip;
	//static int cxClient,cyClient;
	double fAngle,fRadius;
	HCURSOR hCursor;
	HDC hdc;
	HRGN hRgnTem[6];
	int i;
	PAINTSTRUCT ps;
	RECT WindowsRect;

	HFONT      hFont ;
	LOGFONT    lf ;
	switch(uMsg)
	{
	case WM_SIZE:
		cxClient=LOWORD(lParam);
		cyClient=HIWORD(lParam);

		hCursor=SetCursor(LoadCursor(NULL,IDC_WAIT));
		ShowCursor(TRUE);
//dosomething SetCursor(hCursor); ShowCursor(FALSE); return 0; case WM_PAINT: hdc=BeginPaint(hwnd,&ps); //GetClientRect(hwnd,&WindowsRect); GetWindowRect(hwnd,&WindowsRect); hdc=GetWindowDC(hwnd);//获得整个窗口的DC /* for (int i=0;i<WindowsRect.right;i+=100) { MoveToEx(hdc,i,0,NULL); LineTo(hdc,i,WindowsRect.bottom); }*/ SetTextColor(hdc,GetSysColor(COLOR_CAPTIONTEXT));//设置字体颜色 //SetBkColor(hdc,GetSysColor(COLOR_WINDOW)); SetBkColor(hdc,GetSysColor(COLOR_INACTIVECAPTION)) ;//设置背景颜色 SetBkMode(hdc,TRANSPARENT);//修改背景模式 lf.lfHeight = 30 ; lf.lfWidth = 0 ; lf.lfEscapement = 0 ; lf.lfOrientation = 0 ; lf.lfWeight = 5; lf.lfItalic = 0 ; lf.lfUnderline = 0 ; lf.lfStrikeOut = 0 ; lf.lfCharSet = DEFAULT_CHARSET ; lf.lfOutPrecision = 0 ; lf.lfClipPrecision = 0 ; lf.lfQuality = 0 ; lf.lfPitchAndFamily = 0 ; lstrcpy(lf.lfFaceName,TEXT("Arial")) ; hFont = CreateFontIndirect (&lf) ; SelectObject (hdc, hFont) ; TextOut(hdc,256,0,TEXT("hello world!"),11); EndPaint(hwnd,&ps); return 0; case WM_DESTROY: DeleteObject(hRgnClip); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd,uMsg,wParam,lParam); } void DrawRectangle(HWND hwnd) { }

  

原文地址:https://www.cnblogs.com/xzlq/p/3116749.html