// 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. HTML系列(五):超链接

    <a> 标签定义超链接,最重要的属性是 href 属性,它指示链接的目标.通过将href属性设定不同类型的值可以使链接指向不同类型的链接地址:内部链接.外部链接.锚链接. 内部链接指的是同 ...

  2. eclipse使用技巧---使用正则表达式查找替换

    1,Eclipse ctrl+f 打开查找框2,选中 Regular expressions (正则表达式) 去掉/* */(eclipse)        /\*(.|[\r\n])*?\*/去掉/ ...

  3. 用原生JS写移动动画案例及实际应用

    js很强大 相信很多人都知道,那么它有哪些强大之处呢?有兴趣的人可以去查查,这里就不赘述了,因为不在本片文章讨论的范围. 我们要讲的是怎么用原生JS写移动动画?我们先举一个最简单的动画例子,很多网站的 ...

  4. C#学习日志 day 4 ------ 类相关---this指针以及相关关键字

    c#中的类和java中的类没什么太大区别.但是c#有些特有的关键字以及属性使得c#具有一些特性. 首先就是this关键字,this在c++和java中都有,可以表示当前对象,以及变量所属对象等.例如 ...

  5. codeforces 546E. Soldier and Traveling 网络流

    题目链接 给出n个城市, 以及初始时每个城市的人数以及目标人数.初始时有些城市是相连的. 每个城市的人只可以待在自己的城市或走到与他相邻的城市, 相邻, 相当于只能走一条路. 如果目标状态不可达, 输 ...

  6. win7使用的一些误区以及困惑

    总结了一些新人在使用win7时容易产生的误区和困惑,罗列出来说明一下,以便新人能尽快适应新的操作系统. 1.内存使用的问题:这是个大误区,很多人都用xp时代的眼光来审视win7,这是错误的,因为两者的 ...

  7. 修改win7注册表发挥大容量内存优势

    现在请打开注册表编辑器,找到[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control \Session Manager\MomoryManagement ...

  8. Dialog with HTML skin using CDHtmlDialog and SetWindowRgn

    Introduction This program demonstrates how to use CDHtmlDialog and SetWindowRgn functions to give a ...

  9. sqlplus conn远程连接

    oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0oracle.in ...

  10. C模块回调Lua函数的两种方法

    作者:ani_di 版权所有,转载务必保留此链接 http://blog.csdn.net/ani_di C模块回调Lua函数的两种方法 lua和C通过虚拟栈这种交互方式简单而又可靠,缺点就是C做栈平 ...