首次用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程序的更多相关文章

  1. win32SDK的hello,world程序(二)

    接上篇,原生的控件都不太好看,所以决定自己画一个,稍微处理下消息就能用了.不过,美化这东西是需要天赋的.即使技术再好,没有对UI布局调整和良好的审美能力,做出来的东西还是很挫. 主要把消息逻辑和画的过 ...

  2. 《白手起家Win32SDK应用程序》(完整版+目录)

    <白手起家Win32SDK应用程序> 目 录 <白手起家Win32SDK应用程序> 第一篇.预备知识 第二篇.创建Win32工程和主函数 第三篇.增加一个回调函数 第四篇.注册 ...

  3. Win32SDK应用程序

    转自:https://blog.csdn.net/jxf_ioriyagami/article/details/1486626 1 说在前面    由于VC6及MFC的特点,我们许多人从标准C++学习 ...

  4. windows下VC界面 DIY系列1----写给想要写界面的C++程序猿的话

    非常早就想写关于C++ UI开发的一系列博文,博客专栏刚审核通过,就立即開始刷博文,不能辜负自己的一番热血,我并非写界面的高手,仅仅想通过写博文提高我自己的技术积累,也顺便帮助大家解决界面开发的瓶颈. ...

  5. JavaScript之父Brendan Eich,Clojure 创建者Rich Hickey,Python创建者Van Rossum等编程大牛对程序员的职业建议

    软件开发是现时很火的职业.据美国劳动局发布的一项统计数据显示,从2014年至2024年,美国就业市场对开发人员的需求量将增长17%,而这个增长率比起所有职业的平均需求量高出了7%.很多人年轻人会选择编 ...

  6. 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用

    有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...

  7. 微信小程序开发心得

    微信小程序也已出来有一段时间了,最近写了几款微信小程序项目,今天来说说感受. 首先开发一款微信小程序,最主要的就是针对于公司来运营的,因为,在申请appid(微信小程序ID号)时候,需要填写相关的公司 ...

  8. node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理

    一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...

  9. 微信应用号(小程序)开发IDE配置(第一篇)

    2016年9月22日凌晨,微信宣布“小程序”问世,当然只是开始内测了,微信公众平台对200个服务号发送了小程序内测邀请.那么什么是“小程序”呢,来看微信之父怎么说 看完之后,相信大家大概都有些明白了吧 ...

随机推荐

  1. xml 和html 语言区别

    都是标记语言(ML),一个是超文本标记语言,一个是扩展标记语言. 不同之处: 1可扩展性:HTML不具备扩展性,而XML是原标记语言,可以用于定义新的标记语言. 2侧重点: HTML侧重于如何表现信息 ...

  2. 论MySQL何时使用索引,何时不使用索引

    索引: 使用索引可快速访问数据库表中的特定信息.索引是对数据库表中一列或多列的值进行排序的一种结构,例如 employee 表的姓(name)列.如果要按姓查找特定职员,与必须搜索表中的所有行相比,索 ...

  3. 测试class

    各种断言方法: assertEqual(a,b) a == b assertNotEqual(a,b) a != b assertTrue(x) x == True assertFalse(x) x ...

  4. hadoop2.7.2单机与伪分布式安装

    环境相关 系统:CentOS 6.8 64位 jdk:1.7.0_79 hadoop:hadoop 2.7.2 安装java环境 详见:linux中搭建java开发环境 创建hadoop用户 # 以r ...

  5. Lesser known purrr tricks

    purrr is package that extends R's functional programming capabilities. It brings a lot of new stuff ...

  6. web worker 扫盲篇

    什么是woker 官方的解释是这样的: worker是一个对象,通过构造函数Worker创建,参数就是一个js文件的路径:文件中的js代码将运行在主线程之外的worker线程: var jsFileU ...

  7. 在node.js中如何屏蔽掉favicon.ico的请求

    今天准备用node做个api出来,还没入门,遇到一个小问题,特在此记录一下! 在做路由模块的时候,发现控制台每次都会多输出一条favicon.ico的请求,对于这种又占资源,看着又碍眼的玩意,强迫症完 ...

  8. Spring框架之IOC(控制反转)

    [TOC] 第一章Spring框架简介 IOC(控制反转)和AOP(面向方面编程)作为Spring框架的两个核心,很好地实现了解耦合.所以,简单来说,Spring是一个轻量级的控制反转(IoC)和面向 ...

  9. Android开发的过去、现在和将来

    现如今,拥有着 80% 的市场份额的 Android 是最主流的手机操作系统.它运行在无数的智能手机.平板以及其他各种各样的设备上.仅凭这一点,我们是否可以认为  Android 编程是简单而轻松的呢 ...

  10. AES加密解密算法---java

    package com.BFGJ.AES; import java.util.Random; import java.util.StringTokenizer; import javax.crypto ...