win32SDK的hello,world程序
首次用Code::Blocks写Win32GUI程序,关于GDI+的引用摸索了半天。SDK写GUI比较累人,以后还是考虑Qt或者其他方式。
代码:
/**
*code by lichmama from cnblogs.com
*@platform: code::blocks 13.12/windows xp
*/
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif #include <tchar.h>
#include <windows.h>
#include ".\gdiplus.h" #define BUTTON 101
#define WS_EX_LAYERED 0x80000
#define GWL_EXSTYLE (-20)
#define LWA_ALPHA 2
#define SC_DRAGMOVE 0xF012 /* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
typedef BOOL (WINAPI *PFSLWA) (HWND hWnd, COLORREF cr, BYTE bAlpha, DWORD dwFlags);
PFSLWA SetLayeredWindowAttributes; /* Make the class name into a global variable */
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp"); int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = ; /* No extra bytes after the window class */
wincl.cbWndExtra = ; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return ; /* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
, /* Extended possibilites for variation */
szClassName, /* Classname */
NULL, //_T("Code::Blocks Template Windows App"), /* Title Text */
WS_POPUP, //WS_OVERLAPPEDWINDOW, /* default window */
, /* Windows decides the position */
, /* where the window ends up on the screen */
, /* The programs width */
, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
); /* Make the window visible on the screen */ ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusInput;
GdiplusStartup(&gdiplusToken, &gdiplusInput, NULL);
ShowWindow(hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, , ))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
} /* The program return-value is 0 - The value that PostQuitMessage() gave */
Gdiplus::GdiplusShutdown(gdiplusToken);
return messages.wParam;
} /* This function is called by the Windows function DispatchMessage() */ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:
//SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_CAPTION);
//SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME);
SetWindowRgn(hwnd, CreateRoundRectRgn(,,,,,), TRUE);
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE)|WS_EX_LAYERED);
{
HMODULE hmod;
hmod=(HMODULE)LoadLibrary("user32.dll");
SetLayeredWindowAttributes=(PFSLWA)GetProcAddress(hmod, "SetLayeredWindowAttributes");
SetLayeredWindowAttributes(hwnd, , , LWA_ALPHA);
CloseHandle(hmod);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HBITMAP hbmp;
BITMAP bmp;
HDC hmemdc;
HDC hdc;
BeginPaint(hwnd, &ps);
hdc=GetWindowDC(hwnd);
hbmp=(HBITMAP)LoadImage(NULL,
"D:\\12.bmp",
IMAGE_BITMAP,
,
,
LR_DEFAULTSIZE|LR_LOADFROMFILE);
GetObject(hbmp, sizeof(bmp), &bmp);
hmemdc=CreateCompatibleDC(NULL);
SelectObject(hmemdc, hbmp);
BitBlt(hdc, , , bmp.bmWidth, bmp.bmHeight, hmemdc, , , SRCCOPY);
DeleteObject(hbmp);
DeleteDC(hmemdc);
ReleaseDC(hwnd, hdc);
EndPaint(hwnd, &ps);
} {
PAINTSTRUCT ps;
HDC hdc;
UINT width;
UINT height;
WCHAR file[]={L"D:\\3.png"};
BeginPaint(hwnd, &ps);
hdc=GetWindowDC(hwnd);
Gdiplus::GpImage *image;
Gdiplus::GpGraphics *graphics;
Gdiplus::DllExports::GdipLoadImageFromFile(file, &image);
Gdiplus::DllExports::GdipCreateFromHDC(hdc, &graphics);
Gdiplus::DllExports::GdipGetImageWidth(image, &width);
Gdiplus::DllExports::GdipGetImageHeight(image, &height);
Gdiplus::DllExports::GdipDrawImageRect(graphics, image, , , width*0.1, height*0.1);
Gdiplus::DllExports::GdipDisposeImage(image);
Gdiplus::DllExports::GdipDeleteGraphics(graphics);
ReleaseDC(hwnd, hdc);
EndPaint(hwnd, &ps);
}
break;
case WM_LBUTTONDOWN:
{
//(700,10)-(751.61)
UINT cx=LOWORD(lParam);
UINT cy=HIWORD(lParam);
if(cx>= && cx<=){
if(cy>= && cy<=){
if(MessageBox(hwnd, "你希望退出程序么?", "MessageBox", MB_YESNO)==IDYES)DestroyWindow(hwnd);
break;
}
}
}
SendMessage(hwnd,WM_SYSCOMMAND,SC_DRAGMOVE,);
break;
case WM_DESTROY:
PostQuitMessage (); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
} return ;
}
贴张图:

