// WinThreadTest.cpp : Defines the entry point for the application.
// #include "stdafx.h"
#include "WinThreadTest.h"
#include <windows.h>
#define MAX_LOADSTRING 100 // Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name // Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine); // TODO: Place code here.
MSG msg;
HACCEL hAccelTable; // Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WINTHREADTEST, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance); // Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
} hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINTHREADTEST)); // Main message loop:
while (GetMessage(&msg, NULL, , ))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} return (int) msg.wParam;
} //
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = ;
wcex.cbWndExtra = ;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINTHREADTEST));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_WINTHREADTEST);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassEx(&wcex);
} //
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, , CW_USEDEFAULT, , NULL, NULL, hInstance, NULL); if (!hWnd)
{
return FALSE;
} ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd); return TRUE;
} DWORD WINAPI tProc(LPVOID pParam){
//TODO.................
HDC hdc;
hdc=(HDC)pParam;
MoveToEx(hdc, , , NULL);
for(int i=;i<=;i++){
LineTo(hdc, +i,);
Sleep();
}
MoveToEx(hdc, , , NULL);
for(int i=;i<=;i++){
LineTo(hdc, ,+i);
Sleep();
}
for(int i=;i<=;i++){
LineTo(hdc, -i,);
Sleep();
}
for(int i=;i<=;i++){
LineTo(hdc, ,-i);
Sleep();
}
return ;
} DWORD WINAPI tProc2(LPVOID pParam){
//TODO.................
HDC hdc;
hdc=(HDC)pParam;
for(int i=;i<=;i++){
Pie(hdc,,,,,,,-i,);
Sleep();
}
for(int i=;i<=;i++){
Pie(hdc,,,,,,,,+i);
Sleep();
}
for(int i=;i<=;i++){
Pie(hdc,,,,,,,,+i);
Sleep();
}
for(int i=;i<=;i++){
Pie(hdc,,,,,,,+i,);
Sleep();
}
for(int i=;i<=;i++){
Pie(hdc,,,,,,,+i,);
Sleep();
}
for(int i=;i<=;i++){
Pie(hdc,,,,,,,,-i);
Sleep();
}
for(int i=;i<=;i++){
Pie(hdc,,,,,,,,-i);
Sleep();
}
for(int i=;i<=;i++){
Pie(hdc,,,,,,,-i,);
Sleep();
}
return ;
} //
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
static int cxClient, cyClient;
PAINTSTRUCT ps;
HDC hdc; //rakus code==================
HPEN hPen, hPenOld;//定义画笔
HBRUSH hBrush,HBruOld;//定义画刷
TEXTMETRIC tm;//用于获取字体信息
int x=;
int y=;
//end of rakus code===================== switch (message)
{
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
return ;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here... //this is rakus code
//划横线
MoveToEx(hdc, , cyClient / , NULL);
LineTo(hdc, cxClient, cyClient / );
// 画竖线
MoveToEx(hdc, cxClient / , , NULL);
LineTo(hdc, cxClient / , cyClient);
// 画椭圆
Ellipse(hdc, cxClient / , , cxClient, cyClient / );
// 画圆矩形
RoundRect(hdc, cxClient / , * cyClient / ,
cxClient / - cxClient / , cyClient - cyClient / ,
cxClient / , cyClient / ); DWORD threadID;
HANDLE hThread;
hThread=CreateThread(NULL,,tProc,hdc,,&threadID); DWORD threadID2;
HANDLE hThread2;
hThread2=CreateThread(NULL,,tProc2,hdc,,&threadID2); HANDLE threads[];
threads[]=hThread;
threads[]=hThread2;
WaitForMultipleObjects(,threads,TRUE,INFINITE);////处理多个线程用这个方法最好 EndPaint(hWnd, &ps);
//end of rakus code
break;
case WM_DESTROY:
PostQuitMessage();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return ;
} // Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE; case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}

