|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <windows.h>
#include <tchar.h>
#include <wchar.h>
#define WINAPI __stdcall
//声明回调程序
LRESULT CALLBACK MyWndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM Lparam);
const TCHAR szWindowsClass[] = TEXT("第一个窗口");
const TCHAR szWindowsTitle[] = TEXT("主窗口标题");
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE iPrevInsrance,
LPTSTR lpCmdLine,
int nCmdShow){
WNDCLASSEX wnd = { 0 };
wnd.cbSize = sizeof(WNDCLASSEX);
wnd.style = CS_HREDRAW | CS_VREDRAW;
wnd.lpfnWndProc = (WNDPROC)MyWndProc;
wnd.cbWndExtra = 0;
wnd.cbClsExtra = 0;
wnd.hInstance = hInstance; //引用程序实例句柄
wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wnd.lpszClassName = szWindowsClass;
RegisterClassEx(&wnd);
//窗口创建
HWND hWnd = CreateWindow(szWindowsClass,
szWindowsTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
HWND_DESKTOP, NULL,
hInstance,NULL);
if (!hWnd){
MessageBox(NULL, TEXT("注册窗口创建失败."), TEXT("失败提示"), MB_OKCANCEL);
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
/*
消息循环
*/
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam; //返回的是窗口参数
}
LRESULT CALLBACK MyWndProc(HWND wnd,
UINT msg,
WPARAM wParam,
LPARAM Lparam){
int mymsg = 0;
switch (msg){
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PRINT:{
TCHAR * str = TEXT("Hello world!");
PAINTSTRUCT ps;
HDC hdc = BeginPaint(wnd, &ps);
RECT r;
GetClientRect(wnd, &r);
SetTextColor(hdc, RGB(255, 0, 0));
DrawText(hdc, str,-1, &r, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
TextOut(hdc, 2, 2, str, _tcslen(str));
EndPaint(wnd, &ps);
return 0;
}
/*case WM_NCPAINT:
{
WCHAR * str1 = TEXT("Hello world!";)
HDC hdc;
hdc = GetDCEx(hwnd, (HRGN)wParam, DCX_WINDOW | DCX_INTERSECTRGN);
// Paint into this DC
TextOut(hdc, 100, 100, str1, _tcslen(str));
ReleaseDC(hwnd, hdc);
return 1;
}*/
default:
return DefWindowProc(wnd, msg, wParam, Lparam);
}
}
#include <windows.h>
#include <tchar.h>
#include <wchar.h>
#define WINAPI __stdcall
//声明回调程序
LRESULT CALLBACK MyWndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM Lparam);
const TCHAR szWindowsClass[] = TEXT("第一个窗口");
const TCHAR szWindowsTitle[] = TEXT("主窗口标题");
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE iPrevInsrance,
LPTSTR lpCmdLine,
int nCmdShow){
WNDCLASSEX wnd = { 0 };
wnd.cbSize = sizeof(WNDCLASSEX);
wnd.style = CS_HREDRAW | CS_VREDRAW;
wnd.lpfnWndProc = (WNDPROC)MyWndProc;
wnd.cbWndExtra = 0;
wnd.cbClsExtra = 0;
wnd.hInstance = hInstance; //引用程序实例句柄
wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wnd.lpszClassName = szWindowsClass;
RegisterClassEx(&wnd);
//窗口创建
HWND hWnd = CreateWindow(szWindowsClass,
szWindowsTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
HWND_DESKTOP, NULL,
hInstance, NULL);
if (!hWnd){
MessageBox(NULL, TEXT("注册窗口创建失败."), TEXT("失败提示"), MB_OKCANCEL);
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
/*
消息循环
*/
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam; //返回的是窗口参数
}
LRESULT CALLBACK MyWndProc(HWND wnd,
UINT msg,
WPARAM wParam,
LPARAM Lparam){
int mymsg = 0;
switch (msg){
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_NCPAINT:{
TCHAR * str = TEXT("Hello world!");
PAINTSTRUCT ps;
HDC hdc = BeginPaint(wnd, &ps);
RECT r;
GetClientRect(wnd, &r);
SetTextColor(hdc, RGB(255, 0, 0));
DrawText(hdc, str, -1, &r, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
TextOut(hdc, 2, 2, str, _tcslen(str));
EndPaint(wnd, &ps);
//MessageBox(NULL, TEXT("结束绘画"), TEXT("提示"), MB_OKCANCEL);
return 0;
}
default:
return DefWindowProc(wnd, msg, wParam, Lparam);
}
}
楼主不知道窗口加载完才能绘画么:shock:
|
|