win32SDK的hello,world程序的更多相关文章
- win32SDK的hello,world程序(二)
接上篇,原生的控件都不太好看,所以决定自己画一个,稍微处理下消息就能用了.不过,美化这东西是需要天赋的.即使技术再好,没有对UI布局调整和良好的审美能力,做出来的东西还是很挫. 主要把消息逻辑和画的过 ...
- 《白手起家Win32SDK应用程序》(完整版+目录)
<白手起家Win32SDK应用程序> 目 录 <白手起家Win32SDK应用程序> 第一篇.预备知识 第二篇.创建Win32工程和主函数 第三篇.增加一个回调函数 第四篇.注册 ...
- Win32SDK应用程序
转自:https://blog.csdn.net/jxf_ioriyagami/article/details/1486626 1 说在前面 由于VC6及MFC的特点,我们许多人从标准C++学习 ...
- windows下VC界面 DIY系列1----写给想要写界面的C++程序猿的话
非常早就想写关于C++ UI开发的一系列博文,博客专栏刚审核通过,就立即開始刷博文,不能辜负自己的一番热血,我并非写界面的高手,仅仅想通过写博文提高我自己的技术积累,也顺便帮助大家解决界面开发的瓶颈. ...
- JavaScript之父Brendan Eich,Clojure 创建者Rich Hickey,Python创建者Van Rossum等编程大牛对程序员的职业建议
软件开发是现时很火的职业.据美国劳动局发布的一项统计数据显示,从2014年至2024年,美国就业市场对开发人员的需求量将增长17%,而这个增长率比起所有职业的平均需求量高出了7%.很多人年轻人会选择编 ...
- 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用
有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...
- 微信小程序开发心得
微信小程序也已出来有一段时间了,最近写了几款微信小程序项目,今天来说说感受. 首先开发一款微信小程序,最主要的就是针对于公司来运营的,因为,在申请appid(微信小程序ID号)时候,需要填写相关的公司 ...
- node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理
一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...
- 微信应用号(小程序)开发IDE配置(第一篇)
2016年9月22日凌晨,微信宣布“小程序”问世,当然只是开始内测了,微信公众平台对200个服务号发送了小程序内测邀请.那么什么是“小程序”呢,来看微信之父怎么说 看完之后,相信大家大概都有些明白了吧 ...
随机推荐
- Aspose.Cells.dll操作execl
附件:Aspose.Cells.dll 1.创建execl(不需要服务器或者客户端安装office) public void DCExexl(DataTable dt) { Workbook wb ...
- Nginx教程(二) Nginx虚拟主机配置
Nginx教程(二) Nginx虚拟主机配置 1 虚拟主机管理 1.1 Nginx管理虚拟主机 虚拟主机使用的是特殊的软硬件技术,它把一台运行在因特网上的服务器主机分成一台台“虚拟”的主机,每台虚拟主 ...
- MySQL数据库使用mysqldump导出数据详解
mysqldump是mysql用于转存储数据库的实用程序.它主要产生一个SQL脚本,其中包含从头重新创建数据库所必需的命令CREATE TABLE INSERT等.接下来通过本文给大家介绍MySQL数 ...
- Html_Task4(知识点:水平居中+垂直居中/position/float/border-radius)
任务四:定位和居中问题 任务目标 实践HTML/CSS布局方式 深入了解position等CSS属性 任务描述 实现如 示例图(点击打开) 的效果 灰色元素水平垂直居中,有两个四分之一圆位于其左上角和 ...
- zookeeper的安装与配置
本文将通过三个zookeeper的节点去配置 1.首先去官网下载zookeeper的包 zookeeper-3.4.10.tar.gz 2.用FTP文上传到/usr/local下 3.解压文件tar ...
- php笔记一
一.Login登陆验证步骤: 1.赋值,用$_POST将id和password传递给loginProcess.php登陆验证页面. 2.建立数据库连接 $conn=mysql_connect($hos ...
- Java 9 揭秘(1.Java入门介绍)
文 by / 林本托 在第一部分中,主要讲解如下内容: JDK 9 包含了哪些内容 运行代码的系统要求 如何安装 NetBeans 1 JDK 介绍 JDK 9是Java开发工具包的第九个主要版本,计 ...
- 对pathtracing的一些个人理解
本人水平有限,若有错误也请指正~ 上面说到pathtracing(pt)的一些优点和缺点,优点即其实现很简单,这就是大概为什么当今市面上流行的很多渲染器如今都相继采用pathtracing算法为核心进 ...
- 如何同时完成多个ajax之后再执行某个方法 ? 使用$.when().done();
jQuery中的$.when()方法比较复杂,这里不作全面讲解,只写一个同时完成多个ajax请求后执行操作的方法. 有时候我们需要等待多个ajax执行完以后,再执行某个操作. 写法如下: $.when ...
- JavaFx TableView疑难详解
TableView是个十分有用的控件,适应性和灵活性非常强,可以对它进行任意的修改,比如界面样式.功能.本文将从一步步提问的方式讲解TableView 创建已知列的TableView 已知列的表格的创 ...