VC++ win32 多线程 一边画圆一边画矩形的更多相关文章

  1. 1.1.2-学习Opencv与MFC混合编程之---画图工具 画直线 画圆 画矩形

    源代码地址:http://download.csdn.net/detail/nuptboyzhb/3961685 画图工具 1.     画直线 Ø  增加‘直线’菜单项,建立类向导: Ø  对CXX ...

  2. 操作系统实验 windows编程多线程 生产者消费者问题 画圆画方(内置bug版)

    实验3:随便写的 #include <windows.h> #include <string> #include <stdio.h> #pragma warning ...

  3. 第一个VC++ win32程序 绘制简单图形

    创建一个VC++ win32 打开VS 新工程类型中选择Win32----Win32 Project  自己取个名字(假如叫做My1stWin) 一路next 系统会自动生成好最基本的代码  然后我们 ...

  4. 《图形学》实验六:中点Bresenham算法画圆

    开发环境: VC++6.0,OpenGL 实验内容: 使用中点Bresenham算法画圆. 实验结果: 代码: #include <gl/glut.h> #define WIDTH 500 ...

  5. Win32多线程编程(1) — 基础概念篇

      内核对象的基本概念 Windows系统是非开源的,它提供给我们的接口是用户模式的,即User-Mode API.当我们调用某个API时,需要从用户模式切换到内核模式的I/O System Serv ...

  6. 深入浅出Win32多线程程序设计之基本概念

    一.深入浅出Win32多线程程序设计之基本概念[转] 引言 从单进程单线程到多进程多线程是操作系统发展的一种必然趋势,当年的DOS系统属于单任务操作系统,最优秀的程序员也只能通过驻留内存的方式实现所谓 ...

  7. win32多线程编程

    关于多线程多进程的学习,有没有好的书籍我接触的书里头关于多线程多进程部分,一是<操作系统原理>里面讲的相关概念   一个是<linux基础教程>里面讲的很简单的多线程多进程编程 ...

  8. H5中画图标签Canvas---画矩形,画线,画圆,渐变色,图形载入

    一: 1.鼠标监视坐标值 <!DOCTYPE html> <head> <meta charset=UTF-8> <title>canvas的演示< ...

  9. MFC文档(SDI)应用:画图程序(画圆、画线、鼠标事件)

    要求 1. 在客户区输出一条顺时针45度的直线.一个正方形.一个大圆: 2. 在客户区输出一个图标: 3. 当按下鼠标左键时,将以鼠标坐标为圆心画直径为20个单位的小圆. 首先设置两个变量,用来保存颜 ...

随机推荐

  1. Objective-C时间戳转换的转换和时间

    什么是时间戳? 时间戳(timestamp),一般是一个字符序列.唯一地标识某一刻的时间.数字时间戳技术是数字签名技术一种变种的应用. 思考:简单来讲就是依据文件hash加密后生成的摘要和时间生成的时 ...

  2. Css 外边距折叠(collapsed margin ) 浅析

    Css 外边距折叠(collapses margin ) a.先来看看w3c 文档对于外边距折叠的定义: In CSS, the adjoining margins of two or more bo ...

  3. java项目打jar包

    首先 在工程中,右键项目,有个export,选择JAR File,就能导出jar包. 一.java项目没有导入第三方jar包 1. 首先在Eclipse中打开项目, 右键点击项目,选择“Export” ...

  4. qt检测网络连接状态【只能检测和路由器的连接,不能测试到外网的连接】

    #include <QCoreApplication>#include <QDebug>#include <QTextStream>#include <QDi ...

  5. The type javax.servlet.http.HttpServletRequest cannot be resolved.

    The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from ...

  6. Responsive Design响应式网站设计心得笔记

    这个词已经喊了很久了,一直都是小打小闹,没正经的做过大的响应式全站,这次终于有机会了.网站刚上线半个月,就要改版为响应式设计,支持手机/PC等各类终端显示浏览.今天把首页做好,并测试无误,这里把一些应 ...

  7. MarkDown使用 (三)表格

    MarkDown表格的用法 MarkDown表格的用法 例如: $$ \begin{array}{c|lcr} n & \text{Left} & \text{Center} & ...

  8. Category、Extension

    Category,分类,类目.主要作⽤用是为没有源代码的添加方法,例系统自带的NSString. 通过Category添加的方法会成为原类的一部分.从⽽而达到扩展一 个类的功能.   Category ...

  9. win7 gsoap与vs2010 c++创建Web Service

    ---恢复内容开始--- 之前曾经编写过简单的样例,很久没有碰过,发现已经全部忘记,如今又需要重新巩固一下. 首先是下载gsoap,无法访问官方下载页面,只能在网上搜索,找到一个2.8版本存入云盘以防 ...

  10. GitHub Linux下使用方法

    1. 在网站注册帐号,创建工程 test 进入工程,右下角会有一个项目仓库的地址.https://github.com/braverior/test.git 2.Linux下 安装github sud ...