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个服务号发送了小程序内测邀请.那么什么是“小程序”呢,来看微信之父怎么说 看完之后,相信大家大概都有些明白了吧 ...
随机推荐
- XD
题目 是否完成 题目分类 简要题解 没有上司的舞会(codevs1380) Y 树形dp dp[u][0]表示不包含此节点,dp[u][1]表示包含,转移方程为 dp[u][0]+=max(dp[v] ...
- xml 和html 语言区别
都是标记语言(ML),一个是超文本标记语言,一个是扩展标记语言. 不同之处: 1可扩展性:HTML不具备扩展性,而XML是原标记语言,可以用于定义新的标记语言. 2侧重点: HTML侧重于如何表现信息 ...
- 开涛spring3(5.3) - Spring表达式语言 之 5.3 SpEL语法
5.3 SpEL语法 5.3.1 基本表达式 一.字面量表达式: SpEL支持的字面量包括:字符串.数字类型(int.long.float.double).布尔类型.null类型. 类型 示例 字 ...
- 【原创】iOS图片预览(支持缩放和移动)
1.传入图片 PreViewController.h: #import <UIKit/UIKit.h> @interface PreViewController : UIViewContr ...
- 从插上网线到web页面请求,究竟发生了哪些过程?(计算机网络篇)
一.说在前头 好久没有更新博客了,汗颜,最近忙于各种实验与报告,但是还是要抽时间总结一下学的东西.欢迎转载,但是要注明出处哦(=^ ^=). 最近学了计算机网络,正好总结一下.本篇博客的大部分是跟计算 ...
- CCNP第一课:默认路由(路由黑洞,路由终结)
一:功能实现 R1的环回口由R3控制下放,下放之后R4才可以ping通 代码: R1: 只需要一条静态路由,能回包就行了 ip route 20.1.1.0 255.255.255.0 10.1.1. ...
- React模块化开发
借助前端构建工具webpack 1.webpack是facebook为react量身打造的构建工具 2.主要作用是实现模块化,代码整合,代码分割的作用 3.使用webpack整合以后 也不需要使用br ...
- 如何编写Hexo主题
完成一个Hexo的主题其实很简单,和写静态页面差不多,只是内容部分通过Hexo的变量去获取,而且Hexo还内置了一些辅助函数帮你快速方便地完成繁琐的处理. 起步 在写代码之前要先把项目结构搭建好,一个 ...
- 如何在vuejs中抽出公共代码
当我们在使用vue构建中大型项目时,通常会遇到某些经常用的方法以及属性,比如说搭建一个员工管理系统,请求的url需要一个共同的前缀,或者在某几个view中需要用到时间,这个时间是通过某方法格式化之后的 ...
- Javascript事件模型(一):DOM0事件和DOM2事件
javascript事件模型,本文主要有以下内容: DOM0事件模型 DOM2事件模型 一.DOM0事件模型 早期的事件模型称为DOM0级别. DOM0的事件具有极好的跨浏览器优势, 会以最快的速度 ...