iCmdShow初始值在哪里

本文详细介绍了Windows API中ShowWindow函数的iCmdShow参数及其默认值,并提供了修改显示方式的方法。通过调整iCmdShow的值,可以改变窗口的显示状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

iCmdShow初始值在哪里

 

调试得知,系统默认值为1  SW_SHOWNORAML

但不知道如何修改系统默认值

可以在ShowWindow (hwnd, iCmdShow)函数前面写代码来修改

 

  iCmdShow = SW_SHOWMAXIMIZED;   //修改
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;

 

BTW:

 

* ShowWindow() Commands
*/
#define SW_HIDE 0
#define SW_SHOWNORMAL 1
#define SW_NORMAL 1
#define SW_SHOWMINIMIZED 2
#define SW_SHOWMAXIMIZED 3
#define SW_MAXIMIZE 3
#define SW_SHOWNOACTIVATE 4
#define SW_SHOW 5
#define SW_MINIMIZE 6
#define SW_SHOWMINNOACTIVE 7
#define SW_SHOWNA 8
#define SW_RESTORE 9
#define SW_SHOWDEFAULT 10
#define SW_FORCEMINIMIZE 11
#define SW_MAX 11

 

 

http://topic.youkuaiyun.com/t/20051025/19/4349897.html

#include <windows.h> #define TIMER_ID 1 // 颜色序列常量定义 COLORREF colors[] = { RGB(255, 0, 0), // 红 RGB(255, 165, 0), // 橙 RGB(255, 255, 0), // 黄 RGB(0, 255, 0), // 绿 RGB(0, 255, 255), // 青 RGB(0, 0, 255), // 蓝 RGB(148, 0, 211) // 紫 }; int colorIndex = -1; // 当前使用的颜色索引初始化为无效值(-1) LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static char szAppName[] = "HelloWin"; HWND hwnd; MSG msg; WNDCLASS wndclass; // 设置WNDCLASS结构体... wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = (WNDPROC)WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = GetStockBrush(WHITE_BRUSH); // 初始白色背景刷子 wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; if (!RegisterClass(&wndclass)) { MessageBox(NULL, TEXT("This program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, TEXT("The Windows Program"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); SetTimer(hwnd, TIMER_ID, 500, NULL); // 启动周期性事件(每隔半秒钟) while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } KillTimer(hwnd, TIMER_ID); // 停止定时器 return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; switch(message){ case WM_CREATE: break; case WM_PAINT: { hdc = BeginPaint(hwnd,&ps); // 获取客户区矩形区域信息. GetClientRect(hwnd,&rect); ++colorIndex %= sizeof(colors)/sizeof(COLORREF); // 自增当前颜色索引 FillRect(hdc,&rect,(HBRUSH)CreateSolidBrush(colors[colorIndex])); DeleteObject((HGDIOBJ)(HPEN)SelectObject(hdc,GetStockPen(DC_PEN))); EndPaint(hwnd,&ps); }break; case WM_DESTROY: PostQuitMessage(0); break; default : return DefWindowProc(hwnd,message,wParam,lParam); } return 0; }
03-12
#include <windows.h> //窗口处理函数WndProc()的声明 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); //主函数,程序的入口,相当于之前的main()函数 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static char szAppName[] = “HelloWin”; HWND hwnd; MSG msg; WNDCLASS wndclass;//WNDCLASSEX也行,会多几个分量,配合RegisterClassEX使用 //设置WNDCLASS结构体,为下一步调用RegisterClass()函数做准备 wndclass.style = CS_HREDRAW | CS_VREDRAW;//支持重绘,不能为0 wndclass.lpfnWndProc = (WNDPROC)WndProc;//主函数与窗口处理函数绑定 wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; //注册 if (!RegisterClass(&wndclass)) { MessageBox(NULL, "This program requires Windows NT!", szAppName, MB_ICONERROR); return 0; } //调用CreateWindow()函数创建窗体 hwnd = CreateWindow (szAppName, // window class name "The Windows Program", // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // creation parameters //显示和更新窗口 ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); //消息循环,不停接收消息直至收到WM_QUIT消息后,跳出循环,程序结束 while(GetMessage(&msg, NULL, 0, 0))//如果函数取得WM_QUIT之外的其他消息,返回非零值。如果函数取得WM_QUIT消息,返回值是零 { TranslateMessage(&msg);//翻译消息,将按键消息转换为字符消息 DispatchMessage(&msg);//以此消息为参数转发给相应的窗口消息处理程序 } return msg.wParam; } //窗口处理函数,函数格式固定,函数名无所谓 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { //Code 使用以上的框架代码,编写程序,要求不断变换窗口屏幕中的颜色,以红橙黄绿青蓝紫的顺序依次变换,间隔0.5秒,不断循环
03-12
#include <windows.h> #include <cmath> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT("SinWave"); HWND hwnd; MSG msg; WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; if (!RegisterClass(&wndclass)) { MessageBox(NULL, TEXT("Program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, TEXT("Dynamic Sin Wave"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static double phase = 0.0; static UINT_PTR timerId = 0; switch (message) { case WM_CREATE: timerId = SetTimer(hwnd, 1, 50, NULL); // 每50毫秒触发一次WM_TIMER return 0; case WM_TIMER: phase += 0.1; // 更新相位 InvalidateRect(hwnd, NULL, TRUE); // 触发重绘 return 0; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); RECT rect; GetClientRect(hwnd, &rect); // 绘制背景 FillRect(hdc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH)); // 绘制Sin曲线 int yCenter = rect.bottom / 2; int amplitude = 100; HPEN hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255)); SelectObject(hdc, hPen); MoveToEx(hdc, 0, yCenter, NULL); for (int x = 0; x < rect.right; x++) { double value = sin(phase + x * 0.05); // 调整频率 int y = yCenter - static_cast<int>(amplitude * value); LineTo(hdc, x, y); } DeleteObject(hPen); EndPaint(hwnd, &ps); return 0; } case WM_DESTROY: KillTimer(hwnd, timerId); PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
最新发布
07-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值